From b4bc4764cace17f1fbda75a757538a9eff04f6cc Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Fri, 10 Nov 2017 11:48:41 -0500 Subject: [PATCH] got transaction.cpp compiling --- libraries/chain/CMakeLists.txt | 2 +- .../chain/include/eos/chain/authority.hpp | 8 +-- libraries/chain/include/eos/chain/block.hpp | 14 +++-- libraries/chain/include/eos/chain/message.hpp | 61 ------------------- .../include/eos/chain/producer_schedule.hpp | 4 +- .../chain/include/eos/chain/transaction.hpp | 26 +++++--- libraries/chain/include/eos/chain/types.hpp | 2 +- libraries/chain/transaction.cpp | 22 +++---- 8 files changed, 47 insertions(+), 92 deletions(-) delete mode 100644 libraries/chain/include/eos/chain/message.hpp diff --git a/libraries/chain/CMakeLists.txt b/libraries/chain/CMakeLists.txt index 8721aaa3f..4325c5d64 100644 --- a/libraries/chain/CMakeLists.txt +++ b/libraries/chain/CMakeLists.txt @@ -24,7 +24,7 @@ add_library( eos_chain ${HEADERS} ) -target_link_libraries( eos_chain fc chainbase Logging IR WAST WASM Runtime ) +target_link_libraries( eos_chain eos_utilities fc chainbase Logging IR WAST WASM Runtime ) target_include_directories( eos_chain PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/../wasm-jit/Include" diff --git a/libraries/chain/include/eos/chain/authority.hpp b/libraries/chain/include/eos/chain/authority.hpp index afc9a1ca2..6dee604b9 100644 --- a/libraries/chain/include/eos/chain/authority.hpp +++ b/libraries/chain/include/eos/chain/authority.hpp @@ -12,17 +12,17 @@ namespace eosio { namespace chain { struct permission_level_weight { permission_level permission; - uint16_t weight; + weight_type weight; }; struct key_weight { public_key_type key; - uint16_t weight; + weight_type weight; }; struct authority { - uint32_t threshold = 0; - vector accounts; + uint32_t threshold = 0; + vector accounts; vector keys; }; diff --git a/libraries/chain/include/eos/chain/block.hpp b/libraries/chain/include/eos/chain/block.hpp index 95490f4c0..5ce373357 100644 --- a/libraries/chain/include/eos/chain/block.hpp +++ b/libraries/chain/include/eos/chain/block.hpp @@ -5,6 +5,7 @@ #pragma once #include #include +#include namespace eosio { namespace chain { @@ -73,7 +74,7 @@ namespace eosio { namespace chain { * tree of a block should be generated over a set of message IDs rather than a set of * transaction ids. */ - struct block_summary : public signed_block_header { + struct signed_block_summary : public signed_block_header { typedef vector shard; /// new or generated transactions typedef vector cycle; @@ -88,14 +89,17 @@ namespace eosio { namespace chain { * The transactions are grouped to mirror the cycles in block_summary, generated * transactions are not included. */ - struct signed_block : public block_summary { + struct signed_block : public signed_block_summary { vector input_transactions; /// this is loaded and indexed into map that is referenced by summary }; } } // eosio::chain -FC_REFLECT(eosio::chain::block_header, (previous)(timestamp)(transaction_merkle_root)(producer)(producer_changes)) +FC_REFLECT(eosio::chain::block_header, (previous)(timestamp) + (transaction_mroot)(message_mroot)(block_mroot) + (producer)(new_producers)) + FC_REFLECT_DERIVED(eosio::chain::signed_block_header, (eosio::chain::block_header), (producer_signature)) -FC_REFLECT(eosio::chain::thread, (generated_input)(user_input) ) -FC_REFLECT_DERIVED(eosio::chain::signed_block, (eosio::chain::signed_block_header), (cycles)) +FC_REFLECT_DERIVED(eosio::chain::signed_block_summary, (eosio::chain::signed_block_header), (cycles_summary)) +FC_REFLECT_DERIVED(eosio::chain::signed_block, (eosio::chain::signed_block_header), (input_transactions)) diff --git a/libraries/chain/include/eos/chain/message.hpp b/libraries/chain/include/eos/chain/message.hpp deleted file mode 100644 index 299e325fe..000000000 --- a/libraries/chain/include/eos/chain/message.hpp +++ /dev/null @@ -1,61 +0,0 @@ -/** - * @file - * @copyright defined in eos/LICENSE.txt - */ -#pragma once - -#include - -namespace eosio { namespace chain { - -/** - * @brief The message struct defines a blockchain message - * -#warning Outdated documentation should be fixed - * Messages are the heart of all activity on the blockchain, - * -- all events and actions which take place in the chain are - * recorded as messages. Messages are sent from one account - * (@ref sender) to another account (@ref recipient), and are - * optionally also delivered to several other accounts (@ref notify). - * - * A message has a header that defines who sent it and who will - * be processing it. The message content is a binary blob, - * @ref data, whose type is determined by @ref type, which is - * dynamic and defined by the scripting language. - */ -struct Message : public types::Message { - Message() = default; - template - Message(const AccountName& code, const vector& authorization, const types::FuncName& type, T&& value) - :types::Message(code, type, authorization, Bytes()) { - set(type, std::forward(value)); - } - - Message(const AccountName& code, const vector& authorization, const types::FuncName& type) - :types::Message(code, type, authorization, Bytes()) {} - - Message(const types::Message& m) : types::Message(m) {} - - template - void set_packed(const types::FuncName& t, const T& value) { - type = t; - data.resize(sizeof(value)); - memcpy( data.data(), &value, sizeof(value) ); - } - - template - void set(const types::FuncName& t, const T& value) { - type = t; - data = fc::raw::pack(value); - } - template - T as()const { - return fc::raw::unpack(data); - } -}; - - - -} } // namespace eosio::chain - -FC_REFLECT_DERIVED(eosio::chain::Message, (eosio::types::Message), ) diff --git a/libraries/chain/include/eos/chain/producer_schedule.hpp b/libraries/chain/include/eos/chain/producer_schedule.hpp index fc7db92a8..011fc60e4 100644 --- a/libraries/chain/include/eos/chain/producer_schedule.hpp +++ b/libraries/chain/include/eos/chain/producer_schedule.hpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include namespace eosio { namespace chain { diff --git a/libraries/chain/include/eos/chain/transaction.hpp b/libraries/chain/include/eos/chain/transaction.hpp index f89829dd5..3a9d80901 100644 --- a/libraries/chain/include/eos/chain/transaction.hpp +++ b/libraries/chain/include/eos/chain/transaction.hpp @@ -34,19 +34,19 @@ namespace eosio { namespace chain { * were properly declared when it executes. */ struct action { - scope_name scope; + scope_name scope; action_name name; vector permissions; - bytes data; + vector data; action(){} template action( vector auth, T&& value ) { - scope = T::get_action_scope; - name = T::get_action_name; - permissions = move(auth); - data = fc::raw::pack(value); + scope = T::get_scope; + name = T::get_name; + permissions = move(auth); + data = fc::raw::pack(value); } template @@ -108,7 +108,8 @@ namespace eosio { namespace chain { block_num_type get_ref_blocknum( block_num_type head_blocknum )const { return ((head_blocknum/0xffff)*0xffff) + head_blocknum%0xffff; } - void set_reference_block(transaction& t, const block_id_type& reference_block); + void set_reference_block( const block_id_type& reference_block ); + bool verify_reference_block( const block_id_type& reference_block ); }; /** @@ -122,13 +123,18 @@ namespace eosio { namespace chain { vector actions; transaction_id_type id()const; + digest_type sig_digest( const chain_id_type& chain_id )const; }; struct signed_transaction : public transaction { vector signatures; + const signature_type& sign(const private_key_type& key, const chain_id_type& chain_id); + signature_type sign(const private_key_type& key, const chain_id_type& chain_id)const; + flat_set get_signature_keys( const chain_id_type& chain_id )const; }; + /** * When a transaction is generated it can be scheduled to occur * in the future. It may also fail to execute for some reason in @@ -146,3 +152,9 @@ namespace eosio { namespace chain { } } // eosio::chain +FC_REFLECT( eosio::chain::permission_level, (actor)(level) ) +FC_REFLECT( eosio::chain::action, (scope)(name)(permissions)(data) ) +FC_REFLECT( eosio::chain::transaction_header, (expiration)(region)(ref_block_num)(ref_block_prefix) ) +FC_REFLECT_DERIVED( eosio::chain::transaction, (eosio::chain::transaction_header), (read_scope)(write_scope)(actions) ) +FC_REFLECT_DERIVED( eosio::chain::signed_transaction, (eosio::chain::transaction), (signatures) ) + diff --git a/libraries/chain/include/eos/chain/types.hpp b/libraries/chain/include/eos/chain/types.hpp index 2e9847d4d..9678364b4 100644 --- a/libraries/chain/include/eos/chain/types.hpp +++ b/libraries/chain/include/eos/chain/types.hpp @@ -144,7 +144,7 @@ namespace eosio { namespace chain { using transaction_id_type = checksum_type; using digest_type = checksum_type; using weight_type = uint16_t; - + using block_num_type = uint32_t; using share_type = uint64_t; diff --git a/libraries/chain/transaction.cpp b/libraries/chain/transaction.cpp index c90e1b436..9eb8408c5 100644 --- a/libraries/chain/transaction.cpp +++ b/libraries/chain/transaction.cpp @@ -12,14 +12,14 @@ namespace eosio { namespace chain { -void transaction_header::set_reference_block(transaction& t, const block_id_type& reference_block) { - t.ref_block_num= fc::endian_reverse_u32(reference_block._hash[0]); - t.ref_block_prefix= reference_block._hash[1]; +void transaction_header::set_reference_block( const block_id_type& reference_block ) { + ref_block_num = fc::endian_reverse_u32(reference_block._hash[0]); + ref_block_prefix = reference_block._hash[1]; } -bool transaction_header::verify_reference_block(const transaction& t, const block_id_type& reference_block) { - return t.ref_block_num == (decltype(t.ref_block_num))fc::endian_reverse_u32(reference_block._hash[0]) && - t.ref_block_prefix == (decltype(t.ref_block_prefix))reference_block._hash[1]; +bool transaction_header::verify_reference_block( const block_id_type& reference_block ) { + return ref_block_num == (decltype(ref_block_num))fc::endian_reverse_u32(reference_block._hash[0]) && + ref_block_prefix == (decltype(ref_block_prefix))reference_block._hash[1]; } @@ -30,26 +30,26 @@ transaction_id_type transaction::id() const { } -digest_type signed_transaction::sig_digest( const chain_id_type& chain_id )const { +digest_type transaction::sig_digest( const chain_id_type& chain_id )const { digest_type::encoder enc; fc::raw::pack( enc, chain_id ); - fc::raw::pack( enc, static_cast(*this) ); + fc::raw::pack( enc, *this ); return enc.result(); } const signature_type& signed_transaction::sign(const private_key_type& key, const chain_id_type& chain_id) { - signatures.push_back(key.sign_compact(sig_digest(chain_id))); + signatures.push_back(key.sign(sig_digest(chain_id))); return signatures.back(); } signature_type signed_transaction::sign(const private_key_type& key, const chain_id_type& chain_id)const { - return key.sign_compact(sig_digest(chain_id)); + return key.sign(sig_digest(chain_id)); } flat_set signed_transaction::get_signature_keys( const chain_id_type& chain_id )const { try { using boost::adaptors::transformed; - auto sig_to_key = transformed([digest = sig_digest(chain_id)](const fc::ecc::compact_signature& signature) { + auto sig_to_key = transformed([digest = sig_digest(chain_id)](const fc::crypto::signature& signature) { return public_key_type(signature, digest); }); auto key_range = signatures | sig_to_key; -- GitLab