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

[+] Wallet

[+] Transactions and transaction items
[*] Some renames mostly related to section
parent d560a810
No related branches found
No related tags found
No related merge requests found
Showing with 272 additions and 133 deletions
......@@ -4,32 +4,38 @@ project (dap-chain)
set(DAP_CHAIN_SRCS
dap_chain_common.c
dap_chain_block.c
dap_chain_block_section.c
dap_chain_block_roots.c
dap_chain_block_txs.c
dap_chain_section.c
dap_chain_section_roots.c
dap_chain.c
dap_chain_coin.c
dap_chain_srv.c
dap_chain_tx.c
dap_chain_section_tx.c
dap_hash.c
dap_hash_fusion.c
dap_hash_keccak.c
dap_hash_slow.c
dap_chain_wallet.c
)
set(DAP_CHAIN_HEADERS
dap_chain_block.h
dap_chain_block_section.h
dap_chain_block_roots.h
dap_chain.h
dap_chain_common.h
dap_chain_internal.h
dap_chain_common.h
dap_chain_coin.h
dap_chain_srv.h
dap_chain_tx.h
dap_chain_section.h
dap_chain_section_roots.h
dap_chain_section_tx.h
dap_chain_section_tx_in.h
dap_chain_section_tx_out.h
dap_hash.h
dap_hash_fusion.h
dap_hash_keccak.h
dap_hash_slow.h
dap_chain_wallet.h
dap_chain_wallet_internal.h
)
add_subdirectory(monero_crypto)
......
......@@ -19,6 +19,7 @@
*/
#include "dap_chain_internal.h"
#include "dap_chain.h"
#define LOG_TAG "dap_chain"
......@@ -47,9 +48,15 @@ void dap_chain_deinit()
* @param a_file_name
* @return
*/
dap_chain_t * dap_chain_open(const char * a_file_name)
dap_chain_t * dap_chain_open(const char * a_file_cache,const char * a_file_storage )
{
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+");
return l_chain;
}
/**
......
......@@ -18,9 +18,7 @@
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _DAP_CHAIN_H_
#define _DAP_CHAIN_H_
#pragma once
#include "dap_chain_block.h"
typedef struct dap_chain{
......@@ -42,5 +40,3 @@ void dap_chain_save(dap_chain_t * a_chain);
void dap_chain_info_dump_log(dap_chain_t * a_chain);
void dap_chain_close(dap_chain_t * a_chain);
#endif
......@@ -19,7 +19,7 @@
*/
#include "dap_common.h"
#include "dap_chain_block_roots.h"
#include "dap_chain_section_roots.h"
#include "dap_chain_block.h"
......
......@@ -17,16 +17,15 @@
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_
#pragma once
#include <stdalign.h>
#include <stdint.h>
#include <stddef.h>
#include "dap_common.h"
#include "dap_math_ops.h"
#include "dap_chain_common.h"
#include "dap_chain_block_section.h"
#include "dap_chain_block_roots.h"
#include "dap_chain_section.h"
#include "dap_chain_section_roots.h"
#define DAP_CHAIN_BLOCK_SIGNATURE 0xDA05BF8E
......@@ -39,11 +38,10 @@ typedef struct dap_chain_block{
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
dap_chain_hash_t root_main;/// @param root_main Main tree's root for all block's hashes
uint64_t timestamp; /// @param timestamp @brief Block create time timestamp
uint64_t difficulty; /// difficulty level
uint64_t nonce; /// Nonce value to allow header variation for mining
uint32_t section_size; /// @param secion_size Size of section[] array
dap_chain_hash_t root_sections;/// @param root_main Main tree's root for all sections's hashes
} header;
dap_chain_block_section_t section[];
} DAP_ALIGN_PACKED dap_chain_block_t;
......@@ -51,4 +49,3 @@ typedef struct dap_chain_block{
int dap_chain_block_init();
void dap_chain_block_deinit();
#endif
#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_v1
* @brief Hash tree roots for block, version 1
*/
typedef struct dap_chain_block_roots_v1{
dap_chain_hash_t main;
} DAP_ALIGN_PACKED dap_chain_block_roots_v1_t;
/**
* @struct dap_chain_block_roots_v2
* @brief Hash tree roots for block, version 2
*/
typedef struct dap_chain_block_roots_v2{
dap_chain_hash_t main;
dap_chain_hash_t txs;
} DAP_ALIGN_PACKED dap_chain_block_roots_v2_t;
typedef dap_chain_block_roots_v2_t dap_chain_block_roots_t;
#endif
#include "dap_common.h"
#define LOG_TAG "dap_chain_block_secion"
/**
* @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"
#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
/// Transaction section
#define DAP_CHAIN_BLOCK_SECTION_TX 0x0100
/// Smart contract: EVM code section
#define DAP_CHAIN_BLOCK_SECTION_EVM_CODE 0x0200
/// Smart contract: EVM data section
#define DAP_CHAIN_BLOCK_SECTION_EVM_DATA 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
uint32_t size; // section size
} header;
uint8_t data[]; // data
} DAP_ALIGN_PACKED dap_chain_block_section_t;
#endif
File moved
File moved
......@@ -5,10 +5,18 @@
#include "dap_common.h"
#include "dap_math_ops.h"
#define DAP_CHAIN_HASH_SIZE 32
#define DAP_CHAIN_HASH_SIZE 64
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;
} dap_chain_sig_type_t;
#endif
/*
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/>.
*/
#pragma once
#include <stdio.h>
#include <stdint.h>
#include "dap_common.h"
#include "dap_chain.h"
#define DAP_CHAIN_FILE_SIGNATURE 0xfa340bef153eba48
typedef struct dap_chain_file_header
{
uint64_t signature;
uint32_t version;
uint8_t type;
uint32_t chain_id;
} dap_chain_file_header_t;
/**
* @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
FILE * file_cache_idx_txs; /// @param file_cache @brief Index for cache
FILE * file_cache; /// @param file_cache @brief Cache for raw blocks
FILE * file_storage; /// @param file_cache @brief Cache for raw blocks
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_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
......@@ -17,13 +17,7 @@
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_TX_H_
#define _DAP_CHAIN_TX_H_
#include "dap_chain_common.h"
int dap_chain_tx_init();
void dap_chain_tx_deinit();
#endif
#include "dap_common.h"
#define LOG_TAG "dap_chain_block_secion"
/*
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/>.
*/
/**
* @struct dap_chain_block_section
* @brief section inside the block
*/
#pragma once
#include <stdint.h>
#include "dap_common.h"
#include "dap_math_ops.h"
#include "dap_chain_common.h"
/// End section, means all the rest of the block is empty
#define DAP_CHAIN_SECTION_END 0x0000
/// Transaction header section
#define DAP_CHAIN_SECTION_TX 0x0100
/// Transaction request section
#define DAP_CHAIN_SECTION_TX_REQUEST 0x0300
/// Smart contract: DVM code section
#define DAP_CHAIN_SECTION_DVM_CODE 0x0900
/// Smart contract: DVM code section
#define DAP_CHAIN_SECTION_DVM_DATA 0x0901
/// Smart contract: EVM code section
#define DAP_CHAIN_SECTION_EVM_CODE 0x0910
/// Smart contract: EVM data section
#define DAP_CHAIN_SECTION_EVM_CODE 0x0911
/// Pub key section, with sign and address
#define DAP_CHAIN_SECTION_PKEY 0x0c00
/// Section with additional roots, for example transaction roots
#define DAP_CHAIN_SECTION_ROOTS 0xf000
/// Coin
#define DAP_CHAIN_SECTION_COIN 0xffff
typedef struct dap_chain_block_section{
uint16_t type; // Section type
uint8_t data[]; // data
} DAP_ALIGN_PACKED dap_chain_block_section_t;
inline uint32_t
......@@ -19,24 +19,6 @@
*/
#include "dap_common.h"
#include "dap_chain_tx.h"
#define LOG_TAG "dap_chain_tx"
/**
* @brief dap_chain_tx_init
* @return
*/
int dap_chain_tx_init()
{
log_it(L_INFO,"DapChain Transactions module init");
return 0;
}
/**
* @brief dap_chain_tx_deinit
*/
void dap_chain_tx_deinit()
{
log_it(L_INFO,"DapChain Transactions module deinit");
}
#include "dap_chain_section_roots.h"
#define LOG_TAG "dap_chain_section_roots"
/*
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/>.
*/
#pragma once
#include "dap_common.h"
#include "dap_chain_common.h"
/**
* @struct dap_chain_section_roots_v1
* @brief Hash tree roots for block, version 1
*/
typedef struct dap_chain_section_roots_v1{
dap_chain_hash_t main;
} DAP_ALIGN_PACKED dap_chain_block_roots_v1_t;
/**
* @struct dap_chain_section_roots_v2
* @brief Hash tree roots for block, version 2
*/
typedef struct dap_chain_section_roots_v2{
dap_chain_hash_t main;
dap_chain_hash_t txs;
} DAP_ALIGN_PACKED dap_chain_section_roots_v2_t;
typedef dap_chain_section_roots_v2_t dap_chain_section_roots_t;
#include "dap_common.h"
#include "dap_chain_section_tx.h"
#define LOG_TAG "dap_chain_section_tx"
/*
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/>.
*/
#pragma once
#include "dap_chain_common.h"
#include "dap_chain_section.h"
typedef enum dap_chain_tx_item_type{
TX_ITEM_TYPE_IN = 0x00,
TX_ITEM_TYPE_OUT = 0x10,
} dap_chain_tx_item_type_t;
/**
* @struct dap_chain_section_tx
* @brief Transaction section, consists from lot of tx_items
*/
typedef struct dap_chain_section_tx{
struct {
uint64_t lock_time;
uint32_t tx_items_size; // size of next sequencly lying tx_item sections would be decided to belong this transaction
} DAP_ALIGN_PACKED header;
uint8_t tx_items[];
} DAP_ALIGN_PACKED dap_chain_section_tx_t;
#pragma once
#include <stdint.h>
#include "dap_common.h"
#include "dap_chain_common.h"
#include "dap_chain_section_tx.h"
/**
* @struct dap_chain_tx_item
* @brief Sections belongs to heading tx section, with inputs, outputs and others tx relatated items
*/
typedef struct dap_chain_tx_in{
struct {
dap_chain_tx_item_type_t type:8; /// @param type @brief Transaction item type
dap_chain_hash_t tx_prev_hash; /// @param tx_prev_hash @brief Hash of the previous transaction
uint32_t tx_out_prev_idx; /// @param tx_prev_idx @brief Previous tx_out index
dap_chain_sig_type_t sig_type:16; /// Signature type
uint32_t sig_size; /// Signature size
} header; /// Only header's hash is used for verification
uint32_t seq_no; /// Sequence number, out of the header so could be changed during reorganization
uint8_t sig[]; /// @param sig @brief raw signatura dat
} DAP_ALIGN_PACKED dap_chain_tx_in_t;
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