BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface software
database_api.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 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 #pragma once
25 
27 
29 
31 
40 
41 #include <fc/api.hpp>
42 #include <fc/variant_object.hpp>
43 
44 #include <fc/network/ip.hpp>
45 
46 #include <boost/container/flat_set.hpp>
47 
48 #include <functional>
49 #include <map>
50 #include <memory>
51 #include <vector>
52 
53 namespace graphene { namespace app {
54 
55 using namespace graphene::chain;
56 using namespace graphene::market_history;
57 using std::string;
58 using std::vector;
59 using std::map;
60 
61 class database_api_impl;
62 
71 {
72  public:
73  database_api(graphene::chain::database& db, const application_options* app_options = nullptr );
74  ~database_api();
75 
77  // Objects //
79 
92  fc::variants get_objects( const vector<object_id_type>& ids,
93  optional<bool> subscribe = optional<bool>() )const;
94 
96  // Subscriptions //
98 
110  void set_subscribe_callback( std::function<void(const variant&)> cb, bool notify_remove_create );
128  void set_auto_subscription( bool enable );
137  void set_pending_transaction_callback( std::function<void(const variant& signed_transaction_object)> cb );
142  void set_block_applied_callback( std::function<void(const variant& block_id)> cb );
148  void cancel_all_subscriptions();
149 
151  // Blocks and transactions //
153 
159  optional<block_header> get_block_header(uint32_t block_num)const;
160 
166  map<uint32_t, optional<block_header>> get_block_header_batch(const vector<uint32_t> block_nums)const;
167 
173  optional<signed_block> get_block(uint32_t block_num)const;
174 
181  processed_transaction get_transaction( uint32_t block_num, uint32_t trx_in_block )const;
182 
191  optional<signed_transaction> get_recent_transaction_by_id( const transaction_id_type& txid )const;
192 
194  // Globals //
196 
200  chain_property_object get_chain_properties()const;
201 
205  global_property_object get_global_properties()const;
206 
211 
215  chain_id_type get_chain_id()const;
216 
220  dynamic_global_property_object get_dynamic_global_properties()const;
221 
223  // Keys //
225 
232  vector<flat_set<account_id_type>> get_key_references( vector<public_key_type> keys )const;
233 
241  bool is_public_key_registered(string public_key) const;
242 
244  // Accounts //
246 
253  account_id_type get_account_id_from_string(const std::string& name_or_id) const;
254 
265  vector<optional<account_object>> get_accounts( const vector<std::string>& account_names_or_ids,
266  optional<bool> subscribe = optional<bool>() )const;
267 
281  std::map<string,full_account> get_full_accounts( const vector<string>& names_or_ids,
282  optional<bool> subscribe = optional<bool>() );
283 
289  vector<account_statistics_object> get_top_voters(uint32_t limit)const;
290 
296  optional<account_object> get_account_by_name( string name )const;
297 
303  vector<account_id_type> get_account_references( const std::string account_name_or_id )const;
304 
312  vector<optional<account_object>> lookup_account_names(const vector<string>& account_names)const;
313 
326  map<string,account_id_type> lookup_accounts( const string& lower_bound_name,
327  uint32_t limit,
328  optional<bool> subscribe = optional<bool>() )const;
329 
331  // Balances //
333 
340  vector<asset> get_account_balances( const std::string& account_name_or_id,
341  const flat_set<asset_id_type>& assets )const;
342 
344  vector<asset> get_named_account_balances(const std::string& name, const flat_set<asset_id_type>& assets)const;
345 
351  vector<balance_object> get_balance_objects( const vector<address>& addrs )const;
352 
359  vector<asset> get_vested_balances( const vector<balance_id_type>& objs )const;
360 
366  vector<vesting_balance_object> get_vesting_balances( const std::string account_name_or_id )const;
367 
371  uint64_t get_account_count()const;
372 
374  // Assets //
376 
382  asset_id_type get_asset_id_from_string(const std::string& symbol_or_id) const;
383 
394  vector<optional<extended_asset_object>> get_assets( const vector<std::string>& asset_symbols_or_ids,
395  optional<bool> subscribe = optional<bool>() )const;
396 
403  vector<extended_asset_object> list_assets(const string& lower_bound_symbol, uint32_t limit)const;
404 
412  vector<optional<extended_asset_object>> lookup_asset_symbols(const vector<string>& symbols_or_ids)const;
413 
418  uint64_t get_asset_count()const;
419 
427  vector<extended_asset_object> get_assets_by_issuer(const std::string& issuer_name_or_id,
428  asset_id_type start, uint32_t limit)const;
429 
431  // Markets / feeds //
433 
441  vector<limit_order_object> get_limit_orders(std::string a, std::string b, uint32_t limit)const;
442 
458  vector<limit_order_object> get_limit_orders_by_account( const string& account_name_or_id,
459  optional<uint32_t> limit = 101,
460  optional<limit_order_id_type> start_id = optional<limit_order_id_type>() );
461 
485  vector<limit_order_object> get_account_limit_orders( const string& account_name_or_id,
486  const string &base,
487  const string &quote,
488  uint32_t limit = 101,
489  optional<limit_order_id_type> ostart_id = optional<limit_order_id_type>(),
490  optional<price> ostart_price = optional<price>());
491 
498  vector<call_order_object> get_call_orders(const std::string& a, uint32_t limit)const;
499 
507  vector<call_order_object> get_call_orders_by_account(const std::string& account_name_or_id,
508  asset_id_type start, uint32_t limit)const;
509 
516  vector<force_settlement_object> get_settle_orders(const std::string& a, uint32_t limit)const;
517 
525  vector<force_settlement_object> get_settle_orders_by_account( const std::string& account_name_or_id,
526  force_settlement_id_type start,
527  uint32_t limit )const;
528 
536  vector<collateral_bid_object> get_collateral_bids(const std::string& a, uint32_t limit, uint32_t start)const;
537 
545  vector<call_order_object> get_margin_positions( const std::string account_name_or_id )const;
546 
556  void subscribe_to_market(std::function<void(const variant&)> callback,
557  const std::string& a, const std::string& b);
558 
564  void unsubscribe_from_market( const std::string& a, const std::string& b );
565 
572  market_ticker get_ticker( const string& base, const string& quote )const;
573 
580  market_volume get_24_volume( const string& base, const string& quote )const;
581 
589  order_book get_order_book( const string& base, const string& quote, unsigned limit = 50 )const;
590 
597  vector<market_ticker> get_top_markets(uint32_t limit)const;
598 
611  vector<market_trade> get_trade_history( const string& base, const string& quote,
613  unsigned limit = 100 )const;
614 
625  vector<market_trade> get_trade_history_by_sequence( const string& base, const string& quote,
626  int64_t start, fc::time_point_sec stop,
627  unsigned limit = 100 )const;
628 
629 
631  // Liquidity pools //
633 
647  vector<liquidity_pool_object> get_liquidity_pools_by_asset_a(
648  std::string asset_symbol_or_id,
649  optional<uint32_t> limit = 101,
650  optional<liquidity_pool_id_type> start_id = optional<liquidity_pool_id_type>() )const;
651 
665  vector<liquidity_pool_object> get_liquidity_pools_by_asset_b(
666  std::string asset_symbol_or_id,
667  optional<uint32_t> limit = 101,
668  optional<liquidity_pool_id_type> start_id = optional<liquidity_pool_id_type>() )const;
669 
685  vector<liquidity_pool_object> get_liquidity_pools_by_both_assets(
686  std::string asset_symbol_or_id_a,
687  std::string asset_symbol_or_id_b,
688  optional<uint32_t> limit = 101,
689  optional<liquidity_pool_id_type> start_id = optional<liquidity_pool_id_type>() )const;
690 
702  vector<optional<liquidity_pool_object>> get_liquidity_pools_by_share_asset(
703  const vector<std::string>& asset_symbols_or_ids,
704  optional<bool> subscribe = optional<bool>() )const;
705 
707  // Witnesses //
709 
717  vector<optional<witness_object>> get_witnesses(const vector<witness_id_type>& witness_ids)const;
718 
724  fc::optional<witness_object> get_witness_by_account(const std::string account_name_or_id)const;
725 
732  map<string, witness_id_type> lookup_witness_accounts(const string& lower_bound_name, uint32_t limit)const;
733 
737  uint64_t get_witness_count()const;
738 
740  // Committee members //
742 
750  vector<optional<committee_member_object>> get_committee_members(
751  const vector<committee_member_id_type>& committee_member_ids)const;
752 
758  fc::optional<committee_member_object> get_committee_member_by_account( const string account_name_or_id )const;
759 
766  map<string, committee_member_id_type> lookup_committee_member_accounts( const string& lower_bound_name,
767  uint32_t limit )const;
768 
772  uint64_t get_committee_count()const;
773 
774 
776  // Worker proposals //
778 
785  vector<worker_object> get_all_workers( const optional<bool> is_expired = optional<bool>() )const;
786 
792  vector<worker_object> get_workers_by_account(const std::string account_name_or_id)const;
793 
797  uint64_t get_worker_count()const;
798 
799 
800 
802  // Votes //
804 
815  vector<variant> lookup_vote_ids( const vector<vote_id_type>& votes )const;
816 
818  // Authority / validation //
820 
826  std::string get_transaction_hex(const signed_transaction& trx)const;
827 
833  std::string get_transaction_hex_without_sig( const signed_transaction &trx ) const;
834 
844  set<public_key_type> get_required_signatures( const signed_transaction& trx,
845  const flat_set<public_key_type>& available_keys )const;
846 
855  set<public_key_type> get_potential_signatures( const signed_transaction& trx )const;
856 
863  set<address> get_potential_address_signatures( const signed_transaction& trx )const;
864 
870  bool verify_authority( const signed_transaction& trx )const;
871 
878  bool verify_account_authority( const string& account_name_or_id,
879  const flat_set<public_key_type>& signers )const;
880 
887  processed_transaction validate_transaction( const signed_transaction& trx )const;
888 
895  vector< fc::variant > get_required_fees( const vector<operation>& ops,
896  const std::string& asset_symbol_or_id )const;
897 
899  // Proposed transactions //
901 
908  vector<proposal_object> get_proposed_transactions( const std::string account_name_or_id )const;
909 
911  // Blinded balances //
913 
919  vector<blinded_balance_object> get_blinded_balances( const flat_set<commitment_type>& commitments )const;
920 
922  // Withdrawals //
924 
933  vector<withdraw_permission_object> get_withdraw_permissions_by_giver( const std::string account_name_or_id,
934  withdraw_permission_id_type start,
935  uint32_t limit )const;
936 
945  vector<withdraw_permission_object> get_withdraw_permissions_by_recipient( const std::string account_name_or_id,
946  withdraw_permission_id_type start,
947  uint32_t limit )const;
948 
950  // HTLC //
952 
961  optional<htlc_object> get_htlc( htlc_id_type id, optional<bool> subscribe = optional<bool>() ) const;
962 
970  vector<htlc_object> get_htlc_by_from( const std::string account_name_or_id,
971  htlc_id_type start,
972  uint32_t limit ) const;
973 
981  vector<htlc_object> get_htlc_by_to( const std::string account_name_or_id,
982  htlc_id_type start,
983  uint32_t limit ) const;
984 
991  vector<htlc_object> list_htlcs(const htlc_id_type start, uint32_t limit) const;
992 
993 
994 private:
995  std::shared_ptr< database_api_impl > my;
996 };
997 
998 } }
999 
1000 extern template class fc::api<graphene::app::database_api>;
1001 
1003  // Objects
1004  (get_objects)
1005 
1006  // Subscriptions
1007  (set_subscribe_callback)
1008  (set_auto_subscription)
1009  (set_pending_transaction_callback)
1010  (set_block_applied_callback)
1011  (cancel_all_subscriptions)
1012 
1013  // Blocks and transactions
1014  (get_block_header)
1015  (get_block_header_batch)
1016  (get_block)
1017  (get_transaction)
1018  (get_recent_transaction_by_id)
1019 
1020  // Globals
1021  (get_chain_properties)
1022  (get_global_properties)
1023  (get_config)
1024  (get_chain_id)
1025  (get_dynamic_global_properties)
1026 
1027  // Keys
1028  (get_key_references)
1029  (is_public_key_registered)
1030 
1031  // Accounts
1032  (get_account_id_from_string)
1033  (get_accounts)
1034  (get_full_accounts)
1035  (get_top_voters)
1036  (get_account_by_name)
1037  (get_account_references)
1038  (lookup_account_names)
1039  (lookup_accounts)
1040  (get_account_count)
1041 
1042  // Balances
1043  (get_account_balances)
1044  (get_named_account_balances)
1045  (get_balance_objects)
1046  (get_vested_balances)
1047  (get_vesting_balances)
1048 
1049  // Assets
1050  (get_assets)
1051  (list_assets)
1052  (lookup_asset_symbols)
1053  (get_asset_count)
1054  (get_assets_by_issuer)
1055  (get_asset_id_from_string)
1056 
1057  // Markets / feeds
1058  (get_order_book)
1059  (get_limit_orders)
1060  (get_limit_orders_by_account)
1061  (get_account_limit_orders)
1062  (get_call_orders)
1063  (get_call_orders_by_account)
1064  (get_settle_orders)
1065  (get_settle_orders_by_account)
1066  (get_margin_positions)
1067  (get_collateral_bids)
1068  (subscribe_to_market)
1069  (unsubscribe_from_market)
1070  (get_ticker)
1071  (get_24_volume)
1072  (get_top_markets)
1073  (get_trade_history)
1074  (get_trade_history_by_sequence)
1075 
1076  // Liquidity pools
1077  (get_liquidity_pools_by_asset_a)
1078  (get_liquidity_pools_by_asset_b)
1079  (get_liquidity_pools_by_both_assets)
1080  (get_liquidity_pools_by_share_asset)
1081 
1082  // Witnesses
1083  (get_witnesses)
1084  (get_witness_by_account)
1085  (lookup_witness_accounts)
1086  (get_witness_count)
1087 
1088  // Committee members
1089  (get_committee_members)
1090  (get_committee_member_by_account)
1091  (lookup_committee_member_accounts)
1092  (get_committee_count)
1093 
1094  // workers
1095  (get_all_workers)
1096  (get_workers_by_account)
1097  (get_worker_count)
1098 
1099  // Votes
1100  (lookup_vote_ids)
1101 
1102  // Authority / validation
1103  (get_transaction_hex)
1104  (get_transaction_hex_without_sig)
1105  (get_required_signatures)
1106  (get_potential_signatures)
1107  (get_potential_address_signatures)
1109  (verify_account_authority)
1110  (validate_transaction)
1111  (get_required_fees)
1112 
1113  // Proposed transactions
1114  (get_proposed_transactions)
1115 
1116  // Blinded balances
1117  (get_blinded_balances)
1118 
1119  // Withdrawals
1120  (get_withdraw_permissions_by_giver)
1121  (get_withdraw_permissions_by_recipient)
1122 
1123  // HTLC
1124  (get_htlc)
1125  (get_htlc_by_from)
1126  (get_htlc_by_to)
1127  (list_htlcs)
1128 )
Maintains global state information (committee_member list, current fees)This is an implementation det...
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
An order-perserving dictionary of variant&#39;s.
Definition: api.cpp:56
std::vector< variant > variants
Definition: variant.hpp:170
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
#define FC_API(CLASS, METHODS)
Definition: api.hpp:197
contains only the public point of an elliptic curve key.
Definition: elliptic.hpp:35
void verify_authority(const vector< operation > &ops, const flat_set< public_key_type > &sigs, const std::function< const authority *(account_id_type)> &get_active, const std::function< const authority *(account_id_type)> &get_owner, const custom_authority_lookup &get_custom, bool allow_non_immediate_owner, bool ignore_custom_operation_required_auths, uint32_t max_recursion=GRAPHENE_MAX_SIG_CHECK_DEPTH, bool allow_committee=false, const flat_set< account_id_type > &active_aprovals=flat_set< account_id_type >(), const flat_set< account_id_type > &owner_approvals=flat_set< account_id_type >())
The database_api class implements the RPC API for the chain database.
fc::variant_object get_config()
Definition: get_config.cpp:31
Maintains global state information (committee_member list, current fees)This is an implementation det...
fc::ripemd160 transaction_id_type
Definition: types.hpp:244
captures the result of evaluating the operations contained in the transaction