BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface software
api_helper_indexes.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 api_helper_indexes 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 
28 
29 namespace graphene { namespace api_helper_indexes {
30 
32 { try {
33  const call_order_object& o = static_cast<const call_order_object&>( objct );
34 
35  {
36  auto itr = in_collateral.find( o.collateral_type() );
37  if( itr == in_collateral.end() )
38  in_collateral[o.collateral_type()] = o.collateral;
39  else
40  itr->second += o.collateral;
41  }
42 
43  {
44  auto itr = backing_collateral.find( o.debt_type() );
45  if( itr == backing_collateral.end() )
46  backing_collateral[o.debt_type()] = o.collateral;
47  else
48  itr->second += o.collateral;
49  }
50 
51 } FC_CAPTURE_AND_RETHROW( (objct) ); }
52 
53 void amount_in_collateral_index::object_removed( const object& objct )
54 { try {
55  const call_order_object& o = static_cast<const call_order_object&>( objct );
56 
57  {
58  auto itr = in_collateral.find( o.collateral_type() );
59  if( itr != in_collateral.end() ) // should always be true
60  itr->second -= o.collateral;
61  }
62 
63  {
64  auto itr = backing_collateral.find( o.debt_type() );
65  if( itr != backing_collateral.end() ) // should always be true
66  itr->second -= o.collateral;
67  }
68 
69 } FC_CAPTURE_AND_RETHROW( (objct) ); }
70 
72 { try {
73  object_removed( objct );
74 } FC_CAPTURE_AND_RETHROW( (objct) ); }
75 
77 { try {
78  object_inserted( objct );
79 } FC_CAPTURE_AND_RETHROW( (objct) ); }
80 
82 { try {
83  auto itr = in_collateral.find( asset );
84  if( itr == in_collateral.end() ) return 0;
85  return itr->second;
86 } FC_CAPTURE_AND_RETHROW( (asset) ); }
87 
89 { try {
90  auto itr = backing_collateral.find( asset );
91  if( itr == backing_collateral.end() ) return 0;
92  return itr->second;
93 } FC_CAPTURE_AND_RETHROW( (asset) ); }
94 
95 namespace detail
96 {
97 
99 {
100  public:
102  : _self( _plugin )
103  { }
104 
106  {
107  return _self.database();
108  }
109 
111 
112  private:
113 
114 };
115 
116 } // end namespace detail
117 
119  my( new detail::api_helper_indexes_impl(*this) )
120 {
121 }
122 
124 {
125 }
126 
128 {
129  return "api_helper_indexes";
130 }
132 {
133  return "Provides some helper indexes used by various API calls";
134 }
135 
137  boost::program_options::options_description& cli,
138  boost::program_options::options_description& cfg
139  )
140 {
141 }
142 
143 void api_helper_indexes::plugin_initialize(const boost::program_options::variables_map& options)
144 {
145 }
146 
148 {
149  ilog("api_helper_indexes: plugin_startup() begin");
151  for( const auto& call : database().get_index_type<call_order_index>().indices() )
152  amount_in_collateral->object_inserted( call );
153 
155  for( const auto& account : database().get_index_type< account_index >().indices() )
156  account_members.object_inserted( account );
157 
159  for( const auto& proposal : database().get_index_type< proposal_index >().indices() )
160  approvals.object_inserted( proposal );
161 }
162 
163 } }
tracks all of the proposal objects that requrie approval of an individual account.
SecondaryIndexType * add_secondary_index(Args...args)
Wraps a derived index to intercept calls to create, modify, and remove so that callbacks may be fired...
Definition: index.hpp:309
virtual void plugin_startup() override
Begin normal runtime operations.
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
Definition: api.cpp:56
tracks debt and call price information
virtual void object_removed(const object &obj) override
asset_id_type collateral_type() const
chain::database & database()
Definition: plugin.hpp:114
This secondary index tracks how much of each asset is locked up as collateral for MPAs...
asset_id_type debt_type() const
#define ilog(FORMAT,...)
Definition: logger.hpp:117
This secondary index will allow a reverse lookup of all accounts that a particular key or account is ...
virtual void plugin_set_program_options(boost::program_options::options_description &cli, boost::program_options::options_description &cfg) override
Fill in command line parameters used by the plugin.
#define FC_CAPTURE_AND_RETHROW(...)
Definition: exception.hpp:478
virtual void object_modified(const object &after) override
virtual void about_to_modify(const object &before) override
virtual void plugin_initialize(const boost::program_options::variables_map &options) override
Perform early startup routines and register plugin indexes, callbacks, etc.
virtual void object_inserted(const object &obj) override
share_type get_amount_in_collateral(const asset_id_type &asset) const
share_type collateral
call_price.base.asset_id, access via get_collateral
share_type get_backing_collateral(const asset_id_type &asset) const
virtual void object_inserted(const object &obj) override
virtual void object_inserted(const object &obj) override
const IndexType & get_index_type() const