BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface software
db_getter.cpp
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 
26 
31 
32 namespace graphene { namespace chain {
33 
35 {
36  return *_p_core_asset_obj;
37 }
38 
40 {
41  return *_p_core_dynamic_data_obj;
42 }
43 
45 {
46  return *_p_global_prop_obj;
47 }
48 
50 {
51  return *_p_chain_property_obj;
52 }
53 
55 {
56  return *_p_dyn_global_prop_obj;
57 }
58 
60 {
62 }
63 
65 {
67 }
68 
69 uint32_t database::head_block_num()const
70 {
72 }
73 
75 {
77 }
78 
79 decltype( chain_parameters::block_interval ) database::block_interval( )const
80 {
82 }
83 
85 {
87 }
88 
90 {
91  return _node_property_object;
92 }
93 
95 {
96  return _node_property_object;
97 }
98 
100  account_id_type account, const operation &op,
101  rejected_predicate_map* rejected_authorities) const
102 {
103  const auto& index = get_index_type<custom_authority_index>().indices().get<by_account_custom>();
104  auto range = index.equal_range(boost::make_tuple(account, unsigned_int(op.which()), true));
105 
106  auto is_valid = [now=head_block_time()](const custom_authority_object& auth) { return auth.is_valid(now); };
107  vector<std::reference_wrapper<const custom_authority_object>> valid_auths;
108  std::copy_if(range.first, range.second, std::back_inserter(valid_auths), is_valid);
109 
110  vector<authority> results;
111  for (const auto& cust_auth : valid_auths) {
112  try {
113  auto result = cust_auth.get().get_predicate()(op);
114  if (result.success)
115  results.emplace_back(cust_auth.get().auth);
116  else if (rejected_authorities != nullptr)
117  rejected_authorities->insert(std::make_pair(cust_auth.get().id, std::move(result)));
118  } catch (fc::exception& e) {
119  if (rejected_authorities != nullptr)
120  rejected_authorities->insert(std::make_pair(cust_auth.get().id, std::move(e)));
121  }
122  }
123 
124  return results;
125 }
126 
128 {
129  //see https://github.com/bitshares/bitshares-core/issues/377
130  /*
131  There is a case when a value of undo_db.size() is greater then head_block_num(),
132  and as result we get a wrong value for last_non_undoable_block_num.
133  To resolve it we should take into account a number of active_sessions in calculations of
134  last_non_undoable_block_num (active sessions are related to a new block which is under generation).
135  */
136  return head_block_num() - ( _undo_db.size() - _undo_db.active_sessions() );
137 }
138 
140 {
141  return account_statistics_id_type(owner.instance)(*this);
142 }
143 
145 {
146  return *_p_witness_schedule_obj;
147 }
148 
149 } }
map< custom_authority_id_type, rejected_predicate > rejected_predicate_map
Definition: transaction.hpp:31
contains all of the parameters necessary to calculate the fee for any operation
Maintains global state information (committee_member list, current fees)This is an implementation det...
const witness_schedule_object & get_witness_schedule_object() const
Definition: db_getter.cpp:144
Definition: api.cpp:56
Used to generate a useful error report when an exception is thrown.At each level in the stack where t...
Definition: exception.hpp:56
const dynamic_global_property_object & get_dynamic_global_properties() const
Definition: db_getter.cpp:54
fc::static_variant< transfer_operation, limit_order_create_operation, limit_order_cancel_operation, call_order_update_operation, fill_order_operation, account_create_operation, account_update_operation, account_whitelist_operation, account_upgrade_operation, account_transfer_operation, asset_create_operation, asset_update_operation, asset_update_bitasset_operation, asset_update_feed_producers_operation, asset_issue_operation, asset_reserve_operation, asset_fund_fee_pool_operation, asset_settle_operation, asset_global_settle_operation, asset_publish_feed_operation, witness_create_operation, witness_update_operation, proposal_create_operation, proposal_update_operation, proposal_delete_operation, withdraw_permission_create_operation, withdraw_permission_update_operation, withdraw_permission_claim_operation, withdraw_permission_delete_operation, committee_member_create_operation, committee_member_update_operation, committee_member_update_global_parameters_operation, vesting_balance_create_operation, vesting_balance_withdraw_operation, worker_create_operation, custom_operation, assert_operation, balance_claim_operation, override_transfer_operation, transfer_to_blind_operation, blind_transfer_operation, transfer_from_blind_operation, asset_settle_cancel_operation, asset_claim_fees_operation, fba_distribute_operation, bid_collateral_operation, execute_bid_operation, asset_claim_pool_operation, asset_update_issuer_operation, htlc_create_operation, htlc_redeem_operation, htlc_redeemed_operation, htlc_extend_operation, htlc_refund_operation, custom_authority_create_operation, custom_authority_update_operation, custom_authority_delete_operation, ticket_create_operation, ticket_update_operation, liquidity_pool_create_operation, liquidity_pool_delete_operation, liquidity_pool_deposit_operation, liquidity_pool_withdraw_operation, liquidity_pool_exchange_operation >
uint32_t head_block_num() const
Definition: db_getter.cpp:69
const global_property_object & get_global_properties() const
Definition: db_getter.cpp:44
tag_type which() const
Tracks account custom authorities.
const fee_schedule & get_current_fees() const
vector< authority > get_viable_custom_authorities(account_id_type account, const operation &op, rejected_predicate_map *rejected_authorities=nullptr) const
Get a list of custom authorities which can validate the provided operation for the provided account...
Definition: db_getter.cpp:99
std::size_t size() const
Contains per-node database configuration.
uint32_t active_sessions() const
time_point_sec head_block_time() const
Definition: db_getter.cpp:64
const node_property_object & get_node_properties() const
Definition: db_getter.cpp:89
const chain_property_object & get_chain_properties() const
Definition: db_getter.cpp:49
const fee_schedule & current_fee_schedule() const
Definition: db_getter.cpp:59
tracks the asset information that changes frequentlyBecause the asset_object is very large it doesn&#39;t...
const account_statistics_object & get_account_stats_by_owner(account_id_type owner) const
Definition: db_getter.cpp:139
const asset_dynamic_data_object & get_core_dynamic_data() const
Definition: db_getter.cpp:39
tracks the parameters of an assetAll assets have a globally unique symbol name that controls how they...
const object & get(object_id_type id) const
Definition: index.hpp:111
node_property_object & node_properties()
Definition: db_getter.cpp:94
abstract base class for accessing objects indexed in various ways.
Definition: index.hpp:71
uint32_t last_non_undoable_block_num() const
Definition: db_getter.cpp:127
Maintains global state information (committee_member list, current fees)This is an implementation det...
const chain_id_type & get_chain_id() const
Definition: db_getter.cpp:84
block_id_type head_block_id() const
Definition: db_getter.cpp:74
uint8_t block_interval
interval in seconds between blocks
const asset_object & get_core_asset() const
Definition: db_getter.cpp:34