-
Notifications
You must be signed in to change notification settings - Fork 2
/
block.hpp
93 lines (76 loc) · 4.18 KB
/
block.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#pragma once
#include <eosio/chain/block_header.hpp>
#include <eosio/chain/transaction.hpp>
#include <eosio/chain/archive_record.hpp>
namespace eosio { namespace chain {
/**
* When a transaction is referenced by a block it could imply one of several outcomes which
* describe the state-transition undertaken by the block producer.
*/
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){}
explicit 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, lhs.ram_kbytes, lhs.storage_kbytes) ==
std::tie(rhs.status, rhs.cpu_usage_us, rhs.net_usage_words, rhs.ram_kbytes, rhs.storage_kbytes);
}
fc::enum_type<uint8_t,status_enum> status;
fc::unsigned_int cpu_usage_us = 0; ///< 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...
fc::unsigned_int ram_kbytes = 0; ///< total billed RAM usage (kbytes)
fc::signed_int storage_kbytes = 0; ///< total billed STORAGE usage (kbytes)
};
struct transaction_receipt : public transaction_receipt_header {
transaction_receipt():transaction_receipt_header(){}
explicit transaction_receipt( const transaction_id_type& tid ):transaction_receipt_header(executed),trx(tid){}
explicit transaction_receipt( const packed_transaction& ptrx ):transaction_receipt_header(executed),trx(ptrx){}
fc::static_variant<transaction_id_type, packed_transaction> trx;
digest_type digest()const {
digest_type::encoder enc;
fc::raw::pack( enc, status );
fc::raw::pack( enc, cpu_usage_us );
fc::raw::pack( enc, net_usage_words );
fc::raw::pack( enc, ram_kbytes );
fc::raw::pack( enc, storage_kbytes );
if( trx.contains<transaction_id_type>() )
fc::raw::pack( enc, trx.get<transaction_id_type>() );
else
fc::raw::pack( enc, trx.get<packed_transaction>().packed_digest() );
return enc.result();
}
};
/**
*/
struct signed_block : public signed_block_header {
private:
signed_block( const signed_block& ) = default;
public:
signed_block() = default;
explicit signed_block( const signed_block_header& h ):signed_block_header(h){}
signed_block( signed_block&& ) = default;
signed_block& operator=(const signed_block&) = delete;
signed_block clone() const { return *this; }
vector<transaction_receipt> transactions; /// new or generated transactions
vector<archive_record> archive_records; /// archive records from all transactions
extensions_type block_extensions;
};
using signed_block_ptr = std::shared_ptr<signed_block>;
struct producer_confirmation {
block_id_type block_id;
digest_type block_digest;
account_name producer;
signature_type sig;
};
} } /// eosio::chain
FC_REFLECT_ENUM( eosio::chain::transaction_receipt::status_enum,
(executed)(soft_fail)(hard_fail)(delayed)(expired) )
FC_REFLECT(eosio::chain::transaction_receipt_header, (status)(cpu_usage_us)(net_usage_words)(ram_kbytes)(storage_kbytes) )
FC_REFLECT_DERIVED(eosio::chain::transaction_receipt, (eosio::chain::transaction_receipt_header), (trx) )
FC_REFLECT_DERIVED(eosio::chain::signed_block, (eosio::chain::signed_block_header), (transactions)(archive_records)(block_extensions) )