From f60848a4426632ca7618ebf3c4fd3a112380f790 Mon Sep 17 00:00:00 2001 From: Dmitriy Gerasimov <dm@cifercom.com> Date: Sun, 14 Jan 2018 21:40:47 +0700 Subject: [PATCH] [*] Small and big fixes --- dap_chain.c | 7 ++++--- dap_chain.h | 11 +++++++---- dap_chain_block.c | 1 - dap_chain_block.h | 12 ++++++++---- dap_chain_coin.h | 24 +++++++++++++++++++++++ dap_chain_common.h | 40 ++++++++++++++++++++++++++++++-------- dap_chain_internal.h | 14 +++++++++---- dap_chain_section.h | 14 +++++++------ dap_chain_section_roots.h | 8 ++++++-- dap_chain_section_tx.h | 8 ++++++-- dap_chain_section_tx_in.h | 23 ++++++++++++++++++++++ dap_chain_section_tx_out.h | 23 ++++++++++++++++++++++ dap_chain_srv.h | 23 ++++++++++++++++++++++ dap_chain_wallet.h | 23 ++++++++++++++++++++++ 14 files changed, 197 insertions(+), 34 deletions(-) diff --git a/dap_chain.c b/dap_chain.c index 4bb2fb49fd..282a01fa4f 100644 --- a/dap_chain.c +++ b/dap_chain.c @@ -45,16 +45,17 @@ void dap_chain_deinit() /** * @brief dap_chain_open - * @param a_file_name + * @param a_file_storage + * @param a_file_cache * @return */ -dap_chain_t * dap_chain_open(const char * a_file_cache,const char * a_file_storage ) +dap_chain_t * dap_chain_open(const char * a_file_storage,const char * a_file_cache) { dap_chain_t * l_chain = DAP_NEW_Z(dap_chain_t); DAP_CHAIN_INTERNAL_LOCAL_NEW(l_chain); l_chain_internal->file_storage_type = 0x0000; // TODO compressed format - l_chain_internal->file_storage blockhain_file = fopen(a_file_name,"a+"); + l_chain_internal->file_storage = fopen(a_file_storage,"a+"); return l_chain; } diff --git a/dap_chain.h b/dap_chain.h index 3260fd79ef..0f40cec69a 100644 --- a/dap_chain.h +++ b/dap_chain.h @@ -1,6 +1,10 @@ /* - Copyright (c) 2017-2018 (c) Project "DeM Labs Inc" https://github.com/demlabsinc - All rights reserved. + * Authors: + * Dmitriy A. Gearasimov <kahovski@gmail.com> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://github.com/demlabsinc + * Copyright (c) 2017-2018 + * All rights reserved. This file is part of DAP (Deus Applications Prototypes) the open source project @@ -17,7 +21,6 @@ You should have received a copy of the GNU General Public License along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. */ - #pragma once #include "dap_chain_block.h" @@ -33,7 +36,7 @@ typedef struct dap_chain{ int dap_chain_init(); void dap_chain_deinit(); -dap_chain_t * dap_chain_open(const char * a_file_name); +dap_chain_t * dap_chain_open(const char * a_file_storage,const char * a_file_cache); void dap_chain_remap(dap_chain_t * a_chain, size_t a_offset); void dap_chain_save(dap_chain_t * a_chain); diff --git a/dap_chain_block.c b/dap_chain_block.c index cd160264b0..bc4f0834b7 100644 --- a/dap_chain_block.c +++ b/dap_chain_block.c @@ -19,7 +19,6 @@ */ #include "dap_common.h" -#include "dap_chain_section_roots.h" #include "dap_chain_block.h" diff --git a/dap_chain_block.h b/dap_chain_block.h index f257726a8d..4e9ee859dc 100644 --- a/dap_chain_block.h +++ b/dap_chain_block.h @@ -1,6 +1,10 @@ /* - Copyright (c) 2017-2018 (c) Project "DeM Labs Inc" https://github.com/demlabsinc - All rights reserved. + * Authors: + * Dmitriy A. Gearasimov <kahovski@gmail.com> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://github.com/demlabsinc + * Copyright (c) 2017-2018 + * All rights reserved. This file is part of DAP (Deus Applications Prototypes) the open source project @@ -34,7 +38,7 @@ * @brief The dap_chain_block struct */ typedef struct dap_chain_block{ - struct { + struct block_header{ uint32_t signature; /// @param signature @brief Magic number, always equels to DAP_CHAIN_BLOCK_SIGNATURE int32_t version; /// @param version @brief block version (be carefull, signed value, as Bitcoin has) dap_chain_hash_t prev_block; /// @param prev_block Hash of the previous block @@ -42,7 +46,7 @@ typedef struct dap_chain_block{ uint64_t difficulty; /// difficulty level uint64_t nonce; /// Nonce value to allow header variation for mining dap_chain_hash_t root_sections;/// @param root_main Main tree's root for all sections's hashes - } header; + } DAP_ALIGN_PACKED header; dap_chain_block_section_t section[]; } DAP_ALIGN_PACKED dap_chain_block_t; diff --git a/dap_chain_coin.h b/dap_chain_coin.h index e69de29bb2..8bf7f08772 100644 --- a/dap_chain_coin.h +++ b/dap_chain_coin.h @@ -0,0 +1,24 @@ +/* + * Authors: + * Dmitriy A. Gearasimov <kahovski@gmail.com> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://github.com/demlabsinc + * Copyright (c) 2017-2018 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ +#pragma once diff --git a/dap_chain_common.h b/dap_chain_common.h index df72b8e518..ec0a7b710b 100644 --- a/dap_chain_common.h +++ b/dap_chain_common.h @@ -1,5 +1,28 @@ -#ifndef _DAP_CHAIN_COMMON_H_ -#define _DAP_CHAIN_COMMON_H_ +/* + * Authors: + * Dmitriy A. Gearasimov <kahovski@gmail.com> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://github.com/demlabsinc + * Copyright (c) 2017-2018 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ + +#pragma once #include <stdint.h> #include "dap_common.h" @@ -11,12 +34,13 @@ typedef union dap_chain_hash{ uint8_t data[DAP_CHAIN_HASH_SIZE]; } dap_chain_hash_t; + typedef union dap_chain_sig_type{ - uint16_t raw; - enum { - SIG_TYPE_NEWHOPE = 0x0000, - SIG_TYPE_MULTI = 0xffff /// @brief Has inside subset of different signatures and sign composed with all of them - } type; + enum { + SIG_TYPE_NEWHOPE = 0x0000, + SIG_TYPE_MULTI = 0xffff /// @brief Has inside subset of different signatures and sign composed with all of them + + } type: 16; + uint16_t raw; } dap_chain_sig_type_t; -#endif diff --git a/dap_chain_internal.h b/dap_chain_internal.h index 720e15bb85..d5822356b1 100644 --- a/dap_chain_internal.h +++ b/dap_chain_internal.h @@ -1,6 +1,10 @@ /* - Copyright (c) 2017-2018 (c) Project "DeM Labs Inc" https://github.com/demlabsinc - All rights reserved. + * Authors: + * Dmitriy A. Gearasimov <kahovski@gmail.com> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://github.com/demlabsinc + * Copyright (c) 2017-2018 + * All rights reserved. This file is part of DAP (Deus Applications Prototypes) the open source project @@ -36,6 +40,8 @@ typedef struct dap_chain_file_header /** * @struct dap_chain_internal * @brief Internal blochain data, mostly aggregated + * + */ typedef struct dap_chain_internal { FILE * file_cache_idx_blocks; /// @param file_cache @brief Index for blocks @@ -45,8 +51,8 @@ typedef struct dap_chain_internal uint8_t file_storage_type; /// @param file_storage_type @brief Is file_storage is raw, compressed or smth else } dap_chain_internal_t; -#define DAP_CHAIN_INTERNAL(a) ((dap_chain_internal_t *) a->_inheritor ) +#define DAP_CHAIN_INTERNAL(a) ((dap_chain_internal_t *) a->_internal ) #define DAP_CHAIN_INTERNAL_LOCAL(a) dap_chain_internal_t * l_chain_internal = DAP_CHAIN_INTERNAL(a) -#define DAP_CHAIN_INTERNAL_LOCAL_NEW(a) dap_chain_internal_t * l_chain_internal = DAP_NEW_Z(dap_chain_internal_t); a->_inheritor = l_chain_internal +#define DAP_CHAIN_INTERNAL_LOCAL_NEW(a) dap_chain_internal_t * l_chain_internal = DAP_NEW_Z(dap_chain_internal_t); a->_internal = l_chain_internal diff --git a/dap_chain_section.h b/dap_chain_section.h index 49e3fcff9a..655c4a1053 100644 --- a/dap_chain_section.h +++ b/dap_chain_section.h @@ -1,6 +1,10 @@ /* - Copyright (c) 2017-2018 (c) Project "DeM Labs Inc" https://github.com/demlabsinc - All rights reserved. + * Authors: + * Dmitriy A. Gearasimov <kahovski@gmail.com> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://github.com/demlabsinc + * Copyright (c) 2017-2018 + * All rights reserved. This file is part of DAP (Deus Applications Prototypes) the open source project @@ -17,8 +21,6 @@ You should have received a copy of the GNU General Public License along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. */ - - /** * @struct dap_chain_block_section * @brief section inside the block @@ -48,7 +50,7 @@ #define DAP_CHAIN_SECTION_EVM_CODE 0x0910 /// Smart contract: EVM data section -#define DAP_CHAIN_SECTION_EVM_CODE 0x0911 +#define DAP_CHAIN_SECTION_EVM_DATA 0x0911 /// Pub key section, with sign and address #define DAP_CHAIN_SECTION_PKEY 0x0c00 @@ -67,4 +69,4 @@ typedef struct dap_chain_block_section{ uint8_t data[]; // data } DAP_ALIGN_PACKED dap_chain_block_section_t; -inline uint32_t + diff --git a/dap_chain_section_roots.h b/dap_chain_section_roots.h index d0eb6320aa..491a069498 100644 --- a/dap_chain_section_roots.h +++ b/dap_chain_section_roots.h @@ -1,6 +1,10 @@ /* - Copyright (c) 2017-2018 (c) Project "DeM Labs Inc" https://github.com/demlabsinc - All rights reserved. + * Authors: + * Dmitriy A. Gearasimov <kahovski@gmail.com> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://github.com/demlabsinc + * Copyright (c) 2017-2018 + * All rights reserved. This file is part of DAP (Deus Applications Prototypes) the open source project diff --git a/dap_chain_section_tx.h b/dap_chain_section_tx.h index 10bfc026f3..9d52a97b98 100644 --- a/dap_chain_section_tx.h +++ b/dap_chain_section_tx.h @@ -1,6 +1,10 @@ /* - Copyright (c) 2017-2018 (c) Project "DeM Labs Inc" https://github.com/demlabsinc - All rights reserved. + * Authors: + * Dmitriy A. Gearasimov <kahovski@gmail.com> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://github.com/demlabsinc + * Copyright (c) 2017-2018 + * All rights reserved. This file is part of DAP (Deus Applications Prototypes) the open source project diff --git a/dap_chain_section_tx_in.h b/dap_chain_section_tx_in.h index c2484bacfe..66bbefb5fe 100644 --- a/dap_chain_section_tx_in.h +++ b/dap_chain_section_tx_in.h @@ -1,3 +1,26 @@ +/* + * Authors: + * Dmitriy A. Gearasimov <kahovski@gmail.com> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://github.com/demlabsinc + * Copyright (c) 2017-2018 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ #pragma once #include <stdint.h> diff --git a/dap_chain_section_tx_out.h b/dap_chain_section_tx_out.h index e014f19e4d..9c90d70a26 100644 --- a/dap_chain_section_tx_out.h +++ b/dap_chain_section_tx_out.h @@ -1,3 +1,26 @@ +/* + * Authors: + * Dmitriy A. Gearasimov <kahovski@gmail.com> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://github.com/demlabsinc + * Copyright (c) 2017-2018 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ #pragma once #include <stdint.h> diff --git a/dap_chain_srv.h b/dap_chain_srv.h index e69de29bb2..a672942990 100644 --- a/dap_chain_srv.h +++ b/dap_chain_srv.h @@ -0,0 +1,23 @@ +/* + * Authors: + * Dmitriy A. Gearasimov <kahovski@gmail.com> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://github.com/demlabsinc + * Copyright (c) 2017-2018 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ diff --git a/dap_chain_wallet.h b/dap_chain_wallet.h index e69de29bb2..a672942990 100644 --- a/dap_chain_wallet.h +++ b/dap_chain_wallet.h @@ -0,0 +1,23 @@ +/* + * Authors: + * Dmitriy A. Gearasimov <kahovski@gmail.com> + * DeM Labs Inc. https://demlabs.net + * DeM Labs Open source community https://github.com/demlabsinc + * Copyright (c) 2017-2018 + * All rights reserved. + + This file is part of DAP (Deus Applications Prototypes) the open source project + + DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + DAP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. +*/ -- GitLab