Skip to content
Snippets Groups Projects
Commit 3a23e1c6 authored by Dmitriy Gerasimov's avatar Dmitriy Gerasimov
Browse files

[+] Block's header

[+] Block's section format
[+] Block's section roots header
parent a4aa4c0c
No related branches found
No related tags found
1 merge request!24Support 3689
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}")
......
......@@ -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
......
......@@ -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;
......
#include "dap_common.h"
#include "dap_chain_block_roots.h"
#define LOG_TAG "dap_chain_block_roots"
#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
#include "dap_common.h"
#define LOG_TAG "dap_chain_block_secion"
......@@ -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
......
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment