BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface 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 
44  class withdraw_permission_object : public graphene::db::abstract_object<withdraw_permission_object>
45  {
46  public:
47  static const uint8_t space_id = protocol_ids;
48  static const uint8_t type_id = withdraw_permission_object_type;
49 
51  account_id_type withdraw_from_account;
53  account_id_type authorized_account;
57  uint32_t withdrawal_period_sec = 0;
58  /***
59  * The beginning of the next withdrawal period
60  * WARNING: Due to caching, this value does not always represent the start of the next or current period (because it is only updated after a withdrawal operation such as claim). For the latest current period, use current_period().
61  */
65 
66  /***
67  * Tracks the total amount
68  * WARNING: Due to caching, this value does not always represent the total amount claimed during the current period; it may represent what was claimed during the last claimed period (because it is only updated after a withdrawal operation such as claim). For the latest current period, use current_period().
69  */
71 
72  /***
73  * Determine how much is still available to be claimed during the period that contains a time of interest. This object and function is mainly intended to be used with the "current" time as a parameter. The current time can be obtained from the time of the current head of the blockchain.
74  */
76  {
77  if( current_time >= period_start_time + withdrawal_period_sec )
78  return withdrawal_limit;
79  return asset(
80  ( withdrawal_limit.amount > claimed_this_period )
81  ? withdrawal_limit.amount - claimed_this_period
82  : 0, withdrawal_limit.asset_id );
83  }
84  };
85 
86  struct by_from;
87  struct by_authorized;
88  struct by_expiration;
89 
90  typedef multi_index_container<
92  indexed_by<
93  ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
94  ordered_unique< tag<by_from>,
95  composite_key< withdraw_permission_object,
96  member<withdraw_permission_object, account_id_type, &withdraw_permission_object::withdraw_from_account>,
97  member< object, object_id_type, &object::id >
98  >
99  >,
100  ordered_unique< tag<by_authorized>,
101  composite_key< withdraw_permission_object,
102  member<withdraw_permission_object, account_id_type, &withdraw_permission_object::authorized_account>,
103  member< object, object_id_type, &object::id >
104  >
105  >,
106  ordered_unique< tag<by_expiration>,
107  composite_key< withdraw_permission_object,
108  member<withdraw_permission_object, time_point_sec, &withdraw_permission_object::expiration>,
109  member< object, object_id_type, &object::id >
110  >
111  >
112  >
114 
116 
117 
118 } } // graphene::chain
119 
121 
123 
account_id_type authorized_account
The account authorized to make withdrawals from withdraw_from_account.
Definition: api.cpp:56
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_object_multi_index_type
#define MAP_OBJECT_ID_TO_TYPE(OBJECT)
Definition: object_id.hpp:98
FC_REFLECT_TYPENAME(fc::log_message)
Grants another account authority to withdraw a limited amount of funds per interval.
generic_index< withdraw_permission_object, withdraw_permission_object_multi_index_type > withdraw_permission_index
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:73
time_point_sec expiration
The time at which this withdraw permission expires.
asset withdrawal_limit
The maximum amount which may be withdrawn per period. All withdrawals must be of this asset type...
account_id_type withdraw_from_account
The account authorizing authorized_account to withdraw from it.
Use the Curiously Recurring Template Pattern to automatically add the ability to clone, serialize, and move objects polymorphically.
Definition: object.hpp:90
asset available_this_period(fc::time_point_sec current_time) const
asset_id_type asset_id
Definition: asset.hpp:39