forked from steemit/steem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteem_operations.cpp
549 lines (471 loc) · 21.5 KB
/
steem_operations.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
#include <steemit/protocol/steem_operations.hpp>
#include <fc/io/json.hpp>
#include <locale>
namespace steemit { namespace protocol {
bool inline is_asset_type( asset asset, asset_symbol_type symbol )
{
return asset.symbol == symbol;
}
void account_create_operation::validate() const
{
validate_account_name( new_account_name );
FC_ASSERT( is_asset_type( fee, STEEM_SYMBOL ), "Account creation fee must be STEEM" );
owner.validate();
active.validate();
if ( json_metadata.size() > 0 )
{
FC_ASSERT( fc::is_utf8(json_metadata), "JSON Metadata not formatted in UTF8" );
FC_ASSERT( fc::json::is_valid(json_metadata), "JSON Metadata not valid JSON" );
}
FC_ASSERT( fee >= asset( 0, STEEM_SYMBOL ), "Account creation fee cannot be negative" );
}
void account_create_with_delegation_operation::validate() const
{
validate_account_name( new_account_name );
validate_account_name( creator );
FC_ASSERT( is_asset_type( fee, STEEM_SYMBOL ), "Account creation fee must be STEEM" );
FC_ASSERT( is_asset_type( delegation, VESTS_SYMBOL ), "Delegation must be VESTS" );
owner.validate();
active.validate();
posting.validate();
if( json_metadata.size() > 0 )
{
FC_ASSERT( fc::is_utf8(json_metadata), "JSON Metadata not formatted in UTF8" );
FC_ASSERT( fc::json::is_valid(json_metadata), "JSON Metadata not valid JSON" );
}
FC_ASSERT( fee >= asset( 0, STEEM_SYMBOL ), "Account creation fee cannot be negative" );
FC_ASSERT( delegation >= asset( 0, VESTS_SYMBOL ), "Delegation cannot be negative" );
}
void account_update_operation::validate() const
{
validate_account_name( account );
/*if( owner )
owner->validate();
if( active )
active->validate();
if( posting )
posting->validate();*/
if ( json_metadata.size() > 0 )
{
FC_ASSERT( fc::is_utf8(json_metadata), "JSON Metadata not formatted in UTF8" );
FC_ASSERT( fc::json::is_valid(json_metadata), "JSON Metadata not valid JSON" );
}
}
void comment_operation::validate() const
{
FC_ASSERT( title.size() < 256, "Title larger than size limit" );
FC_ASSERT( fc::is_utf8( title ), "Title not formatted in UTF8" );
FC_ASSERT( body.size() > 0, "Body is empty" );
FC_ASSERT( fc::is_utf8( body ), "Body not formatted in UTF8" );
if( parent_author.size() )
validate_account_name( parent_author );
validate_account_name( author );
validate_permlink( parent_permlink );
validate_permlink( permlink );
if( json_metadata.size() > 0 )
{
FC_ASSERT( fc::json::is_valid(json_metadata), "JSON Metadata not valid JSON" );
}
}
struct comment_options_extension_validate_visitor
{
comment_options_extension_validate_visitor() {}
typedef void result_type;
void operator()( const comment_payout_beneficiaries& cpb ) const
{
cpb.validate();
}
};
void comment_payout_beneficiaries::validate()const
{
uint32_t sum = 0;
FC_ASSERT( beneficiaries.size(), "Must specify at least one beneficiary" );
FC_ASSERT( beneficiaries.size() < 128, "Cannot specify more than 127 beneficiaries." ); // Require size serializtion fits in one byte.
validate_account_name( beneficiaries[0].account );
FC_ASSERT( beneficiaries[0].weight <= STEEMIT_100_PERCENT, "Cannot allocate more than 100% of rewards to one account" );
sum += beneficiaries[0].weight;
FC_ASSERT( sum <= STEEMIT_100_PERCENT, "Cannot allocate more than 100% of rewards to a comment" ); // Have to check incrementally to avoid overflow
for( size_t i = 1; i < beneficiaries.size(); i++ )
{
validate_account_name( beneficiaries[i].account );
FC_ASSERT( beneficiaries[i].weight <= STEEMIT_100_PERCENT, "Cannot allocate more than 100% of rewards to one account" );
sum += beneficiaries[i].weight;
FC_ASSERT( sum <= STEEMIT_100_PERCENT, "Cannot allocate more than 100% of rewards to a comment" ); // Have to check incrementally to avoid overflow
FC_ASSERT( beneficiaries[i - 1] < beneficiaries[i], "Benficiaries must be specified in sorted order (account ascending)" );
}
}
void comment_options_operation::validate()const
{
validate_account_name( author );
FC_ASSERT( percent_steem_dollars <= STEEMIT_100_PERCENT, "Percent cannot exceed 100%" );
FC_ASSERT( max_accepted_payout.symbol == SBD_SYMBOL, "Max accepted payout must be in SBD" );
FC_ASSERT( max_accepted_payout.amount.value >= 0, "Cannot accept less than 0 payout" );
validate_permlink( permlink );
for( auto& e : extensions )
e.visit( comment_options_extension_validate_visitor() );
}
void delete_comment_operation::validate()const
{
validate_permlink( permlink );
validate_account_name( author );
}
void challenge_authority_operation::validate()const
{
validate_account_name( challenger );
validate_account_name( challenged );
FC_ASSERT( challenged != challenger, "cannot challenge yourself" );
}
void prove_authority_operation::validate()const
{
validate_account_name( challenged );
}
void vote_operation::validate() const
{
validate_account_name( voter );
validate_account_name( author );\
FC_ASSERT( abs(weight) <= STEEMIT_100_PERCENT, "Weight is not a STEEMIT percentage" );
validate_permlink( permlink );
}
void transfer_operation::validate() const
{ try {
validate_account_name( from );
validate_account_name( to );
FC_ASSERT( amount.symbol != VESTS_SYMBOL, "transferring of Steem Power (STMP) is not allowed." );
FC_ASSERT( amount.amount > 0, "Cannot transfer a negative amount (aka: stealing)" );
FC_ASSERT( memo.size() < STEEMIT_MAX_MEMO_SIZE, "Memo is too large" );
FC_ASSERT( fc::is_utf8( memo ), "Memo is not UTF8" );
} FC_CAPTURE_AND_RETHROW( (*this) ) }
void transfer_to_vesting_operation::validate() const
{
validate_account_name( from );
FC_ASSERT( is_asset_type( amount, STEEM_SYMBOL ), "Amount must be STEEM" );
if ( to != account_name_type() ) validate_account_name( to );
FC_ASSERT( amount > asset( 0, STEEM_SYMBOL ), "Must transfer a nonzero amount" );
}
void withdraw_vesting_operation::validate() const
{
validate_account_name( account );
FC_ASSERT( is_asset_type( vesting_shares, VESTS_SYMBOL), "Amount must be VESTS" );
}
void set_withdraw_vesting_route_operation::validate() const
{
validate_account_name( from_account );
validate_account_name( to_account );
FC_ASSERT( 0 <= percent && percent <= STEEMIT_100_PERCENT, "Percent must be valid steemit percent" );
}
void witness_update_operation::validate() const
{
validate_account_name( owner );
FC_ASSERT( url.size() > 0, "URL size must be greater than 0" );
FC_ASSERT( fc::is_utf8( url ), "URL is not valid UTF8" );
FC_ASSERT( fee >= asset( 0, STEEM_SYMBOL ), "Fee cannot be negative" );
props.validate();
}
void account_witness_vote_operation::validate() const
{
validate_account_name( account );
validate_account_name( witness );
}
void account_witness_proxy_operation::validate() const
{
validate_account_name( account );
if( proxy.size() )
validate_account_name( proxy );
FC_ASSERT( proxy != account, "Cannot proxy to self" );
}
void custom_operation::validate() const {
/// required auth accounts are the ones whose bandwidth is consumed
FC_ASSERT( required_auths.size() > 0, "at least on account must be specified" );
}
void custom_json_operation::validate() const {
/// required auth accounts are the ones whose bandwidth is consumed
FC_ASSERT( (required_auths.size() + required_posting_auths.size()) > 0, "at least on account must be specified" );
FC_ASSERT( id.size() <= 32, "id is too long" );
FC_ASSERT( fc::is_utf8(json), "JSON Metadata not formatted in UTF8" );
FC_ASSERT( fc::json::is_valid(json), "JSON Metadata not valid JSON" );
}
void custom_binary_operation::validate() const {
/// required auth accounts are the ones whose bandwidth is consumed
FC_ASSERT( (required_owner_auths.size() + required_active_auths.size() + required_posting_auths.size()) > 0, "at least on account must be specified" );
FC_ASSERT( id.size() <= 32, "id is too long" );
for( const auto& a : required_auths ) a.validate();
}
fc::sha256 pow_operation::work_input()const
{
auto hash = fc::sha256::hash( block_id );
hash._hash[0] = nonce;
return fc::sha256::hash( hash );
}
void pow_operation::validate()const
{
props.validate();
validate_account_name( worker_account );
FC_ASSERT( work_input() == work.input, "Determninistic input does not match recorded input" );
work.validate();
}
struct pow2_operation_validate_visitor
{
typedef void result_type;
template< typename PowType >
void operator()( const PowType& pow )const
{
pow.validate();
}
};
void pow2_operation::validate()const
{
props.validate();
work.visit( pow2_operation_validate_visitor() );
}
struct pow2_operation_get_required_active_visitor
{
typedef void result_type;
pow2_operation_get_required_active_visitor( flat_set< account_name_type >& required_active )
: _required_active( required_active ) {}
template< typename PowType >
void operator()( const PowType& work )const
{
_required_active.insert( work.input.worker_account );
}
flat_set<account_name_type>& _required_active;
};
void pow2_operation::get_required_active_authorities( flat_set<account_name_type>& a )const
{
if( !new_owner_key )
{
pow2_operation_get_required_active_visitor vtor( a );
work.visit( vtor );
}
}
void pow::create( const fc::ecc::private_key& w, const digest_type& i )
{
input = i;
signature = w.sign_compact(input,false);
auto sig_hash = fc::sha256::hash( signature );
public_key_type recover = fc::ecc::public_key( signature, sig_hash, false );
work = fc::sha256::hash(recover);
}
void pow2::create( const block_id_type& prev, const account_name_type& account_name, uint64_t n )
{
input.worker_account = account_name;
input.prev_block = prev;
input.nonce = n;
auto prv_key = fc::sha256::hash( input );
auto input = fc::sha256::hash( prv_key );
auto signature = fc::ecc::private_key::regenerate( prv_key ).sign_compact(input);
auto sig_hash = fc::sha256::hash( signature );
public_key_type recover = fc::ecc::public_key( signature, sig_hash );
fc::sha256 work = fc::sha256::hash(std::make_pair(input,recover));
pow_summary = work.approx_log_32();
}
void equihash_pow::create( const block_id_type& recent_block, const account_name_type& account_name, uint32_t nonce )
{
input.worker_account = account_name;
input.prev_block = recent_block;
input.nonce = nonce;
auto seed = fc::sha256::hash( input );
proof = fc::equihash::proof::hash( STEEMIT_EQUIHASH_N, STEEMIT_EQUIHASH_K, seed );
pow_summary = fc::sha256::hash( proof.inputs ).approx_log_32();
}
void pow::validate()const
{
FC_ASSERT( work != fc::sha256() );
FC_ASSERT( public_key_type(fc::ecc::public_key( signature, input, false )) == worker );
auto sig_hash = fc::sha256::hash( signature );
public_key_type recover = fc::ecc::public_key( signature, sig_hash, false );
FC_ASSERT( work == fc::sha256::hash(recover) );
}
void pow2::validate()const
{
validate_account_name( input.worker_account );
pow2 tmp; tmp.create( input.prev_block, input.worker_account, input.nonce );
FC_ASSERT( pow_summary == tmp.pow_summary, "reported work does not match calculated work" );
}
void equihash_pow::validate() const
{
validate_account_name( input.worker_account );
auto seed = fc::sha256::hash( input );
FC_ASSERT( proof.n == STEEMIT_EQUIHASH_N, "proof of work 'n' value is incorrect" );
FC_ASSERT( proof.k == STEEMIT_EQUIHASH_K, "proof of work 'k' value is incorrect" );
FC_ASSERT( proof.seed == seed, "proof of work seed does not match expected seed" );
FC_ASSERT( proof.is_valid(), "proof of work is not a solution", ("block_id", input.prev_block)("worker_account", input.worker_account)("nonce", input.nonce) );
FC_ASSERT( pow_summary == fc::sha256::hash( proof.inputs ).approx_log_32() );
}
void feed_publish_operation::validate()const
{
validate_account_name( publisher );
FC_ASSERT( ( is_asset_type( exchange_rate.base, STEEM_SYMBOL ) && is_asset_type( exchange_rate.quote, SBD_SYMBOL ) )
|| ( is_asset_type( exchange_rate.base, SBD_SYMBOL ) && is_asset_type( exchange_rate.quote, STEEM_SYMBOL ) ),
"Price feed must be a STEEM/SBD price" );
exchange_rate.validate();
}
void limit_order_create_operation::validate()const
{
validate_account_name( owner );
FC_ASSERT( ( is_asset_type( amount_to_sell, STEEM_SYMBOL ) && is_asset_type( min_to_receive, SBD_SYMBOL ) )
|| ( is_asset_type( amount_to_sell, SBD_SYMBOL ) && is_asset_type( min_to_receive, STEEM_SYMBOL ) ),
"Limit order must be for the STEEM:SBD market" );
(amount_to_sell / min_to_receive).validate();
}
void limit_order_create2_operation::validate()const
{
validate_account_name( owner );
FC_ASSERT( amount_to_sell.symbol == exchange_rate.base.symbol, "Sell asset must be the base of the price" );
exchange_rate.validate();
FC_ASSERT( ( is_asset_type( amount_to_sell, STEEM_SYMBOL ) && is_asset_type( exchange_rate.quote, SBD_SYMBOL ) ) ||
( is_asset_type( amount_to_sell, SBD_SYMBOL ) && is_asset_type( exchange_rate.quote, STEEM_SYMBOL ) ),
"Limit order must be for the STEEM:SBD market" );
FC_ASSERT( (amount_to_sell * exchange_rate).amount > 0, "Amount to sell cannot round to 0 when traded" );
}
void limit_order_cancel_operation::validate()const
{
validate_account_name( owner );
}
void convert_operation::validate()const
{
validate_account_name( owner );
/// only allow conversion from SBD to STEEM, allowing the opposite can enable traders to abuse
/// market fluxuations through converting large quantities without moving the price.
FC_ASSERT( is_asset_type( amount, SBD_SYMBOL ), "Can only convert SBD to STEEM" );
FC_ASSERT( amount.amount > 0, "Must convert some SBD" );
}
void report_over_production_operation::validate()const
{
validate_account_name( reporter );
validate_account_name( first_block.witness );
FC_ASSERT( first_block.witness == second_block.witness );
FC_ASSERT( first_block.timestamp == second_block.timestamp );
FC_ASSERT( first_block.signee() == second_block.signee() );
FC_ASSERT( first_block.id() != second_block.id() );
}
void escrow_transfer_operation::validate()const
{
validate_account_name( from );
validate_account_name( to );
validate_account_name( agent );
FC_ASSERT( fee.amount >= 0, "fee cannot be negative" );
FC_ASSERT( sbd_amount.amount >= 0, "sbd amount cannot be negative" );
FC_ASSERT( steem_amount.amount >= 0, "steem amount cannot be negative" );
FC_ASSERT( sbd_amount.amount > 0 || steem_amount.amount > 0, "escrow must transfer a non-zero amount" );
FC_ASSERT( from != agent && to != agent, "agent must be a third party" );
FC_ASSERT( (fee.symbol == STEEM_SYMBOL) || (fee.symbol == SBD_SYMBOL), "fee must be STEEM or SBD" );
FC_ASSERT( sbd_amount.symbol == SBD_SYMBOL, "sbd amount must contain SBD" );
FC_ASSERT( steem_amount.symbol == STEEM_SYMBOL, "steem amount must contain STEEM" );
FC_ASSERT( ratification_deadline < escrow_expiration, "ratification deadline must be before escrow expiration" );
if ( json_meta.size() > 0 )
{
FC_ASSERT( fc::is_utf8(json_meta), "JSON Metadata not formatted in UTF8" );
FC_ASSERT( fc::json::is_valid(json_meta), "JSON Metadata not valid JSON" );
}
}
void escrow_approve_operation::validate()const
{
validate_account_name( from );
validate_account_name( to );
validate_account_name( agent );
validate_account_name( who );
FC_ASSERT( who == to || who == agent, "to or agent must approve escrow" );
}
void escrow_dispute_operation::validate()const
{
validate_account_name( from );
validate_account_name( to );
validate_account_name( agent );
validate_account_name( who );
FC_ASSERT( who == from || who == to, "who must be from or to" );
}
void escrow_release_operation::validate()const
{
validate_account_name( from );
validate_account_name( to );
validate_account_name( agent );
validate_account_name( who );
validate_account_name( receiver );
FC_ASSERT( who == from || who == to || who == agent, "who must be from or to or agent" );
FC_ASSERT( receiver == from || receiver == to, "receiver must be from or to" );
FC_ASSERT( sbd_amount.amount >= 0, "sbd amount cannot be negative" );
FC_ASSERT( steem_amount.amount >= 0, "steem amount cannot be negative" );
FC_ASSERT( sbd_amount.amount > 0 || steem_amount.amount > 0, "escrow must release a non-zero amount" );
FC_ASSERT( sbd_amount.symbol == SBD_SYMBOL, "sbd amount must contain SBD" );
FC_ASSERT( steem_amount.symbol == STEEM_SYMBOL, "steem amount must contain STEEM" );
}
void request_account_recovery_operation::validate()const
{
validate_account_name( recovery_account );
validate_account_name( account_to_recover );
new_owner_authority.validate();
}
void recover_account_operation::validate()const
{
validate_account_name( account_to_recover );
FC_ASSERT( !( new_owner_authority == recent_owner_authority ), "Cannot set new owner authority to the recent owner authority" );
FC_ASSERT( !new_owner_authority.is_impossible(), "new owner authority cannot be impossible" );
FC_ASSERT( !recent_owner_authority.is_impossible(), "recent owner authority cannot be impossible" );
FC_ASSERT( new_owner_authority.weight_threshold, "new owner authority cannot be trivial" );
new_owner_authority.validate();
recent_owner_authority.validate();
}
void change_recovery_account_operation::validate()const
{
validate_account_name( account_to_recover );
validate_account_name( new_recovery_account );
}
void transfer_to_savings_operation::validate()const {
validate_account_name( from );
validate_account_name( to );
FC_ASSERT( amount.amount > 0 );
FC_ASSERT( amount.symbol == STEEM_SYMBOL || amount.symbol == SBD_SYMBOL );
FC_ASSERT( memo.size() < STEEMIT_MAX_MEMO_SIZE, "Memo is too large" );
FC_ASSERT( fc::is_utf8( memo ), "Memo is not UTF8" );
}
void transfer_from_savings_operation::validate()const {
validate_account_name( from );
validate_account_name( to );
FC_ASSERT( amount.amount > 0 );
FC_ASSERT( amount.symbol == STEEM_SYMBOL || amount.symbol == SBD_SYMBOL );
FC_ASSERT( memo.size() < STEEMIT_MAX_MEMO_SIZE, "Memo is too large" );
FC_ASSERT( fc::is_utf8( memo ), "Memo is not UTF8" );
}
void cancel_transfer_from_savings_operation::validate()const {
validate_account_name( from );
}
void decline_voting_rights_operation::validate()const
{
validate_account_name( account );
}
void reset_account_operation::validate()const
{
validate_account_name( reset_account );
validate_account_name( account_to_reset );
FC_ASSERT( !new_owner_authority.is_impossible(), "new owner authority cannot be impossible" );
FC_ASSERT( new_owner_authority.weight_threshold, "new owner authority cannot be trivial" );
new_owner_authority.validate();
}
void set_reset_account_operation::validate()const
{
validate_account_name( account );
if( current_reset_account.size() )
validate_account_name( current_reset_account );
validate_account_name( reset_account );
FC_ASSERT( current_reset_account != reset_account, "new reset account cannot be current reset account" );
}
void claim_reward_balance_operation::validate()const
{
validate_account_name( account );
FC_ASSERT( is_asset_type( reward_steem, STEEM_SYMBOL ), "Reward Steem must be STEEM" );
FC_ASSERT( is_asset_type( reward_sbd, SBD_SYMBOL ), "Reward Steem must be SBD" );
FC_ASSERT( is_asset_type( reward_vests, VESTS_SYMBOL ), "Reward Steem must be VESTS" );
FC_ASSERT( reward_steem.amount >= 0, "Cannot claim a negative amount" );
FC_ASSERT( reward_sbd.amount >= 0, "Cannot claim a negative amount" );
FC_ASSERT( reward_vests.amount >= 0, "Cannot claim a negative amount" );
FC_ASSERT( reward_steem.amount > 0 || reward_sbd.amount > 0 || reward_vests.amount > 0, "Must claim something." );
}
void delegate_vesting_shares_operation::validate()const
{
validate_account_name( delegator );
validate_account_name( delegatee );
FC_ASSERT( delegator != delegatee, "You cannot delegate VESTS to yourself" );
FC_ASSERT( is_asset_type( vesting_shares, VESTS_SYMBOL ), "Delegation must be VESTS" );
FC_ASSERT( vesting_shares >= asset( 0, VESTS_SYMBOL ), "Delegation cannot be negative" );
}
} } // steemit::protocol