BitShares-Core  4.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 
55 class ticket_object : public abstract_object<ticket_object>
56 {
57  public:
58  static const uint8_t space_id = protocol_ids;
59  static const uint8_t type_id = ticket_object_type;
60 
61  account_id_type account;
64 
69 
71  time_point_sec next_type_downgrade_time = time_point_sec::maximum();
72 
73  // Configurations
74  static constexpr uint32_t lock_forever_update_steps = 4;
75  static constexpr uint32_t seconds_per_lock_forever_update_step = 180 * 86400;
76  static constexpr uint32_t seconds_per_charging_step = 15 * 86400;
77  static constexpr uint32_t seconds_to_cancel_charging = 7 * 86400;
78  static uint32_t seconds_to_downgrade( ticket_type i ) {
79  static constexpr uint32_t _seconds_to_downgrade[] = { 180 * 86400, 180 * 86400, 360 * 86400 };
80  return _seconds_to_downgrade[ static_cast<uint8_t>(i) ];
81  }
82  static uint8_t value_multiplier( ticket_type i ) {
83  static constexpr uint32_t _value_multiplier[] = { 1, 2, 4, 8, 8, 0 };
84  return _value_multiplier[ static_cast<uint8_t>(i) ];
85  }
86 
88  void init_new( time_point_sec now, account_id_type new_account,
89  ticket_type new_target_type, const asset& new_amount );
90 
92  void init_split( time_point_sec now, const ticket_object& old_ticket,
93  ticket_type new_target_type, const asset& new_amount );
94 
96  void update_target_type( time_point_sec now, ticket_type new_target_type );
97 
99  void adjust_amount( const asset& delta_amount );
100 
102  void auto_update();
103 
104  private:
106  void update_value();
107 
108 };
109 
110 struct by_next_update;
111 struct by_account_type;
112 
116 typedef multi_index_container<
118  indexed_by<
119  ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
120  ordered_unique< tag<by_next_update>,
121  composite_key< ticket_object,
122  member< ticket_object, time_point_sec, &ticket_object::next_auto_update_time>,
123  member< object, object_id_type, &object::id>
124  >
125  >,
126  ordered_unique< tag<by_account_type>,
127  composite_key< ticket_object,
128  member< ticket_object, account_id_type, &ticket_object::account>,
129  member< ticket_object, ticket_type, &ticket_object::current_type>,
130  member< object, object_id_type, &object::id>
131  >
132  >
133  >
135 
140 
141 } } // graphene::chain
142 
145 
147 
149 
generic_index< ticket_object, ticket_multi_index_type > ticket_index
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:90
ticket_status
Status of a ticket.
account_id_type account
The account who owns the ticket.
static uint8_t value_multiplier(ticket_type i)
a ticket for governance voting
share_type value
The current value of the ticket.