BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
withdraw_permission_object.hpp
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  */
24 #pragma once
25 
28 
29 #include <boost/multi_index/composite_key.hpp>
30 
31 namespace graphene { namespace chain {
32  using namespace graphene::protocol;
33 
45  class withdraw_permission_object : public graphene::db::abstract_object<withdraw_permission_object,
46  protocol_ids, withdraw_permission_object_type>
47  {
48  public:
50  account_id_type withdraw_from_account;
52  account_id_type authorized_account;
56  uint32_t withdrawal_period_sec = 0;
66 
75 
76  /***
77  * Determine how much is still available to be claimed during the period that contains a time of interest.
78  * This object and function is mainly intended to be used with the "current" time as a parameter.
79  * The current time can be obtained from the time of the current head of the blockchain.
80  */
82  {
83  if( current_time >= period_start_time + withdrawal_period_sec )
84  return withdrawal_limit;
85  return asset( ( withdrawal_limit.amount > claimed_this_period ) ?
86  ( withdrawal_limit.amount - claimed_this_period ) : 0,
87  withdrawal_limit.asset_id );
88  }
89  };
90 
91  struct by_from;
92  struct by_authorized;
93  struct by_expiration;
94 
95  using withdraw_permission_obj_mlt_idx = multi_index_container<
96  withdraw_permission_object,
97  indexed_by<
98  ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
99  ordered_unique< tag<by_from>,
100  composite_key< withdraw_permission_object,
101  member< withdraw_permission_object, account_id_type,
103  member< object, object_id_type, &object::id >
104  >
105  >,
106  ordered_unique< tag<by_authorized>,
107  composite_key< withdraw_permission_object,
108  member< withdraw_permission_object, account_id_type, &withdraw_permission_object::authorized_account >,
109  member< object, object_id_type, &object::id >
110  >
111  >,
112  ordered_unique< tag<by_expiration>,
113  composite_key< withdraw_permission_object,
114  member< withdraw_permission_object, time_point_sec, &withdraw_permission_object::expiration >,
115  member< object, object_id_type, &object::id >
116  >
117  >
118  >
119  >;
120 
122 
123 
124 } } // graphene::chain
125 
127 
129 
graphene::chain::withdraw_permission_object::claimed_this_period
share_type claimed_this_period
Definition: withdraw_permission_object.hpp:74
graphene::chain::withdraw_permission_object::available_this_period
asset available_this_period(fc::time_point_sec current_time) const
Definition: withdraw_permission_object.hpp:81
graphene::chain::withdraw_permission_object::period_start_time
time_point_sec period_start_time
Definition: withdraw_permission_object.hpp:63
FC_REFLECT_TYPENAME
FC_REFLECT_TYPENAME(fc::log_message)
generic_index.hpp
MAP_OBJECT_ID_TO_TYPE
#define MAP_OBJECT_ID_TO_TYPE(OBJECT)
Definition: object_id.hpp:93
graphene::chain::withdraw_permission_object::withdrawal_limit
asset withdrawal_limit
The maximum amount which may be withdrawn per period. All withdrawals must be of this asset type.
Definition: withdraw_permission_object.hpp:54
graphene::db::abstract_object
Definition: object.hpp:107
graphene::chain::withdraw_permission_object::authorized_account
account_id_type authorized_account
The account authorized to make withdrawals from withdraw_from_account.
Definition: withdraw_permission_object.hpp:52
graphene::protocol
Definition: util.hpp:29
fc::time_point_sec
Definition: time.hpp:74
graphene::protocol::asset::asset_id
asset_id_type asset_id
Definition: asset.hpp:37
GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:85
graphene::chain::withdraw_permission_object::expiration
time_point_sec expiration
The time at which this withdraw permission expires.
Definition: withdraw_permission_object.hpp:65
graphene::protocol::asset::amount
share_type amount
Definition: asset.hpp:36
graphene::chain::withdraw_permission_object
Grants another account authority to withdraw a limited amount of funds per interval.
Definition: withdraw_permission_object.hpp:45
graphene::chain::withdraw_permission_object::withdraw_from_account
account_id_type withdraw_from_account
The account authorizing authorized_account to withdraw from it.
Definition: withdraw_permission_object.hpp:50
graphene::db::generic_index
Definition: generic_index.hpp:43
graphene::protocol::asset
Definition: asset.hpp:31
graphene::chain::withdraw_permission_obj_mlt_idx
multi_index_container< withdraw_permission_object, indexed_by< ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >, ordered_unique< tag< by_from >, composite_key< withdraw_permission_object, member< withdraw_permission_object, account_id_type, &withdraw_permission_object::withdraw_from_account >, member< object, object_id_type, &object::id > > >, ordered_unique< tag< by_authorized >, composite_key< withdraw_permission_object, member< withdraw_permission_object, account_id_type, &withdraw_permission_object::authorized_account >, member< object, object_id_type, &object::id > > >, ordered_unique< tag< by_expiration >, composite_key< withdraw_permission_object, member< withdraw_permission_object, time_point_sec, &withdraw_permission_object::expiration >, member< object, object_id_type, &object::id > > > > > withdraw_permission_obj_mlt_idx
Definition: withdraw_permission_object.hpp:119
asset.hpp
graphene
Definition: api.cpp:48
fc::safe
Definition: safe.hpp:26