-
Notifications
You must be signed in to change notification settings - Fork 338
/
assert.hpp
91 lines (76 loc) · 2.64 KB
/
assert.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
#pragma once
#include <graphene/chain/protocol/base.hpp>
namespace graphene { namespace chain {
/**
* Used to verify that account_id->name is equal to the given string literal.
*/
struct account_name_eq_lit_predicate
{
account_id_type account_id;
string name;
/**
* Perform state-independent checks. Verify
* account_name is a valid account name.
*/
bool validate()const;
};
/**
* Used to verify that asset_id->symbol is equal to the given string literal.
*/
struct asset_symbol_eq_lit_predicate
{
asset_id_type asset_id;
string symbol;
/**
* Perform state independent checks. Verify symbol is a
* valid asset symbol.
*/
bool validate()const;
};
/**
* Used to verify that a specific block is part of the
* blockchain history. This helps protect some high-value
* transactions to newly created IDs
*
* The block ID must be within the last 2^16 blocks.
*/
struct block_id_predicate
{
block_id_type id;
bool validate()const{ return true; }
};
/**
* When defining predicates do not make the protocol dependent upon
* implementation details.
*/
typedef static_variant<
account_name_eq_lit_predicate,
asset_symbol_eq_lit_predicate,
block_id_predicate
> predicate;
/**
* @brief assert that some conditions are true.
* @ingroup operations
*
* This operation performs no changes to the database state, but can but used to verify
* pre or post conditions for other operations.
*/
struct assert_operation : public base_operation
{
struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; };
asset fee;
account_id_type fee_paying_account;
vector<predicate> predicates;
flat_set<account_id_type> required_auths;
extensions_type extensions;
account_id_type fee_payer()const { return fee_paying_account; }
void validate()const;
share_type calculate_fee(const fee_parameters_type& k)const;
};
} } // graphene::chain
FC_REFLECT( graphene::chain::assert_operation::fee_parameters_type, (fee) )
FC_REFLECT( graphene::chain::account_name_eq_lit_predicate, (account_id)(name) )
FC_REFLECT( graphene::chain::asset_symbol_eq_lit_predicate, (asset_id)(symbol) )
FC_REFLECT( graphene::chain::block_id_predicate, (id) )
FC_REFLECT_TYPENAME( graphene::chain::predicate )
FC_REFLECT( graphene::chain::assert_operation, (fee)(fee_paying_account)(predicates)(required_auths)(extensions) )