1.get_transaction_result
get_transaction_resulteos_read/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp
struct get_transaction_result {
transaction_id_type id; //交易hash
fc::variant trx;
chain::block_timestamp_type block_time; //区块时间
uint32_t block_num = 0; //区块高度
uint32_t last_irreversible_block = 0;
vector<fc::variant> traces;
};
transaction id的生成方式
eos_read/libraries/chain/transaction.cpp
transaction_id_type transaction::id() const {
digest_type::encoder enc;
fc::raw::pack( enc, *this );
return enc.result();
}
2.trx
trx2.1recipt
recipttransaction_receipt_header
eos_read/libraries/chain/include/eosio/chain/block.hpp
struct transaction_receipt_header {
enum status_enum {
executed = 0, ///< succeed, no error handler executed
soft_fail = 1, ///< objectively failed (not executed), error handler executed
hard_fail = 2, ///< objectively failed and error handler objectively failed thus no state change
delayed = 3, ///< transaction delayed/deferred/scheduled for future execution
expired = 4 ///< transaction expired and storage space refuned to user
};
transaction_receipt_header():status(hard_fail){}
transaction_receipt_header( status_enum s ):status(s){}
friend inline bool operator ==( const transaction_receipt_header& lhs, const transaction_receipt_header& rhs ) {
return std::tie(lhs.status, lhs.cpu_usage_us, lhs.net_usage_words) == std::tie(rhs.status, rhs.cpu_usage_us, rhs.net_usage_words);
}
fc::enum_type<uint8_t,status_enum> status;
uint32_t cpu_usage_us; ///< total billed CPU usage (microseconds)
fc::unsigned_int net_usage_words; ///< total billed NET usage, so we can reconstruct resource state when skipping context free data... hard failures...
};
packed_transaction
struct packed_transaction {
vector<signature_type> signatures;
fc::enum_type<uint8_t,compression_type> compression;
bytes packed_context_free_data;
bytes packed_trx;
}
2.2.1 transaction_header
transactioneos_read/libraries/chain/include/eosio/chain/transaction.hpp
struct transaction_header {
time_point_sec expiration; ///< the time at which a transaction expires(交易过期时间)
uint16_t ref_block_num = 0U; ///< specifies a block num in the last 2^16 blocks.
uint32_t ref_block_prefix = 0UL; ///< specifies the lower 32 bits of the blockid at get_ref_blocknum
fc::unsigned_int max_net_usage_words = 0UL; /// upper limit on total network bandwidth (in 8 byte words) billed for this transaction
uint8_t max_cpu_usage_ms = 0; /// upper limit on the total CPU time billed for this transaction
fc::unsigned_int delay_sec = 0UL; /// number of seconds to delay this transaction for during which it may be canceled.
/**
* @return the absolute block number given the relative ref_block_num
*/
block_num_type get_ref_blocknum( block_num_type head_blocknum )const {
return ((head_blocknum/0xffff)*0xffff) + head_blocknum%0xffff;
}
void set_reference_block( const block_id_type& reference_block );
bool verify_reference_block( const block_id_type& reference_block )const;
void validate()const;
};
2.2.2 transaction
eos_read/libraries/chain/include/eosio/chain/transaction.hpp
/**
* A transaction consits of a set of messages which must all be applied or
* all are rejected. These messages have access to data within the given
* read and write scopes.
*/
struct transaction : public transaction_header {
vector<action> context_free_actions;
vector<action> actions;
extensions_type transaction_extensions;
transaction_id_type id()const;
digest_type sig_digest( const chain_id_type& chain_id, const vector<bytes>& cfd = vector<bytes>() )const;
flat_set<public_key_type> get_signature_keys( const vector<signature_type>& signatures,
const chain_id_type& chain_id,
const vector<bytes>& cfd = vector<bytes>(),
bool allow_duplicate_keys = false,
bool use_cache = true )const;
uint32_t total_actions()const { return context_free_actions.size() + actions.size(); }
account_name first_authorizor()const {
for( const auto& a : actions ) {
for( const auto& u : a.authorization )
return u.actor;
}
return account_name();
}
};
2.2.3.signed_transaction
struct signed_transaction : public transaction
{
signed_transaction() = default;
// signed_transaction( const signed_transaction& ) = default;
// signed_transaction( signed_transaction&& ) = default;
signed_transaction( transaction&& trx, const vector<signature_type>& signatures, const vector<bytes>& context_free_data)
: transaction(std::move(trx))
, signatures(signatures)
, context_free_data(context_free_data)
{
}
vector<signature_type> signatures;
vector<bytes> context_free_data; ///< for each context-free action, there is an entry here
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, bool allow_duplicate_keys = false, bool use_cache = true )const;
};
2.2.4.action
actioneos_read/libraries/chain/include/eosio/chain/action.hpp
struct action {
account_name account;
action_name name;
vector<permission_level> authorization;
bytes data;
action(){}
template<typename T, std::enable_if_t<std::is_base_of<bytes, T>::value, int> = 1>
action( vector<permission_level> auth, const T& value ) {
account = T::get_account();
name = T::get_name();
authorization = move(auth);
data.assign(value.data(), value.data() + value.size());
}
template<typename T, std::enable_if_t<!std::is_base_of<bytes, T>::value, int> = 1>
action( vector<permission_level> auth, const T& value ) {
account = T::get_account();
name = T::get_name();
authorization = move(auth);
data = fc::raw::pack(value);
}
action( vector<permission_level> auth, account_name account, action_name name, const bytes& data )
: account(account), name(name), authorization(move(auth)), data(data) {
}
template<typename T>
T data_as()const {
EOS_ASSERT( account == T::get_account(), action_type_exception, "account is not consistent with action struct" );
EOS_ASSERT( name == T::get_name(), action_type_exception, "action name is not consistent with action struct" );
return fc::raw::unpack<T>(data);
}
};
网友评论