BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
ticket_object.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Abit More, 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 
26 #include <graphene/chain/types.hpp>
28 
31 
32 #include <boost/multi_index/composite_key.hpp>
33 
34 namespace graphene { namespace chain {
35 
36 using namespace graphene::db;
37 
39 
42 {
47 };
48 
51 {
52  ticket_v1 = 1,
54 };
55 
62 class ticket_object : public abstract_object<ticket_object, protocol_ids, ticket_object_type>
63 {
64  public:
65  account_id_type account;
68 
73 
75  time_point_sec next_type_downgrade_time = time_point_sec::maximum();
76 
77  // Configurations
78  static constexpr uint32_t lock_forever_update_steps = 4;
79  static constexpr uint32_t seconds_per_lock_forever_update_step = 180 * 86400;
80  static constexpr uint32_t seconds_per_charging_step = 15 * 86400;
81  static constexpr uint32_t seconds_to_cancel_charging = 7 * 86400;
82  static uint32_t seconds_to_downgrade( ticket_type i ) {
83  static constexpr uint32_t _seconds_to_downgrade[] = { 180 * 86400, 180 * 86400, 360 * 86400 };
84  return _seconds_to_downgrade[ static_cast<uint8_t>(i) ];
85  }
86  static uint8_t value_multiplier( ticket_type i, ticket_version version ) {
87  static constexpr uint8_t _value_multiplier_v1[] = { 1, 2, 4, 8, 8, 0 };
88  static constexpr uint8_t _value_multiplier_v2[] = { 0, 2, 4, 8, 8, 0 };
89  return ( version == ticket_v1 ? _value_multiplier_v1[ static_cast<uint8_t>(i) ]
90  : _value_multiplier_v2[ static_cast<uint8_t>(i) ] );
91  }
92 
94  void init_new( time_point_sec now, account_id_type new_account,
95  ticket_type new_target_type, const asset& new_amount, ticket_version version );
96 
98  void init_split( time_point_sec now, const ticket_object& old_ticket,
99  ticket_type new_target_type, const asset& new_amount, ticket_version version );
100 
102  void update_target_type( time_point_sec now, ticket_type new_target_type, ticket_version version );
103 
105  void adjust_amount( const asset& delta_amount, ticket_version version );
106 
108  void auto_update( ticket_version version );
109 
110  private:
112  void update_value( ticket_version version );
113 
114 };
115 
116 struct by_next_update;
117 struct by_account;
118 
122 typedef multi_index_container<
124  indexed_by<
125  ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
126  ordered_unique< tag<by_next_update>,
127  composite_key< ticket_object,
128  member< ticket_object, time_point_sec, &ticket_object::next_auto_update_time>,
129  member< object, object_id_type, &object::id>
130  >
131  >,
132  ordered_unique< tag<by_account>,
133  composite_key< ticket_object,
134  member< ticket_object, account_id_type, &ticket_object::account>,
135  member< object, object_id_type, &object::id>
136  >
137  >
138  >
140 
145 
146 } } // graphene::chain
147 
150 
152 
154 
graphene::chain::ticket_status
ticket_status
Status of a ticket.
Definition: ticket_object.hpp:41
graphene::chain::ticket_object::status
ticket_status status
The status of the ticket.
Definition: ticket_object.hpp:70
FC_REFLECT_TYPENAME
FC_REFLECT_TYPENAME(fc::log_message)
graphene::chain::ticket_object
a ticket for governance voting
Definition: ticket_object.hpp:62
graphene::chain::ticket_version
ticket_version
Version of a ticket.
Definition: ticket_object.hpp:50
generic_index.hpp
graphene::protocol::ticket_type
ticket_type
Type of a ticket.
Definition: ticket.hpp:33
MAP_OBJECT_ID_TO_TYPE
#define MAP_OBJECT_ID_TO_TYPE(OBJECT)
Definition: object_id.hpp:93
graphene::chain::withdrawing
@ withdrawing
Definition: ticket_object.hpp:45
fc::time_point_sec::maximum
static time_point_sec maximum()
Definition: time.hpp:86
graphene::chain::TICKET_STATUS_COUNT
@ TICKET_STATUS_COUNT
Definition: ticket_object.hpp:46
graphene::chain::ticket_object::value
share_type value
The current value of the ticket.
Definition: ticket_object.hpp:71
graphene::db::abstract_object
Definition: object.hpp:107
graphene::chain::ticket_v1
@ ticket_v1
Definition: ticket_object.hpp:52
graphene::chain::ticket_v2
@ ticket_v2
Definition: ticket_object.hpp:53
fc::time_point_sec
Definition: time.hpp:74
graphene::chain::charging
@ charging
Definition: ticket_object.hpp:43
GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:85
graphene::chain::ticket_object::current_type
ticket_type current_type
The current type of the ticket.
Definition: ticket_object.hpp:69
graphene::chain::ticket_object::target_type
ticket_type target_type
The target type of the ticket.
Definition: ticket_object.hpp:66
graphene::chain::ticket_object::account
account_id_type account
The account who owns the ticket.
Definition: ticket_object.hpp:65
FC_REFLECT_ENUM
FC_REFLECT_ENUM(graphene::net::core_message_type_enum,(trx_message_type)(block_message_type)(core_message_type_first)(item_ids_inventory_message_type)(blockchain_item_ids_inventory_message_type)(fetch_blockchain_item_ids_message_type)(fetch_items_message_type)(item_not_available_message_type)(hello_message_type)(connection_accepted_message_type)(connection_rejected_message_type)(address_request_message_type)(address_message_type)(closing_connection_message_type)(current_time_request_message_type)(current_time_reply_message_type)(check_firewall_message_type)(check_firewall_reply_message_type)(get_current_connections_request_message_type)(get_current_connections_reply_message_type)(core_message_type_last))(different_chain)(already_connected)(connected_to_self)(not_accepting_connections)(blocked)(invalid_hello_message)(client_too_old))(inbound)(outbound))(firewalled)(not_firewalled))(unable_to_connect)(connection_successful)) namespace std
Definition: core_messages.hpp:404
graphene::chain::ticket_object::value_multiplier
static uint8_t value_multiplier(ticket_type i, ticket_version version)
Definition: ticket_object.hpp:86
graphene::chain::stable
@ stable
Definition: ticket_object.hpp:44
graphene::chain::ticket_object::amount
asset amount
The token type and amount in the ticket.
Definition: ticket_object.hpp:67
types.hpp
graphene::db::generic_index
Definition: generic_index.hpp:43
ticket.hpp
graphene::chain::ticket_index
generic_index< ticket_object, ticket_multi_index_type > ticket_index
Definition: ticket_object.hpp:144
graphene::chain::ticket_object::seconds_to_downgrade
static uint32_t seconds_to_downgrade(ticket_type i)
Definition: ticket_object.hpp:82
graphene::chain::ticket_object::next_auto_update_time
time_point_sec next_auto_update_time
The next time that the ticket will be automatically updated.
Definition: ticket_object.hpp:72
graphene::protocol::asset
Definition: asset.hpp:31
graphene::db
Definition: generic_index.hpp:31
asset.hpp
graphene::chain::ticket_multi_index_type
multi_index_container< ticket_object, indexed_by< ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >, ordered_unique< tag< by_next_update >, composite_key< ticket_object, member< ticket_object, time_point_sec, &ticket_object::next_auto_update_time >, member< object, object_id_type, &object::id > > >, ordered_unique< tag< by_account >, composite_key< ticket_object, member< ticket_object, account_id_type, &ticket_object::account >, member< object, object_id_type, &object::id > > > >> ticket_multi_index_type
Definition: ticket_object.hpp:117
graphene
Definition: api.cpp:48
fc::safe
Definition: safe.hpp:26