BitShares-Core  5.0.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 
36  pts_address(op.balance_owner_key, false, 56) == balance->owner ||
37  pts_address(op.balance_owner_key, true, 56) == balance->owner ||
38  pts_address(op.balance_owner_key, false, 0) == balance->owner ||
39  pts_address(op.balance_owner_key, true, 0) == balance->owner,
40  balance_claim_owner_mismatch,
41  "Balance owner key was specified as '${op}' but balance's actual owner is '${bal}'",
42  ("op", op.balance_owner_key)
43  ("bal", balance->owner)
44  );
45 
47 
49  {
51  balance->vesting_policy->is_withdraw_allowed(
52  { balance->balance,
53  d.head_block_time(),
54  op.total_claimed } ),
55  balance_claim_invalid_claim_amount,
56  "Attempted to claim ${c} from a vesting balance with ${a} available",
57  ("c", op.total_claimed)("a", balance->available(d.head_block_time()))
58  );
61  balance_claim_claimed_too_often,
62  "Genesis vesting balances may not be claimed more than once per day."
63  );
64  return {};
65  }
66 
68  return {};
69 }
70 
76 {
77  database& d = db();
78 
80  d.modify(*balance, [&](balance_object& b) {
81  b.vesting_policy->on_withdraw({b.balance, d.head_block_time(), op.total_claimed});
82  b.balance -= op.total_claimed;
84  });
85  else
86  d.remove(*balance);
87 
88  d.adjust_balance(op.deposit_to_account, op.total_claimed);
89  return {};
90 }
91 } } // namespace graphene::chain
void modify(const T &obj, const Lambda &m)
optional< linear_vesting_policy > vesting_policy
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
Definition: api.cpp:56
void_result do_evaluate(const balance_claim_operation &op)
Claim a balance in a balance_object.
Definition: balance.hpp:38
microseconds days(int64_t d)
Definition: time.hpp:38
asset_id_type asset_type() const
time_point_sec head_block_time() const
Definition: db_getter.cpp:64
#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:39
#define GRAPHENE_ASSERT(expr, exc_type, FORMAT,...)
Definition: exceptions.hpp:28
asset available(fc::time_point_sec now) const