From a4aa4c0c19fc2b27dd45093e3ff13d0a86c44440 Mon Sep 17 00:00:00 2001 From: Dmitriy Gerasimov <dm@cifercom.com> Date: Fri, 12 Jan 2018 02:44:25 +0700 Subject: [PATCH] [+] Declarations for all base objects - block, block secion, transaction, coin, service --- CMakeLists.txt | 20 +++++++++++++++--- dap_chain_block.c | 38 +++++++++++++++++++++++++++++++++ dap_chain_block.h | 43 ++++++++++++++++++++++++++++++++++++++ dap_chain_block_section.c | 0 dap_chain_block_section.h | 44 +++++++++++++++++++++++++++++++++++++++ dap_chain_coin.c | 0 dap_chain_coin.h | 0 dap_chain_srv.c | 0 dap_chain_srv.h | 0 dap_chain_tx.c | 0 dap_chain_tx.h | 0 11 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 dap_chain_block.c create mode 100644 dap_chain_block.h create mode 100644 dap_chain_block_section.c create mode 100644 dap_chain_block_section.h create mode 100644 dap_chain_coin.c create mode 100644 dap_chain_coin.h create mode 100644 dap_chain_srv.c create mode 100644 dap_chain_srv.h create mode 100644 dap_chain_tx.c create mode 100644 dap_chain_tx.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 557fe00..9942583 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,23 @@ cmake_minimum_required(VERSION 2.8) project (libdap-chain) -set(DAP_CHAIN_SRCS dap_chain.c) - -add_library(${PROJECT_NAME} STATIC ${DAP_CHAIN_SRCS}) +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_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 + ) + +include_directories("${dap_core_INCLUDE_DIRS}") +add_definitions ("${dap_core_DEFINITIONS}") + +include_directories("${dap_crypto_INCLUDE_DIRS}") +add_definitions ("${dap_crypto_DEFINITIONS}") + +add_library(${PROJECT_NAME} STATIC ${DAP_CHAIN_SRCS} ${DAP_CHAIN_HEADERS}) set(${PROJECT_NAME}_DEFINITIONS CACHE INTERNAL "${PROJECT_NAME}: Definitions" FORCE) diff --git a/dap_chain_block.c b/dap_chain_block.c new file mode 100644 index 0000000..dc73e82 --- /dev/null +++ b/dap_chain_block.c @@ -0,0 +1,38 @@ +/* + Copyright (c) 2017-2018 (c) Project "DeM Labs Inc" https://github.com/demlabsinc + 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/>. +*/ + +#include "dap_chain_block.h" + +/** + * @brief dap_chain_block_init + * @return + */ +int dap_chain_block_init() +{ + +} + +/** + * @brief dap_chain_block_deinit + */ +void dap_chain_block_deinit() +{ + +} diff --git a/dap_chain_block.h b/dap_chain_block.h new file mode 100644 index 0000000..2eb5e79 --- /dev/null +++ b/dap_chain_block.h @@ -0,0 +1,43 @@ +/* + Copyright (c) 2017-2018 (c) Project "DeM Labs Inc" https://github.com/demlabsinc + 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/>. +*/ +#ifndef _DAP_CHAIN_BLOCK_H_ +#define _DAP_CHAIN_BLOCK_H_ +#include <stdalign.h> +#include <stdint.h> +#include <stddef.h> +#include "dap_common.h" +#include "dap_math_ops.h" +#include "dap_chain_block_section.h" + +/** + * @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; + } header; + dap_chain_block_section_t section[]; +} DAP_ALIGN_PACKED dap_chain_block_t; + +int dap_chain_block_init(); +void dap_chain_block_deinit(); + +#endif diff --git a/dap_chain_block_section.c b/dap_chain_block_section.c new file mode 100644 index 0000000..e69de29 diff --git a/dap_chain_block_section.h b/dap_chain_block_section.h new file mode 100644 index 0000000..f4328cf --- /dev/null +++ b/dap_chain_block_section.h @@ -0,0 +1,44 @@ +/** + * @struct dap_chain_block_section + * @brief section inside the block + */ +#ifndef _DAP_CHAIN_BLOCK_SECTION_H_ +#define _DAP_CHAIN_BLOCK_SECTION_H_ +#include <stdint.h> +#include "dap_common.h" +#include "dap_math_ops.h" + +/// End section, means all the rest of the block is empty +#define DAP_CHAIN_BLOCK_SECTION_END 0x0000 + +/// Transaction section +#define DAP_CHAIN_BLOCK_SECTION_TX 0x0100 + +/// Smart contract: code section +#define DAP_CHAIN_BLOCK_SECTION_TX 0x0200 + +/// Smart contract: data section +#define DAP_CHAIN_BLOCK_SECTION_TX 0x0201 + +/// Public key +#define DAP_CHAIN_BLOCK_SECTION_PKEY 0x0300 + +/// Coin: gold +#define DAP_CHAIN_BLOCK_SECTION_COIN_GOLD 0xff00 + +/// Coin: copper +#define DAP_CHAIN_BLOCK_SECTION_COIN_COPPER 0xff01 + +/// Coin: silver +#define DAP_CHAIN_BLOCK_SECTION_COIN_SILVER 0xff02 + + +typedef struct dap_chain_block_section{ + struct{ + uint16_t type; // Section type + size_t size; // section size + } header; + uint8_t data[]; // data +} DAP_ALIGN_PACKED dap_chain_block_section_t; + +#endif diff --git a/dap_chain_coin.c b/dap_chain_coin.c new file mode 100644 index 0000000..e69de29 diff --git a/dap_chain_coin.h b/dap_chain_coin.h new file mode 100644 index 0000000..e69de29 diff --git a/dap_chain_srv.c b/dap_chain_srv.c new file mode 100644 index 0000000..e69de29 diff --git a/dap_chain_srv.h b/dap_chain_srv.h new file mode 100644 index 0000000..e69de29 diff --git a/dap_chain_tx.c b/dap_chain_tx.c new file mode 100644 index 0000000..e69de29 diff --git a/dap_chain_tx.h b/dap_chain_tx.h new file mode 100644 index 0000000..e69de29 -- GitLab