BitShares-Core  6.1.0
BitShares blockchain implementation and command-line interface software
balance_evaluator.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cryptonomex, Inc., and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
26 
27 namespace graphene { namespace chain {
28 
30 {
31  database& d = db();
32  balance = &op.balance_to_claim(d);
33 
34  bool is_balance_owner = (
36  pts_address(op.balance_owner_key, false) == balance->owner || // version = 56 (default)
37  pts_address(op.balance_owner_key, true) == balance->owner ); // version = 56 (default)
38  is_balance_owner = (
39  is_balance_owner ||
40  pts_address(op.balance_owner_key, false, 0) == balance->owner ||
41  pts_address(op.balance_owner_key, true, 0) == balance->owner );
42  GRAPHENE_ASSERT( is_balance_owner,
43  balance_claim_owner_mismatch,
44  "Balance owner key was specified as '${op}' but balance's actual owner is '${bal}'",
45  ("op", op.balance_owner_key)
46  ("bal", balance->owner)
47  );
48 
50 
52  {
54  balance->vesting_policy->is_withdraw_allowed(
55  { balance->balance,
56  d.head_block_time(),
57  op.total_claimed } ),
58  balance_claim_invalid_claim_amount,
59  "Attempted to claim ${c} from a vesting balance with ${a} available",
60  ("c", op.total_claimed)("a", balance->available(d.head_block_time()))
61  );
64  balance_claim_claimed_too_often,
65  "Genesis vesting balances may not be claimed more than once per day."
66  );
67  return {};
68  }
69 
71  return {};
72 }
73 
79 {
80  database& d = db();
81 
83  d.modify(*balance, [&](balance_object& b) {
84  b.vesting_policy->on_withdraw({b.balance, d.head_block_time(), op.total_claimed});
85  b.balance -= op.total_claimed;
87  });
88  else
89  d.remove(*balance);
90 
91  d.adjust_balance(op.deposit_to_account, op.total_claimed);
92  return {};
93 }
94 } } // namespace graphene::chain
void modify(const T &obj, const Lambda &m)
optional< linear_vesting_policy > vesting_policy
time_point_sec head_block_time() const
Definition: db_getter.cpp:67
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
Definition: api.cpp:48
void_result do_evaluate(const balance_claim_operation &op)
Claim a balance in a graphene::chain::balance_object.
Definition: balance.hpp:40
asset available(fc::time_point_sec now) const
microseconds days(int64_t d)
Definition: time.hpp:38
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
void_result do_apply(const balance_claim_operation &op)
asset_id_type asset_id
Definition: asset.hpp:37
#define GRAPHENE_ASSERT(expr, exc_type, FORMAT,...)
Definition: exceptions.hpp:28
asset_id_type asset_type() const