Scorum
transaction.hpp
Go to the documentation of this file.
1 #pragma once
5 
6 #include <numeric>
7 
8 namespace scorum {
9 namespace protocol {
10 
12 {
13  uint16_t ref_block_num = 0;
14  uint32_t ref_block_prefix = 0;
15 
16  fc::time_point_sec expiration;
17 
18  std::vector<operation> operations;
20 
21  digest_type digest() const;
22  transaction_id_type id() const;
23  void validate() const;
24  digest_type sig_digest(const chain_id_type& chain_id) const;
25 
26  void set_expiration(fc::time_point_sec expiration_time);
27  void set_reference_block(const block_id_type& reference_block);
28 
29  template <typename Visitor> std::vector<typename Visitor::result_type> visit(Visitor&& visitor)
30  {
31  std::vector<typename Visitor::result_type> results;
32  for (auto& op : operations)
33  results.push_back(op.visit(std::forward<Visitor>(visitor)));
34  return results;
35  }
36  template <typename Visitor> std::vector<typename Visitor::result_type> visit(Visitor&& visitor) const
37  {
38  std::vector<typename Visitor::result_type> results;
39  for (auto& op : operations)
40  results.push_back(op.visit(std::forward<Visitor>(visitor)));
41  return results;
42  }
43 
44  void get_required_authorities(flat_set<account_name_type>& active,
45  flat_set<account_name_type>& owner,
46  flat_set<account_name_type>& posting,
47  std::vector<authority>& other) const;
48 };
49 
51 {
53  : transaction(trx)
54  {
55  }
56 
57  const signature_type& sign(const private_key_type& key, const chain_id_type& chain_id);
58 
59  signature_type sign(const private_key_type& key, const chain_id_type& chain_id) const;
60 
61  std::set<public_key_type> get_required_signatures(const chain_id_type& chain_id,
62  const flat_set<public_key_type>& available_keys,
63  const authority_getter& get_active,
64  const authority_getter& get_owner,
65  const authority_getter& get_posting,
66  uint32_t max_recursion = SCORUM_MAX_SIG_CHECK_DEPTH) const;
67 
68  void verify_authority(const chain_id_type& chain_id,
69  const authority_getter& get_active,
70  const authority_getter& get_owner,
71  const authority_getter& get_posting,
72  uint32_t max_recursion = SCORUM_MAX_SIG_CHECK_DEPTH) const;
73 
74  std::set<public_key_type> minimize_required_signatures(const chain_id_type& chain_id,
75  const flat_set<public_key_type>& available_keys,
76  const authority_getter& get_active,
77  const authority_getter& get_owner,
78  const authority_getter& get_posting,
79  uint32_t max_recursion = SCORUM_MAX_SIG_CHECK_DEPTH) const;
80 
81  flat_set<public_key_type> get_signature_keys(const chain_id_type& chain_id) const;
82 
83  std::vector<signature_type> signatures;
84 
85  digest_type merkle_digest() const;
86 
87  void clear()
88  {
89  operations.clear();
90  signatures.clear();
91  }
92 };
93 
94 void verify_authority(const std::vector<operation>& ops,
95  const flat_set<public_key_type>& sigs,
96  const authority_getter& get_active,
97  const authority_getter& get_owner,
98  const authority_getter& get_posting,
99  uint32_t max_recursion = SCORUM_MAX_SIG_CHECK_DEPTH,
100  bool allow_committe = false,
101  const flat_set<account_name_type>& active_aprovals = flat_set<account_name_type>(),
102  const flat_set<account_name_type>& owner_aprovals = flat_set<account_name_type>(),
103  const flat_set<account_name_type>& posting_approvals = flat_set<account_name_type>());
104 
106 {
108  {
109  }
111  : signed_transaction(trx)
112  , transaction_id(trx.id())
113  {
114  }
115 
117  uint32_t block_num = 0;
118  uint32_t transaction_num = 0;
119 };
120 
122 }
123 } // scorum::protocol
124 
125 FC_REFLECT(scorum::protocol::transaction, (ref_block_num)(ref_block_prefix)(expiration)(operations)(extensions))
126 FC_REFLECT_DERIVED(scorum::protocol::signed_transaction, (scorum::protocol::transaction), (signatures))
129  (transaction_id)(block_num)(transaction_num));
FC_REFLECT(appender_args,(appender)(stream)) FC_REFLECT_DERIVED(file_appender_args
fc::ecc::private_key private_key_type
Definition: types.hpp:60
fc::ripemd160 transaction_id_type
Definition: types.hpp:65
fc::sha256 chain_id_type
Definition: types.hpp:61
void verify_authority(const std::vector< operation > &ops, const flat_set< public_key_type > &sigs, const authority_getter &get_active, const authority_getter &get_owner, const authority_getter &get_posting, uint32_t max_recursion=SCORUM_MAX_SIG_CHECK_DEPTH, bool allow_committe=false, const flat_set< account_name_type > &active_aprovals=flat_set< account_name_type >(), const flat_set< account_name_type > &owner_aprovals=flat_set< account_name_type >(), const flat_set< account_name_type > &posting_approvals=flat_set< account_name_type >())
Definition: transaction.cpp:88
fc::sha256 digest_type
Definition: types.hpp:66
fc::ripemd160 block_id_type
Definition: types.hpp:63
flat_set< future_extensions > extensions_type
Definition: base.hpp:83
std::function< authority(const std::string &)> authority_getter
Definition: sign_state.hpp:9
fc::ecc::compact_signature signature_type
Definition: types.hpp:67
Definition: asset.cpp:15
annotated_signed_transaction(const signed_transaction &trx)
const signature_type & sign(const private_key_type &key, const chain_id_type &chain_id)
Definition: transaction.cpp:51
flat_set< public_key_type > get_signature_keys(const chain_id_type &chain_id) const
void verify_authority(const chain_id_type &chain_id, const authority_getter &get_active, const authority_getter &get_owner, const authority_getter &get_posting, uint32_t max_recursion=SCORUM_MAX_SIG_CHECK_DEPTH) const
std::set< public_key_type > get_required_signatures(const chain_id_type &chain_id, const flat_set< public_key_type > &available_keys, const authority_getter &get_active, const authority_getter &get_owner, const authority_getter &get_posting, uint32_t max_recursion=SCORUM_MAX_SIG_CHECK_DEPTH) const
std::set< public_key_type > minimize_required_signatures(const chain_id_type &chain_id, const flat_set< public_key_type > &available_keys, const authority_getter &get_active, const authority_getter &get_owner, const authority_getter &get_posting, uint32_t max_recursion=SCORUM_MAX_SIG_CHECK_DEPTH) const
signed_transaction(const transaction &trx=transaction())
Definition: transaction.hpp:52
std::vector< signature_type > signatures
Definition: transaction.hpp:83
transaction_id_type id() const
Definition: transaction.cpp:43
std::vector< operation > operations
Definition: transaction.hpp:18
std::vector< typename Visitor::result_type > visit(Visitor &&visitor) const
Definition: transaction.hpp:36
fc::time_point_sec expiration
Definition: transaction.hpp:16
void get_required_authorities(flat_set< account_name_type > &active, flat_set< account_name_type > &owner, flat_set< account_name_type > &posting, std::vector< authority > &other) const
Definition: transaction.cpp:79
void set_reference_block(const block_id_type &reference_block)
Definition: transaction.cpp:73
digest_type sig_digest(const chain_id_type &chain_id) const
Definition: transaction.cpp:28
digest_type digest() const
Definition: transaction.cpp:21
void set_expiration(fc::time_point_sec expiration_time)
Definition: transaction.cpp:68
std::vector< typename Visitor::result_type > visit(Visitor &&visitor)
Definition: transaction.hpp:29