BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface 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>
63 {
64  public:
65  static constexpr uint8_t space_id = protocol_ids;
66  static constexpr uint8_t type_id = ticket_object_type;
67 
68  account_id_type account;
71 
76 
78  time_point_sec next_type_downgrade_time = time_point_sec::maximum();
79 
80  // Configurations
81  static constexpr uint32_t lock_forever_update_steps = 4;
82  static constexpr uint32_t seconds_per_lock_forever_update_step = 180 * 86400;
83  static constexpr uint32_t seconds_per_charging_step = 15 * 86400;
84  static constexpr uint32_t seconds_to_cancel_charging = 7 * 86400;
85  static uint32_t seconds_to_downgrade( ticket_type i ) {
86  static constexpr uint32_t _seconds_to_downgrade[] = { 180 * 86400, 180 * 86400, 360 * 86400 };
87  return _seconds_to_downgrade[ static_cast<uint8_t>(i) ];
88  }
89  static uint8_t value_multiplier( ticket_type i, ticket_version version ) {
90  static constexpr uint32_t _value_multiplier_v1[] = { 1, 2, 4, 8, 8, 0 };
91  static constexpr uint32_t _value_multiplier_v2[] = { 0, 2, 4, 8, 8, 0 };
92  return ( version == ticket_v1 ? _value_multiplier_v1[ static_cast<uint8_t>(i) ]
93  : _value_multiplier_v2[ static_cast<uint8_t>(i) ] );
94  }
95 
97  void init_new( time_point_sec now, account_id_type new_account,
98  ticket_type new_target_type, const asset& new_amount, ticket_version version );
99 
101  void init_split( time_point_sec now, const ticket_object& old_ticket,
102  ticket_type new_target_type, const asset& new_amount, ticket_version version );
103 
105  void update_target_type( time_point_sec now, ticket_type new_target_type, ticket_version version );
106 
108  void adjust_amount( const asset& delta_amount, ticket_version version );
109 
111  void auto_update( ticket_version version );
112 
113  private:
115  void update_value( ticket_version version );
116 
117 };
118 
119 struct by_next_update;
120 struct by_account_type;
121 
125 typedef multi_index_container<
127  indexed_by<
128  ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
129  ordered_unique< tag<by_next_update>,
130  composite_key< ticket_object,
131  member< ticket_object, time_point_sec, &ticket_object::next_auto_update_time>,
132  member< object, object_id_type, &object::id>
133  >
134  >,
135  ordered_unique< tag<by_account_type>,
136  composite_key< ticket_object,
137  member< ticket_object, account_id_type, &ticket_object::account>,
138  member< ticket_object, ticket_type, &ticket_object::current_type>,
139  member< object, object_id_type, &object::id>
140  >
141  >
142  >
144 
149 
150 } } // graphene::chain
151 
154 
156 
158 
generic_index< ticket_object, ticket_multi_index_type > ticket_index
static uint8_t value_multiplier(ticket_type i, ticket_version version)
ticket_type
Type of a ticket.
Definition: ticket.hpp:33
ticket_type target_type
The target type of the ticket.
Definition: api.cpp:56
static uint32_t seconds_to_downgrade(ticket_type i)
#define MAP_OBJECT_ID_TO_TYPE(OBJECT)
Definition: object_id.hpp:98
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_type >, composite_key< ticket_object, member< ticket_object, account_id_type,&ticket_object::account >, member< ticket_object, ticket_type,&ticket_object::current_type >, member< object, object_id_type,&object::id > > > >> ticket_multi_index_type
FC_REFLECT_TYPENAME(fc::log_message)
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
static time_point_sec maximum()
Definition: time.hpp:86
time_point_sec next_auto_update_time
The next time that the ticket will be automatically updated.
asset amount
The token type and amount in the ticket.
#define GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION(type)
Definition: types.hpp:73
ticket_type current_type
The current type of the ticket.
ticket_status status
The status of the ticket.
Use the Curiously Recurring Template Pattern to automatically add the ability to clone, serialize, and move objects polymorphically.
Definition: object.hpp:86
ticket_status
Status of a ticket.
ticket_version
Version of a ticket.
account_id_type account
The account who owns the ticket.
a ticket for governance voting
share_type value
The current value of the ticket.