Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
transaction.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <numeric>
5
6namespace sysio { namespace chain {
7
26
27 namespace detail {
28 template<typename... Ts>
30 using transaction_extension_t = std::variant< Ts... >;
31 using decompose_t = decompose< Ts... >;
32 };
33 }
34
37 >;
38
40
66
71 return ((head_blocknum/0xffff)*0xffff) + head_blocknum%0xffff;
72 }
73 void set_reference_block( const block_id_type& reference_block );
74 bool verify_reference_block( const block_id_type& reference_block )const;
75 void validate()const;
76 };
77
87
89 digest_type sig_digest( const chain_id_type& chain_id, const vector<bytes>& cfd = vector<bytes>() )const;
91 const chain_id_type& chain_id,
92 fc::time_point deadline,
93 const vector<bytes>& cfd,
94 flat_set<public_key_type>& recovered_pub_keys,
95 bool allow_duplicate_keys = false) const;
96
97 uint32_t total_actions()const { return context_free_actions.size() + actions.size(); }
98
100 for( const auto& a : actions ) {
101 for( const auto& u : a.authorization )
102 return u.actor;
103 }
104 return account_name();
105 }
106
107 flat_multimap<uint16_t, transaction_extension> validate_and_extract_extensions()const;
108 };
109
111 {
113// signed_transaction( const signed_transaction& ) = default;
114// signed_transaction( signed_transaction&& ) = default;
116 : transaction(std::move(trx))
117 , signatures(signatures)
119 {}
121 : transaction(std::move(trx))
122 , signatures(signatures)
124 {}
125
128
129 const signature_type& sign(const private_key_type& key, const chain_id_type& chain_id);
130 signature_type sign(const private_key_type& key, const chain_id_type& chain_id)const;
132 flat_set<public_key_type>& recovered_pub_keys,
133 bool allow_duplicate_keys = false )const;
134 };
135
137 enum class compression_type {
138 none = 0,
139 zlib = 1,
140 };
141
144 explicit packed_transaction(const packed_transaction&) = default;
147
149 :signatures(t.signatures), compression(_compression), unpacked_trx(t), trx_id(unpacked_trx.id())
150 {
151 local_pack_transaction();
152 local_pack_context_free_data();
153 }
154
156 :signatures(t.signatures), compression(_compression), unpacked_trx(std::move(t)), trx_id(unpacked_trx.id())
157 {
158 local_pack_transaction();
159 local_pack_context_free_data();
160 }
161
162 // used by abi_serializer
163 packed_transaction( bytes&& packed_txn, vector<signature_type>&& sigs, bytes&& packed_cfd, compression_type _compression );
164 packed_transaction( bytes&& packed_txn, vector<signature_type>&& sigs, vector<bytes>&& cfd, compression_type _compression );
165 packed_transaction( transaction&& t, vector<signature_type>&& sigs, bytes&& packed_cfd, compression_type _compression );
166
167 friend bool operator==(const packed_transaction& lhs, const packed_transaction& rhs) {
168 return std::tie(lhs.signatures, lhs.compression, lhs.packed_context_free_data, lhs.packed_trx) ==
169 std::tie(rhs.signatures, rhs.compression, rhs.packed_context_free_data, rhs.packed_trx);
170 }
171 friend bool operator!=(const packed_transaction& lhs, const packed_transaction& rhs) { return !(lhs == rhs); }
172
175 size_t get_estimated_size()const;
176
178
179 const transaction_id_type& id()const { return trx_id; }
181
182 time_point_sec expiration()const { return unpacked_trx.expiration; }
183 const vector<bytes>& get_context_free_data()const { return unpacked_trx.context_free_data; }
184 const transaction& get_transaction()const { return unpacked_trx; }
185 const signed_transaction& get_signed_transaction()const { return unpacked_trx; }
186 const vector<signature_type>& get_signatures()const { return signatures; }
187 const fc::enum_type<uint8_t,compression_type>& get_compression()const { return compression; }
188 const bytes& get_packed_context_free_data()const { return packed_context_free_data; }
189 const bytes& get_packed_transaction()const { return packed_trx; }
190
191 private:
192 void local_unpack_transaction(vector<bytes>&& context_free_data);
193 void local_unpack_context_free_data();
194 void local_pack_transaction();
195 void local_pack_context_free_data();
196
197 friend struct fc::reflector<packed_transaction>;
200 void reflector_init();
201 private:
202 vector<signature_type> signatures;
204 bytes packed_context_free_data;
205 // transaction (not signed_transaction) packed and possibly compressed according to compression
206 bytes packed_trx;
207
208 private:
209 // cache unpacked trx, for thread safety do not modify after construction
210 signed_transaction unpacked_trx;
211 transaction_id_type trx_id;
212 };
213
214 using packed_transaction_ptr = std::shared_ptr<const packed_transaction>;
215
217
218} }
219
220FC_REFLECT(sysio::chain::deferred_transaction_generation_context, (sender_trx_id)(sender_id)(sender) )
221FC_REFLECT( sysio::chain::transaction_header, (expiration)(ref_block_num)(ref_block_prefix)
222 (max_net_usage_words)(max_cpu_usage_ms)(delay_sec) )
223FC_REFLECT_DERIVED( sysio::chain::transaction, (sysio::chain::transaction_header), (context_free_actions)(actions)(transaction_extensions) )
226// @ignore unpacked_trx
227FC_REFLECT( sysio::chain::packed_transaction, (signatures)(compression)(packed_context_free_data)(packed_trx) )
Definition name.hpp:106
transaction_extension_types::transaction_extension_t transaction_extension
std::shared_ptr< const packed_transaction > packed_transaction_ptr
unsigned __int128 uint128_t
Definition types.hpp:242
uint32_t block_num_type
Definition types.hpp:239
uint128_t transaction_id_to_sender_id(const transaction_id_type &tid)
name account_name
Definition types.hpp:120
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition reflect.hpp:311
#define FC_REFLECT_ENUM(ENUM, FIELDS)
Definition reflect.hpp:194
#define FC_REFLECT_DERIVED(TYPE, INHERITS, MEMBERS)
Specializes fc::reflector for TYPE where type inherits other reflected classes.
Definition reflect.hpp:298
unsigned short uint16_t
Definition stdint.h:125
unsigned int uint32_t
Definition stdint.h:126
unsigned char uint8_t
Definition stdint.h:124
defines visit functions for T Unless this is specialized, visit() will not be defined for T.
Definition reflect.hpp:33
deferred_transaction_generation_context(const transaction_id_type &sender_trx_id, uint128_t sender_id, account_name sender)
Immutable except for fc::from_variant.
Definition name.hpp:43
packed_transaction & operator=(const packed_transaction &)=delete
packed_transaction(signed_transaction &&t, compression_type _compression=compression_type::none)
const bytes & get_packed_context_free_data() const
digest_type packed_digest() const
packed_transaction(const signed_transaction &t, compression_type _compression=compression_type::none)
const vector< signature_type > & get_signatures() const
time_point_sec expiration() const
const fc::enum_type< uint8_t, compression_type > & get_compression() const
friend bool operator==(const packed_transaction &lhs, const packed_transaction &rhs)
const vector< bytes > & get_context_free_data() const
packed_transaction(packed_transaction &&)=default
const signed_transaction & get_signed_transaction() const
const transaction_id_type & id() const
const transaction & get_transaction() const
packed_transaction & operator=(packed_transaction &&)=default
const bytes & get_packed_transaction() const
friend bool operator!=(const packed_transaction &lhs, const packed_transaction &rhs)
packed_transaction(const packed_transaction &)=default
vector< bytes > context_free_data
for each context-free action, there is an entry here
vector< signature_type > signatures
fc::microseconds get_signature_keys(const chain_id_type &chain_id, fc::time_point deadline, flat_set< public_key_type > &recovered_pub_keys, bool allow_duplicate_keys=false) const
signed_transaction(transaction &&trx, const vector< signature_type > &signatures, const vector< bytes > &context_free_data)
signed_transaction(transaction &&trx, const vector< signature_type > &signatures, vector< bytes > &&context_free_data)
const signature_type & sign(const private_key_type &key, const chain_id_type &chain_id)
void set_reference_block(const block_id_type &reference_block)
fc::unsigned_int delay_sec
upper limit on the total CPU time billed for this transaction
uint16_t ref_block_num
specifies a block num in the last 2^16 blocks.
uint32_t ref_block_prefix
specifies the lower 32 bits of the blockid at get_ref_blocknum
uint8_t max_cpu_usage_ms
upper limit on total network bandwidth (in 8 byte words) billed for this transaction
block_num_type get_ref_blocknum(block_num_type head_blocknum) const
number of seconds to delay this transaction for during which it may be canceled.
bool verify_reference_block(const block_id_type &reference_block) const
time_point_sec expiration
the time at which a transaction expires
vector< action > actions
uint32_t total_actions() const
vector< action > context_free_actions
extensions_type transaction_extensions
account_name first_authorizer() const
fc::microseconds get_signature_keys(const vector< signature_type > &signatures, const chain_id_type &chain_id, fc::time_point deadline, const vector< bytes > &cfd, flat_set< public_key_type > &recovered_pub_keys, bool allow_duplicate_keys=false) const
digest_type sig_digest(const chain_id_type &chain_id, const vector< bytes > &cfd=vector< bytes >()) const
transaction_id_type id() const
flat_multimap< uint16_t, transaction_extension > validate_and_extract_extensions() const
Definition dtoa.c:306