BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface software
transaction.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cryptonomex, Inc., and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #pragma once
26 
27 namespace graphene { namespace protocol {
28  struct predicate_result;
29 
31  using rejected_predicate_map = map<custom_authority_id_type, rejected_predicate>;
32  using custom_authority_lookup = std::function<vector<authority>(account_id_type, const operation&,
34 
69  {
70  public:
71  virtual ~transaction() = default;
76  uint16_t ref_block_num = 0;
82  uint32_t ref_block_prefix = 0;
83 
88 
89  vector<operation> operations;
91 
93  digest_type digest()const;
94  virtual const transaction_id_type& id()const;
95  virtual void validate() const;
96 
97  void set_expiration( fc::time_point_sec expiration_time );
98  void set_reference_block( const block_id_type& reference_block );
99 
101  template<typename Visitor>
102  vector<typename Visitor::result_type> visit( Visitor&& visitor )
103  {
104  vector<typename Visitor::result_type> results;
105  for( auto& op : operations )
106  results.push_back(op.visit( std::forward<Visitor>( visitor ) ));
107  return results;
108  }
109  template<typename Visitor>
110  vector<typename Visitor::result_type> visit( Visitor&& visitor )const
111  {
112  vector<typename Visitor::result_type> results;
113  for( auto& op : operations )
114  results.push_back(op.visit( std::forward<Visitor>( visitor ) ));
115  return results;
116  }
117 
118  void get_required_authorities( flat_set<account_id_type>& active,
119  flat_set<account_id_type>& owner,
120  vector<authority>& other,
121  bool ignore_custom_operation_required_auths )const;
122 
123  virtual uint64_t get_packed_size()const;
124 
125  protected:
126  // Calculate the digest used for signature validation
127  digest_type sig_digest( const chain_id_type& chain_id )const;
129  };
130 
135  {
136  public:
138  : transaction(trx){}
139  virtual ~signed_transaction() = default;
140 
142  const signature_type& sign( const private_key_type& key, const chain_id_type& chain_id );
143 
145  signature_type sign( const private_key_type& key, const chain_id_type& chain_id )const;
146 
154  set<public_key_type> get_required_signatures(
155  const chain_id_type& chain_id,
156  const flat_set<public_key_type>& available_keys,
157  const std::function<const authority*(account_id_type)>& get_active,
158  const std::function<const authority*(account_id_type)>& get_owner,
159  bool allow_non_immediate_owner,
160  bool ignore_custom_operation_required_authorities,
161  uint32_t max_recursion = GRAPHENE_MAX_SIG_CHECK_DEPTH )const;
162 
178  void verify_authority(
179  const chain_id_type& chain_id,
180  const std::function<const authority*(account_id_type)>& get_active,
181  const std::function<const authority*(account_id_type)>& get_owner,
182  const custom_authority_lookup& get_custom,
183  bool allow_non_immediate_owner,
184  bool ignore_custom_operation_required_auths,
185  uint32_t max_recursion = GRAPHENE_MAX_SIG_CHECK_DEPTH )const;
186 
193  set<public_key_type> minimize_required_signatures(
194  const chain_id_type& chain_id,
195  const flat_set<public_key_type>& available_keys,
196  const std::function<const authority*(account_id_type)>& get_active,
197  const std::function<const authority*(account_id_type)>& get_owner,
198  const custom_authority_lookup& get_custom,
199  bool allow_non_immediate_owner,
200  bool ignore_custom_operation_required_auths,
201  uint32_t max_recursion = GRAPHENE_MAX_SIG_CHECK_DEPTH) const;
202 
214  virtual const flat_set<public_key_type>& get_signature_keys( const chain_id_type& chain_id )const;
215 
217  vector<signature_type> signatures;
218 
220  void clear() { operations.clear(); signatures.clear(); }
221 
223  void clear_signatures() { signatures.clear(); }
224  protected:
226  mutable flat_set<public_key_type> _signees;
227  };
228 
234  public:
238  virtual ~precomputable_transaction() = default;
239 
240  virtual const transaction_id_type& id()const override;
241  virtual void validate()const override;
242  virtual const flat_set<public_key_type>& get_signature_keys( const chain_id_type& chain_id )const override;
243  virtual uint64_t get_packed_size()const override;
244  protected:
245  mutable bool _validated = false;
246  mutable uint64_t _packed_size = 0;
247  };
248 
268  void verify_authority( const vector<operation>& ops, const flat_set<public_key_type>& sigs,
269  const std::function<const authority*(account_id_type)>& get_active,
270  const std::function<const authority*(account_id_type)>& get_owner,
271  const custom_authority_lookup& get_custom,
272  bool allow_non_immediate_owner,
273  bool ignore_custom_operation_required_auths,
274  uint32_t max_recursion = GRAPHENE_MAX_SIG_CHECK_DEPTH,
275  bool allow_committee = false,
276  const flat_set<account_id_type>& active_aprovals = flat_set<account_id_type>(),
277  const flat_set<account_id_type>& owner_approvals = flat_set<account_id_type>() );
278 
293  {
296  virtual ~processed_transaction() = default;
297 
298  vector<operation_result> operation_results;
299 
300  digest_type merkle_digest()const;
301  };
302 
304 
305 } } // graphene::protocol
306 
308 // Note: not reflecting signees field for backward compatibility; in addition, it should not be in p2p messages
309 FC_REFLECT_DERIVED( graphene::protocol::signed_transaction, (graphene::protocol::transaction), (signatures) )
310 FC_REFLECT_DERIVED( graphene::protocol::precomputable_transaction, (graphene::protocol::signed_transaction), )
311 FC_REFLECT_DERIVED( graphene::protocol::processed_transaction, (graphene::protocol::precomputable_transaction), (operation_results) )
312 
313 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::protocol::transaction)
314 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::protocol::signed_transaction)
315 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::protocol::precomputable_transaction)
316 GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::protocol::processed_transaction)
future_extensions::flat_set_type extensions_type
Definition: base.hpp:128
virtual const transaction_id_type & id() const
Definition: transaction.cpp:70
fc::time_point_sec expiration
Definition: transaction.hpp:87
Identifies a weighted set of keys and accounts that must approve operations.
Definition: authority.hpp:34
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition: reflect.hpp:386
map< custom_authority_id_type, rejected_predicate > rejected_predicate_map
Definition: transaction.hpp:31
vector< operation > operations
Definition: transaction.hpp:89
virtual void validate() const
Definition: transaction.cpp:58
Definition: api.cpp:56
precomputable_transaction(const signed_transaction &tx)
vector< typename Visitor::result_type > visit(Visitor &&visitor) const
std::function< vector< authority >(account_id_type, const operation &, rejected_predicate_map *)> custom_authority_lookup
Definition: transaction.hpp:33
transaction_id_type _tx_id_buffer
flat_set< public_key_type > _signees
void get_required_authorities(flat_set< account_id_type > &active, flat_set< account_id_type > &owner, vector< authority > &other, bool ignore_custom_operation_required_auths) const
digest_type sig_digest(const chain_id_type &chain_id) const
Definition: transaction.cpp:50
groups operations that should be applied atomically
Definition: transaction.hpp:68
void set_reference_block(const block_id_type &reference_block)
Definition: transaction.cpp:97
FC_REFLECT_DERIVED(graphene::app::extended_asset_object,(graphene::chain::asset_object),(total_in_collateral)(total_backing_collateral))
precomputable_transaction(signed_transaction &&tx)
virtual ~transaction()=default
virtual uint64_t get_packed_size() const
Definition: transaction.cpp:65
vector< operation_result > operation_results
void set_expiration(fc::time_point_sec expiration_time)
Definition: transaction.cpp:92
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:73
void verify_authority(const vector< operation > &ops, const flat_set< public_key_type > &sigs, const std::function< const authority *(account_id_type)> &get_active, const std::function< const authority *(account_id_type)> &get_owner, const custom_authority_lookup &get_custom, bool allow_non_immediate_owner, bool ignore_custom_operation_required_auths, uint32_t max_recursion=GRAPHENE_MAX_SIG_CHECK_DEPTH, bool allow_committee=false, const flat_set< account_id_type > &active_aprovals=flat_set< account_id_type >(), const flat_set< account_id_type > &owner_approvals=flat_set< account_id_type >())
#define GRAPHENE_MAX_SIG_CHECK_DEPTH
Definition: config.hpp:43
adds a signature to a transaction
digest_type digest() const
Calculate the digest for a transaction.
Definition: transaction.cpp:43
signed_transaction(const transaction &trx=transaction())
processed_transaction(const signed_transaction &trx=signed_transaction())
an elliptic curve private key.
Definition: elliptic.hpp:89
captures the result of evaluating the operations contained in the transaction
vector< signature_type > signatures
vector< typename Visitor::result_type > visit(Visitor &&visitor)
visit all operations