BitShares-Core  6.1.0
BitShares blockchain implementation and command-line interface software
api_helper_indexes.hpp
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 #pragma once
25 
26 #include <graphene/app/plugin.hpp>
28 
29 namespace graphene { namespace api_helper_indexes {
30 using namespace chain;
31 
39 {
40  public:
41  void object_inserted( const object& obj ) override;
42  void object_removed( const object& obj ) override;
43  void about_to_modify( const object& before ) override;
44  void object_modified( const object& after ) override;
45 
46  share_type get_amount_in_collateral( const asset_id_type& asset )const;
47  share_type get_backing_collateral( const asset_id_type& asset )const;
48 
49  private:
50  flat_map<asset_id_type, share_type> in_collateral;
51  flat_map<asset_id_type, share_type> backing_collateral;
52 };
53 
60 {
61  public:
62  void object_inserted( const object& obj ) override;
63  void object_removed( const object& obj ) override;
64  void about_to_modify( const object& before ) override;
65  void object_modified( const object& after ) override;
66 
67  const flat_set<liquidity_pool_id_type>& get_liquidity_pools_by_asset( const asset_id_type& a )const;
68 
69  private:
70  flat_set<liquidity_pool_id_type> empty_set;
71  flat_map<asset_id_type, flat_set<liquidity_pool_id_type>> asset_in_pools_map;
72 };
73 
80 {
81  public:
82  object_id_type get_next_id( uint8_t space_id, uint8_t type_id ) const;
83 
84  private:
85  friend class api_helper_indexes;
86  flat_map< std::pair<uint8_t,uint8_t>, object_id_type > _next_ids;
87 };
88 
89 namespace detail
90 {
91  class api_helper_indexes_impl;
92 }
93 
95 {
96  public:
98  ~api_helper_indexes() override;
99 
100  std::string plugin_name()const override;
101  std::string plugin_description()const override;
102  void plugin_set_program_options(
103  boost::program_options::options_description& cli,
104  boost::program_options::options_description& cfg) override;
105  void plugin_initialize(const boost::program_options::variables_map& options) override;
106  void plugin_startup() override;
107 
109 
110  private:
111  std::unique_ptr<detail::api_helper_indexes_impl> my;
112  amount_in_collateral_index* amount_in_collateral_idx = nullptr;
113  asset_in_liquidity_pools_index* asset_in_liquidity_pools_idx = nullptr;
114  next_object_ids_index* next_object_ids_idx = nullptr;
115 
116  bool _next_ids_map_initialized = false;
117  void refresh_next_ids();
118 };
119 
120 } } //graphene::template
This secondary index tracks the next ID of all object types.
Definition: api.cpp:48
This secondary index maintains a map to make it easier to find liquidity pools by any asset in the po...
This secondary index tracks how much of each asset is locked up as collateral for MPAs...