diff --git a/CMakeLists.txt b/CMakeLists.txt index 99425837f55e93f9448712c64ea9fa867a3003d5..a5a03027f9866bccc0925425b92117c88b17af46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,25 @@ cmake_minimum_required(VERSION 2.8) project (libdap-chain) -set(DAP_CHAIN_SRCS dap_chain_block.c dap_chain_block_section.c dap_chain.c dap_chain_coin.c dap_chain_srv.c dap_chain_tx.c) +set(DAP_CHAIN_SRCS + dap_chain_common.c + dap_chain_block.c + dap_chain_block_section.c + dap_chain_block_roots.c + dap_chain.c + dap_chain_coin.c + dap_chain_srv.c + dap_chain_tx.c) + set(DAP_CHAIN_HEADERS - dap_chain_block.h - dap_chain_block_section.h - dap_chain.h - dap_chain_coin.h - dap_chain_srv.h - dap_chain_tx.h + dap_chain_block.h + dap_chain_block_section.h + dap_chain_block_roots.h + dap_chain.h + dap_chain_common.h + dap_chain_coin.h + dap_chain_srv.h + dap_chain_tx.h ) include_directories("${dap_core_INCLUDE_DIRS}") diff --git a/dap_chain_block.c b/dap_chain_block.c index dc73e8291897f5c1a9171485d1db22ba5acf8be7..9c3800732b9b71ba9f16e208171368660304704f 100644 --- a/dap_chain_block.c +++ b/dap_chain_block.c @@ -18,8 +18,13 @@ along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. */ +#include "dap_common.h" +#include "dap_chain_block_roots.h" + #include "dap_chain_block.h" +#define LOG_TAG "dap_chain_block" + /** * @brief dap_chain_block_init * @return diff --git a/dap_chain_block.h b/dap_chain_block.h index 2eb5e794ed9d87accc1d18f4a520f808e99277aa..f370e848afc77a7ad3c92f22f89ca5780cc44be3 100644 --- a/dap_chain_block.h +++ b/dap_chain_block.h @@ -24,16 +24,27 @@ #include <stddef.h> #include "dap_common.h" #include "dap_math_ops.h" +#include "dap_chain_common.h" #include "dap_chain_block_section.h" +#define DAP_CHAIN_BLOCK_SIGNATURE 0xDA05BF8E + + /** * @brief The dap_chain_block struct */ typedef struct dap_chain_block{ struct { - dap_uint128_t id; /// @param Block ID uniqie identificator of the block - size_t size; + uint32_t signature; /// Magic number, always equels to DAP_CHAIN_BLOCK_SIGNATURE + int32_t version; /// block version + dap_chain_hash_t prev_block_hash; + uint64_t timestamp; /// Timestamp + uint64_t bits; /// difficulty + uint64_t nonce; /// Nonce value to allow header variation for mining + dap_uint128_t id; /// @param id Block ID uniqie identificator of the block + size_t section_size; /// @param secion_size Size of section[] array } header; + dap_chain_hash_t tree_root_; dap_chain_block_section_t section[]; } DAP_ALIGN_PACKED dap_chain_block_t; diff --git a/dap_chain_block_roots.c b/dap_chain_block_roots.c new file mode 100644 index 0000000000000000000000000000000000000000..1b2d6b05b473757e74a38166e35a64a99b5bc85e --- /dev/null +++ b/dap_chain_block_roots.c @@ -0,0 +1,4 @@ +#include "dap_common.h" +#include "dap_chain_block_roots.h" + +#define LOG_TAG "dap_chain_block_roots" diff --git a/dap_chain_block_roots.h b/dap_chain_block_roots.h new file mode 100644 index 0000000000000000000000000000000000000000..c8928f55b444ce67e3cdf495ed91b0962f91cc07 --- /dev/null +++ b/dap_chain_block_roots.h @@ -0,0 +1,21 @@ +#ifndef _DAP_CHAIN_BLOCK_ROOTS_H_ +#define _DAP_CHAIN_BLOCK_ROOTS_H_ + +#include "dap_common.h" +#include "dap_chain_common.h" + +/** + * @struct dap_chain_block_roots + * @brief Hash tree roots for block + */ +typedef struct dap_chain_block_roots{ + dap_chain_hash_t main; + dap_chain_hash_t txs; + dap_chain_hash_t txs_pending; + dap_chain_hash_t txs_requests; + dap_chain_hash_t contract_code; + dap_chain_hash_t contract_data; +} DAP_ALIGN_PACKED dap_chain_block_roots_t; + +#endif + diff --git a/dap_chain_block_section.c b/dap_chain_block_section.c index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..64604b205036c4920de8ea7563c91612431e48cb 100644 --- a/dap_chain_block_section.c +++ b/dap_chain_block_section.c @@ -0,0 +1,3 @@ +#include "dap_common.h" + +#define LOG_TAG "dap_chain_block_secion" diff --git a/dap_chain_block_section.h b/dap_chain_block_section.h index f4328cf8f035a2c63f82a45e8ba569513bc5713f..df7fca5d11c54717877e6f2334fe5a325d03dc4f 100644 --- a/dap_chain_block_section.h +++ b/dap_chain_block_section.h @@ -7,6 +7,10 @@ #include <stdint.h> #include "dap_common.h" #include "dap_math_ops.h" +#include "dap_chain_common.h" + +/// First section that must be in any block, with hash tree roots +#define DAP_CHAIN_BLOCK_SECTION_ROOTS 0xffff /// End section, means all the rest of the block is empty #define DAP_CHAIN_BLOCK_SECTION_END 0x0000 @@ -14,11 +18,11 @@ /// Transaction section #define DAP_CHAIN_BLOCK_SECTION_TX 0x0100 -/// Smart contract: code section -#define DAP_CHAIN_BLOCK_SECTION_TX 0x0200 +/// Smart contract: EVM code section +#define DAP_CHAIN_BLOCK_SECTION_EVM_CODE 0x0200 -/// Smart contract: data section -#define DAP_CHAIN_BLOCK_SECTION_TX 0x0201 +/// Smart contract: EVM data section +#define DAP_CHAIN_BLOCK_SECTION_EVM_DATA 0x0201 /// Public key #define DAP_CHAIN_BLOCK_SECTION_PKEY 0x0300 diff --git a/dap_chain_common.c b/dap_chain_common.c new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/dap_chain_common.h b/dap_chain_common.h new file mode 100644 index 0000000000000000000000000000000000000000..5fa776a25bc8a998aca8ba120706cc16a27b8eb1 --- /dev/null +++ b/dap_chain_common.h @@ -0,0 +1,11 @@ +#ifndef _DAP_CHAIN_COMMON_H_ +#define _DAP_CHAIN_COMMON_H_ +#include <stdint.h> + +#define DAP_CHAIN_HASH_SIZE 32 + +typedef union dap_chain_hash{ + uint8_t data[DAP_CHAIN_HASH_SIZE]; +} dap_chain_hash_t; + +#endif