forked from steem-witnesses/steem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
smt_evaluator.cpp
197 lines (160 loc) · 7.55 KB
/
smt_evaluator.cpp
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#include <steem/chain/steem_evaluator.hpp>
#include <steem/chain/database.hpp>
#include <steem/chain/steem_objects.hpp>
#include <steem/chain/smt_objects.hpp>
#include <steem/chain/util/reward.hpp>
#include <steem/protocol/smt_operations.hpp>
#include <steem/protocol/smt_operations.hpp>
#ifdef STEEM_ENABLE_SMT
namespace steem { namespace chain {
namespace {
class smt_setup_parameters_visitor : public fc::visitor<bool>
{
public:
smt_setup_parameters_visitor(smt_token_object& smt_token) : _smt_token(smt_token) {}
bool operator () (const smt_param_allow_voting& allow_voting)
{
_smt_token.allow_voting = allow_voting.value;
return true;
}
bool operator () (const smt_param_allow_vesting& allow_vesting)
{
_smt_token.allow_vesting = allow_vesting.value;
return true;
}
private:
smt_token_object& _smt_token;
};
} // namespace
void smt_elevate_account_evaluator::do_apply( const smt_elevate_account_operation& o )
{
FC_ASSERT( _db.has_hardfork( STEEM_SMT_HARDFORK ), "SMT functionality not enabled until hardfork ${hf}", ("hf", STEEM_SMT_HARDFORK) );
const dynamic_global_property_object& dgpo = _db.get_dynamic_global_properties();
asset effective_elevation_fee;
FC_ASSERT( dgpo.smt_creation_fee.symbol == STEEM_SYMBOL || dgpo.smt_creation_fee.symbol == SBD_SYMBOL,
"Unexpected internal error - wrong symbol ${s} of account elevation fee.", ("s", dgpo.smt_creation_fee.symbol) );
FC_ASSERT( o.fee.symbol == STEEM_SYMBOL || o.fee.symbol == SBD_SYMBOL,
"Asset fee must be STEEM or SBD, was ${s}", ("s", o.fee.symbol) );
if( o.fee.symbol == dgpo.smt_creation_fee.symbol )
{
effective_elevation_fee = dgpo.smt_creation_fee;
}
else
{
const auto& fhistory = _db.get_feed_history();
FC_ASSERT( !fhistory.current_median_history.is_null(), "Cannot pay the fee using SBD because there is no price feed." );
if( o.fee.symbol == STEEM_SYMBOL )
{
effective_elevation_fee = _db.to_sbd( o.fee );
}
else
{
effective_elevation_fee = _db.to_steem( o.fee );
}
}
const account_object& acct = _db.get_account( o.account );
FC_ASSERT( o.fee >= effective_elevation_fee, "Fee of ${of} is too small, must be at least ${ef}", ("of", o.fee)("ef", effective_elevation_fee) );
FC_ASSERT( _db.get_balance( acct, o.fee.symbol ) >= o.fee, "Account does not have sufficient funds for specified fee of ${of}", ("of", o.fee) );
const account_object& null_account = _db.get_account( STEEM_NULL_ACCOUNT );
_db.adjust_balance( acct , -o.fee );
_db.adjust_balance( null_account, o.fee );
_db.create< smt_token_object >( [&]( smt_token_object& token )
{
token.control_account = o.account;
});
}
void smt_setup_evaluator::do_apply( const smt_setup_operation& o )
{
FC_ASSERT( _db.has_hardfork( STEEM_SMT_HARDFORK ), "SMT functionality not enabled until hardfork ${hf}", ("hf", STEEM_SMT_HARDFORK) );
}
void smt_cap_reveal_evaluator::do_apply( const smt_cap_reveal_operation& o )
{
FC_ASSERT( _db.has_hardfork( STEEM_SMT_HARDFORK ), "SMT functionality not enabled until hardfork ${hf}", ("hf", STEEM_SMT_HARDFORK) );
}
void smt_refund_evaluator::do_apply( const smt_refund_operation& o )
{
FC_ASSERT( _db.has_hardfork( STEEM_SMT_HARDFORK ), "SMT functionality not enabled until hardfork ${hf}", ("hf", STEEM_SMT_HARDFORK) );
}
void smt_setup_emissions_evaluator::do_apply( const smt_setup_emissions_operation& o )
{
FC_ASSERT( _db.has_hardfork( STEEM_SMT_HARDFORK ), "SMT functionality not enabled until hardfork ${hf}", ("hf", STEEM_SMT_HARDFORK) );
const smt_token_object* smt = _db.find< smt_token_object, by_control_account >( o.control_account );
// Check whether it's not too early or too late to setup emissions operation.
FC_ASSERT( smt != nullptr, "SMT ${smt} not found", ("smt", o.control_account ) );
// ^ TODO: Replace SMT name with appropriate id in the assertion.
FC_ASSERT( smt->phase < smt_token_object::smt_phase::setup_completed, "SMT emission operation no longer allowed after setup phase is over" );
_db.modify( *smt, [&]( smt_token_object& token )
{
token.schedule_time = o.schedule_time;
token.emissions_unit = o.emissions_unit;
token.interval_seconds = o.interval_seconds;
token.interval_count = o.interval_count;
token.lep_time = o.lep_time;
token.rep_time = o.rep_time;
token.lep_abs_amount = o.lep_abs_amount;
token.rep_abs_amount = o.rep_abs_amount;
token.lep_rel_amount_numerator = o.lep_rel_amount_numerator;
token.rep_rel_amount_numerator = o.rep_rel_amount_numerator;
token.rel_amount_denom_bits = o.rel_amount_denom_bits;
});
}
void smt_set_setup_parameters_evaluator::do_apply( const smt_set_setup_parameters_operation& o )
{
FC_ASSERT( _db.has_hardfork( STEEM_SMT_HARDFORK ), "SMT functionality not enabled until hardfork ${hf}", ("hf", STEEM_SMT_HARDFORK) );
auto& smt_token_by_account = _db.get_index<smt_token_index, by_control_account>();
auto it = smt_token_by_account.find(o.control_account);
FC_ASSERT( it != smt_token_by_account.end(), "SMT ${ac} not elevated yet.", ("ac", o.control_account));
const smt_token_object& smt_token = *it;
FC_ASSERT( smt_token.phase < smt_token_object::smt_phase::setup_completed, "SMT ${ac} setup already completed.", ("ac", o.control_account));
_db.modify( smt_token, [&]( smt_token_object& token )
{
smt_setup_parameters_visitor visitor(token);
for (auto& param : o.setup_parameters)
param.visit(visitor);
});
}
struct smt_set_runtime_parameters_evaluator_visitor
{
const smt_token_object& _token;
database& _db;
smt_set_runtime_parameters_evaluator_visitor( const smt_token_object& token, database& db ): _token( token ), _db( db ){}
typedef void result_type;
void operator()( const smt_param_windows_v1& param_windows ) const
{
_db.modify( _token, [&]( smt_token_object& token )
{
token.cashout_window_seconds = param_windows.cashout_window_seconds;
token.reverse_auction_window_seconds = param_windows.reverse_auction_window_seconds;
});
}
void operator()( const smt_param_vote_regeneration_period_seconds_v1& vote_regeneration ) const
{
_db.modify( _token, [&]( smt_token_object& token )
{
token.vote_regeneration_period_seconds = vote_regeneration.vote_regeneration_period_seconds;
token.votes_per_regeneration_period = vote_regeneration.votes_per_regeneration_period;
});
}
void operator()( const smt_param_rewards_v1& param_rewards ) const
{
_db.modify( _token, [&]( smt_token_object& token )
{
token.content_constant = param_rewards.content_constant;
token.percent_curation_rewards = param_rewards.percent_curation_rewards;
token.percent_content_rewards = param_rewards.percent_content_rewards;
token.author_reward_curve = param_rewards.author_reward_curve;
token.curation_reward_curve = param_rewards.curation_reward_curve;
});
}
};
void smt_set_runtime_parameters_evaluator::do_apply( const smt_set_runtime_parameters_operation& o )
{
FC_ASSERT( _db.has_hardfork( STEEM_SMT_HARDFORK ), "SMT functionality not enabled until hardfork ${hf}", ("hf", STEEM_SMT_HARDFORK) );
const auto* _token = _db.find< smt_token_object, by_control_account >( o.control_account );
FC_ASSERT( _token, "SMT ${ac} not elevated yet.",("ac", o.control_account) );
smt_set_runtime_parameters_evaluator_visitor visitor( *_token, _db );
for( auto& param: o.runtime_parameters )
param.visit( visitor );
}
} }
#endif