Scorum
scorum_operations.cpp
Go to the documentation of this file.
2 #include <fc/io/json.hpp>
3 
4 #include <boost/rational.hpp>
5 
6 #include <locale>
7 
10 
11 namespace scorum {
12 namespace protocol {
13 
15 {
16  return asset.symbol() == symbol;
17 }
18 
19 template <class T> bool is_unique(const std::vector<T>& input)
20 {
21  std::vector<T> data(input);
22 
23  sort(data.begin(), data.end());
24  return adjacent_find(data.begin(), data.end()) == data.end();
25 }
26 
28 {
30  FC_ASSERT(is_asset_type(fee, SCORUM_SYMBOL), "Account creation fee must be SCR");
31  owner.validate();
32  active.validate();
33 
35 
36  FC_ASSERT(fee >= asset(0, SCORUM_SYMBOL), "Account creation fee cannot be negative");
37 }
38 
40 {
43  FC_ASSERT(is_asset_type(fee, SCORUM_SYMBOL), "Account creation fee must be SCR");
44  FC_ASSERT(is_asset_type(delegation, SP_SYMBOL), "Delegation must be SP");
45 
46  owner.validate();
47  active.validate();
48  posting.validate();
49 
51 
52  FC_ASSERT(fee >= asset(0, SCORUM_SYMBOL), "Account creation fee cannot be negative");
53  FC_ASSERT(delegation >= asset(0, SP_SYMBOL), "Delegation cannot be negative");
54 }
55 
57 {
60 
61  owner.validate();
62  active.validate();
63  posting.validate();
64 
66 }
67 
69 {
71 
72  if (owner)
73  owner->validate();
74  if (active)
75  active->validate();
76  if (posting)
77  posting->validate();
78 
80 }
81 
83 {
84  FC_ASSERT(title.size() < 256, "Title larger than size limit");
85  FC_ASSERT(fc::is_utf8(title), "Title not formatted in UTF8");
86  FC_ASSERT(body.size() > 0, "Body is empty");
87  FC_ASSERT(fc::is_utf8(body), "Body not formatted in UTF8");
88 
89  if (parent_author.size())
94 
96 }
97 
99 {
101  FC_ASSERT(max_accepted_payout.symbol() == SCORUM_SYMBOL, "Max accepted payout must be in SCR");
102  FC_ASSERT(max_accepted_payout.amount.value >= 0, "Cannot accept less than 0 payout");
104  for (auto& e : extensions)
105  {
107  }
108 }
109 
111 {
114 }
115 
117 {
119 }
120 
122 {
126 }
127 
129 {
130  try
131  {
134  FC_ASSERT(amount.symbol() != SP_SYMBOL, "transferring of Scorum Power (STMP) is not allowed.");
135  FC_ASSERT(amount.amount > 0, "Cannot transfer a negative amount (aka: stealing)");
136  FC_ASSERT(memo.size() < SCORUM_MAX_MEMO_SIZE, "Memo is too large");
137  FC_ASSERT(fc::is_utf8(memo), "Memo is not UTF8");
138  }
139  FC_CAPTURE_AND_RETHROW((*this))
140 }
141 
143 {
145  FC_ASSERT(is_asset_type(amount, SCORUM_SYMBOL), "Amount must be SCR");
146  if (to != account_name_type())
148  FC_ASSERT(amount > asset(0, SCORUM_SYMBOL), "Must transfer a nonzero amount");
149 }
150 
152 {
154  FC_ASSERT(is_asset_type(scorumpower, SP_SYMBOL), "Amount must be SP");
155  FC_ASSERT(scorumpower.amount >= 0, "Can't withdraw negative amount");
156 }
157 
159 {
162  FC_ASSERT(0 <= percent && percent <= SCORUM_100_PERCENT, "Percent must be valid scorum percent");
163 }
164 
166 {
168  FC_ASSERT(0 <= percent && percent <= SCORUM_100_PERCENT, "Percent must be valid scorum percent");
169 }
170 
172 {
174  FC_ASSERT(url.size() > 0, "URL size must be greater than 0");
175  FC_ASSERT(fc::is_utf8(url), "URL is not valid UTF8");
177 }
178 
180 {
183 }
184 
186 {
188  if (proxy.size())
190  FC_ASSERT(proxy != account, "Cannot proxy to self");
191 }
192 
194 {
198  FC_ASSERT(fee.amount >= 0, "fee cannot be negative");
199  FC_ASSERT(scorum_amount.amount > 0, "scorum amount cannot be negative");
200  FC_ASSERT(from != agent && to != agent, "agent must be a third party");
201  FC_ASSERT(fee.symbol() == SCORUM_SYMBOL, "fee must be SCR");
202  FC_ASSERT(scorum_amount.symbol() == SCORUM_SYMBOL, "scorum amount must contain SCR");
203  FC_ASSERT(ratification_deadline < escrow_expiration, "ratification deadline must be before escrow expiration");
204  if (json_meta.size() > 0)
205  {
206  FC_ASSERT(fc::is_utf8(json_meta), "JSON Metadata not formatted in UTF8");
207  FC_ASSERT(fc::json::is_valid(json_meta), "JSON Metadata not valid JSON");
208  }
209 }
210 
212 {
217  FC_ASSERT(who == to || who == agent, "to or agent must approve escrow");
218 }
219 
221 {
226  FC_ASSERT(who == from || who == to, "who must be from or to");
227 }
228 
230 {
236  FC_ASSERT(who == from || who == to || who == agent, "who must be from or to or agent");
237  FC_ASSERT(receiver == from || receiver == to, "receiver must be from or to");
238  FC_ASSERT(scorum_amount.amount >= 0, "scorum amount cannot be negative");
239  FC_ASSERT(scorum_amount.symbol() == SCORUM_SYMBOL, "scorum amount must contain SCR");
240 }
241 
243 {
247 }
248 
250 {
253  "Cannot set new owner authority to the recent owner authority");
254  FC_ASSERT(!new_owner_authority.is_impossible(), "new owner authority cannot be impossible");
255  FC_ASSERT(!recent_owner_authority.is_impossible(), "recent owner authority cannot be impossible");
256  FC_ASSERT(new_owner_authority.weight_threshold, "new owner authority cannot be trivial");
259 }
260 
262 {
265 }
266 
268 {
270 }
271 
273 {
276  FC_ASSERT(delegator != delegatee, "You cannot delegate SP to yourself");
277  FC_ASSERT(is_asset_type(scorumpower, SP_SYMBOL), "Delegation must be SP");
278  FC_ASSERT(scorumpower >= asset(0, SP_SYMBOL), "Delegation cannot be negative");
279 }
280 
282 {
285  FC_ASSERT(reg_committee_member != delegatee, "You cannot delegate SP to yourself");
286  FC_ASSERT(is_asset_type(scorumpower, SP_SYMBOL), "Delegation must be SP");
287  FC_ASSERT(scorumpower.amount >= 0u, "Delegation cannot be negative");
288  auto max_delegation = SCORUM_CREATE_ACCOUNT_REG_COMMITTEE_DELEGATION_MAX;
289  FC_ASSERT(scorumpower <= max_delegation, "Delegation cannot be more than ${0}", ("0", max_delegation));
290 }
291 
293 {
296  FC_ASSERT(is_asset_type(balance, SCORUM_SYMBOL), "Balance must be SCR");
297  FC_ASSERT(balance > asset(0, SCORUM_SYMBOL), "Balance must be positive");
298  FC_ASSERT(start <= deadline, "Deadline time must be greater or equal then start time");
299 }
300 
302 {
305 }
306 
308 {
310 }
311 
313 {
316  FC_ASSERT(is_asset_type(amount, SCORUM_SYMBOL), "Amount must be SCR");
317  FC_ASSERT(amount > asset(0, SCORUM_SYMBOL), "Amount must be positive");
320 }
321 
323 {
327 }
328 
330 {
334 }
335 
337 {
339 }
340 
342 {
344 }
345 
347 {
349 
351 }
352 
354 {
356 
358 
359  fc::flat_set<market_type> set_of_markets(markets.begin(), markets.end());
360 
361  FC_ASSERT(set_of_markets.size() == markets.size(), "You provided duplicates in market list.",
362  ("input_markets", markets) //
363  ("set_of_markets", set_of_markets));
364 
365  validate_game(game, set_of_markets);
366  validate_markets(set_of_markets);
367 }
368 
370 {
372 }
373 
375 {
377 }
378 
380 {
382 }
383 
385 {
387 
388  const fc::flat_set<wincase_type> set_of_wincases(wincases.begin(), wincases.end());
389 
390  FC_ASSERT(set_of_wincases.size() == wincases.size(), "You provided duplicates in wincases list.",
391  ("input_markets", wincases) //
392  ("set_of_markets", set_of_wincases));
393 
394  validate_wincases(set_of_wincases);
395 }
396 
397 void post_bet_operation::validate() const
398 {
401 
402  FC_ASSERT(is_asset_type(stake, SCORUM_SYMBOL), "Stake must be SCR");
403  FC_ASSERT(stake >= SCORUM_MIN_BET_STAKE, "Stake must be greater or equal then ${s}", ("s", SCORUM_MIN_BET_STAKE));
404  FC_ASSERT(odds.numerator > 0, "odds numerator must be greater then zero");
405  FC_ASSERT(odds.denominator > 0, "odds denominator must be greater then zero");
406  FC_ASSERT(odds.numerator > odds.denominator, "odds must be greater then one");
407 
408  const auto min = SCORUM_MIN_ODDS.base();
409  const auto max = SCORUM_MIN_ODDS.inverted();
410 
411  boost::rational<odds_value_type> bet_odds(odds.numerator, odds.denominator);
412  boost::rational<odds_value_type> min_odds(min.numerator, min.denominator);
413  boost::rational<odds_value_type> max_odds(max.numerator, max.denominator);
414 
415  // clang-format off
416  FC_ASSERT(bet_odds <= max_odds, "Invalid odds value",
417  ("numerator", odds.numerator)
418  ("denominator", odds.denominator)
419  ("min_odds", protocol::odds(min).to_string())
420  ("max_odds", protocol::odds(max).to_string()));
421 
422  FC_ASSERT(bet_odds >= min_odds, "Invalid odds value",
423  ("numerator", odds.numerator)
424  ("denominator", odds.denominator)
425  ("min_odds", protocol::odds(min).to_string())
426  ("max_odds", protocol::odds(max).to_string()));
427  // clang-format on
428 }
429 
431 {
432  FC_ASSERT(bet_uuids.size() > 0, "List of bets is empty.");
433  FC_ASSERT(is_unique<uuid_type>(bet_uuids), "You provided duplicates in bets list.", ("bets", bet_uuids));
434 
436 }
437 
439 {
440  FC_ASSERT(!uuid.is_nil(), "uuid must not be nil");
443 }
444 
446 {
447  FC_ASSERT(!uuid.is_nil(), "uuid must not be nil");
448  FC_ASSERT(moderator == SCORUM_NFT_MODERATOR, "invalid moderator account");
450 }
451 
453 {
454  FC_ASSERT(!uuid.is_nil(), "uuid must not be nil");
455  FC_ASSERT(moderator == SCORUM_NFT_MODERATOR, "invalid moderator account");
456 }
457 
459 {
460  FC_ASSERT(!uuid.is_nil(), "uuid must not be nil");
461  FC_ASSERT(moderator == SCORUM_NFT_MODERATOR, "invalid moderator account");
463 }
464 
466 {
467  FC_ASSERT(!uuid.is_nil(), "uuid must not be nil");
468 // FC_ASSERT(account == SCORUM_NFT_MODERATOR, "invalid moderator account");
469  FC_ASSERT(verification_key.size() == 64, "verification_key should have 64 symbols length");
470  FC_ASSERT(seed.size() == 64, "seed should have 64 symbols length");
471 }
472 
474 {
475  FC_ASSERT(!uuid.is_nil(), "uuid must not be nil");
476 // FC_ASSERT(account == SCORUM_NFT_MODERATOR, "invalid moderator account");
477  FC_ASSERT(proof.size() == 160, "proof should have 160 symbols length");
478  FC_ASSERT(vrf.size() == 128, "vrf should have 128 symbols length");
479  FC_ASSERT(result >= 100, "result should be greater or equal 100");
480 }
481 
482 } // namespace protocol
483 } // namespace scorum
#define SCORUM_MAX_MEMO_SIZE
Definition: config.hpp:185
#define SP_SYMBOL
Definition: config.hpp:104
#define SCORUM_SYMBOL
Definition: config.hpp:102
#define SCORUM_100_PERCENT
Definition: config.hpp:200
void validate_contract_metadata(const std::string &metadata)
void validate_secret(const std::string &secret_hex)
void validate_secret_hash(const std::string &secret_hash)
void validate_json_metadata(const std::string &json_metadata)
Definition: base.hpp:26
void validate_permlink(const std::string &permlink)
Definition: base.hpp:20
bool is_unique(const std::vector< T > &input)
fc::static_variant< vote_operation, comment_operation, transfer_operation, transfer_to_scorumpower_operation, withdraw_scorumpower_operation, account_create_by_committee_operation, account_create_operation, account_create_with_delegation_operation, account_update_operation, witness_update_operation, account_witness_vote_operation, account_witness_proxy_operation, delete_comment_operation, comment_options_operation, set_withdraw_scorumpower_route_to_account_operation, set_withdraw_scorumpower_route_to_dev_pool_operation, prove_authority_operation, request_account_recovery_operation, recover_account_operation, change_recovery_account_operation, escrow_approve_operation, escrow_dispute_operation, escrow_release_operation, escrow_transfer_operation, decline_voting_rights_operation, delegate_scorumpower_operation, create_budget_operation, close_budget_operation, proposal_vote_operation, proposal_create_operation, atomicswap_initiate_operation, atomicswap_redeem_operation, atomicswap_refund_operation, close_budget_by_advertising_moderator_operation, update_budget_operation, create_game_operation, cancel_game_operation, update_game_markets_operation, update_game_start_time_operation, post_game_results_operation, post_bet_operation, cancel_pending_bets_operation, delegate_sp_from_reg_pool_operation, create_nft_operation, update_nft_meta_operation, create_game_round_operation, update_game_round_result_operation, adjust_nft_experience_operation, update_nft_name_operation, author_reward_operation, comment_benefficiary_reward_operation, comment_payout_update_operation, comment_reward_operation, curation_reward_operation, hardfork_operation, producer_reward_operation, active_sp_holders_reward_operation, return_scorumpower_delegation_operation, shutdown_witness_operation, witness_miss_block_operation, expired_contract_refund_operation, acc_finished_vesting_withdraw_operation, devpool_finished_vesting_withdraw_operation, acc_to_acc_vesting_withdraw_operation, devpool_to_acc_vesting_withdraw_operation, acc_to_devpool_vesting_withdraw_operation, devpool_to_devpool_vesting_withdraw_operation, proposal_virtual_operation, budget_outgo_operation, budget_owner_income_operation, active_sp_holders_reward_legacy_operation, budget_closing_operation, bets_matched_operation, game_status_changed_operation, bet_resolved_operation, bet_cancelled_operation, bet_restored_operation, bet_updated_operation > operation
Definition: operations.hpp:112
fc::fixed_string_16 account_name_type
Definition: types.hpp:62
void validate_wincases(const fc::flat_set< wincase_type > &wincases)
void validate_game(const game_type &game, const fc::flat_set< market_type > &markets)
bool is_asset_type(asset asset, asset_symbol_type symbol)
uint64_t asset_symbol_type
Definition: asset.hpp:13
void validate_account_name(const std::string &name)
Definition: base.hpp:15
void operation_validate(const proposal_operation &op)
void validate_markets(const fc::flat_set< market_type > &markets)
void validate_wincase(const wincase_type &wincase)
Definition: asset.cpp:15
asset_symbol_type symbol() const
Definition: asset.hpp:32
share_type amount
Definition: asset.hpp:31
account_name_type moderator
moderator account name
std::vector< uuid_type > bet_uuids
bets list that is being canceling
account_name_type new_recovery_account
The account that creates the recover request.
account_name_type account_to_recover
The account that would be recovered in case of compromise.
comment_options_extensions_type extensions
allows voters to receive curation rewards. Rewards return to reward fund.
game_type game
game type (soccer, hockey, etc ...)
std::vector< market_type > markets
list of markets
account_name_type moderator
moderator account name
asset scorumpower
The amount of scorumpower delegated.
account_name_type delegatee
The account receiving scorumpower.
account_name_type delegator
The account delegating scorumpower.
asset scorum_amount
the amount of scorum to release
account_name_type to
the original 'to'
account_name_type who
the account that is attempting to release the funds, determines valid 'receiver'
account_name_type receiver
the account that should receive funds (might be from, might be to)
account_name_type better
owner for new bet
odds_input odds
odds - rational coefficient that define potential result (p). p = odds * stake
account_name_type moderator
moderator account name
std::vector< wincase_type > wincases
list of wincases
account_name_type account_to_recover
The account to be recovered.
authority new_owner_authority
The new owner authority as specified in the request account recovery operation.
account_name_type account_to_recover
The account to recover. This is likely due to a compromised owner authority.
account_name_type recovery_account
The recovery account is listed as the recovery account on the account to recover.
authority new_owner_authority
known by the account to recover and will be confirmed in a recover_account_operation
account_name_type to
Account to transfer asset to.
asset amount
The amount of asset to transfer from from to to.
account_name_type to
if null, then same as from
account_name_type moderator
moderator account name
account_name_type moderator
moderator account name