提交 b4bc4764 编写于 作者: D Daniel Larimer

got transaction.cpp compiling

上级 867c1aac
......@@ -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"
......
......@@ -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<permission_level_weight> accounts;
uint32_t threshold = 0;
vector<permission_level_weight> accounts;
vector<key_weight> keys;
};
......
......@@ -5,6 +5,7 @@
#pragma once
#include <eos/chain/block_timestamp.hpp>
#include <eos/chain/transaction.hpp>
#include <eos/chain/producer_schedule.hpp>
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<transaction_receipt> shard; /// new or generated transactions
typedef vector<shard> 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<signed_transaction> input_transactions; /// this is loaded and indexed into map<id,trx> 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))
/**
* @file
* @copyright defined in eos/LICENSE.txt
*/
#pragma once
#include <eos/chain/types.hpp>
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<typename T>
Message(const AccountName& code, const vector<types::AccountPermission>& authorization, const types::FuncName& type, T&& value)
:types::Message(code, type, authorization, Bytes()) {
set<T>(type, std::forward<T>(value));
}
Message(const AccountName& code, const vector<types::AccountPermission>& authorization, const types::FuncName& type)
:types::Message(code, type, authorization, Bytes()) {}
Message(const types::Message& m) : types::Message(m) {}
template<typename T>
void set_packed(const types::FuncName& t, const T& value) {
type = t;
data.resize(sizeof(value));
memcpy( data.data(), &value, sizeof(value) );
}
template<typename T>
void set(const types::FuncName& t, const T& value) {
type = t;
data = fc::raw::pack(value);
}
template<typename T>
T as()const {
return fc::raw::unpack<T>(data);
}
};
} } // namespace eosio::chain
FC_REFLECT_DERIVED(eosio::chain::Message, (eosio::types::Message), )
#include <eosio/chain/config.hpp>
#include <eosio/chain/types.hpp>
#include <eos/chain/config.hpp>
#include <eos/chain/types.hpp>
namespace eosio { namespace chain {
......
......@@ -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<permission_level> permissions;
bytes data;
vector<char> data;
action(){}
template<typename T>
action( vector<permission_level> 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<typename T>
......@@ -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<action> actions;
transaction_id_type id()const;
digest_type sig_digest( const chain_id_type& chain_id )const;
};
struct signed_transaction : public transaction {
vector<signature_type> 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<public_key_type> 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) )
......@@ -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;
......
......@@ -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<const transaction&>(*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<public_key_type> 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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册