BitShares-Core  4.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 
39 
40 #include <fc/api.hpp>
41 #include <fc/variant_object.hpp>
42 
43 #include <fc/network/ip.hpp>
44 
45 #include <boost/container/flat_set.hpp>
46 
47 #include <functional>
48 #include <map>
49 #include <memory>
50 #include <vector>
51 
52 namespace graphene { namespace app {
53 
54 using namespace graphene::chain;
55 using namespace graphene::market_history;
56 using std::string;
57 using std::vector;
58 using std::map;
59 
60 class database_api_impl;
61 
70 {
71  public:
72  database_api(graphene::chain::database& db, const application_options* app_options = nullptr );
73  ~database_api();
74 
76  // Objects //
78 
91  fc::variants get_objects( const vector<object_id_type>& ids,
92  optional<bool> subscribe = optional<bool>() )const;
93 
95  // Subscriptions //
97 
109  void set_subscribe_callback( std::function<void(const variant&)> cb, bool notify_remove_create );
126  void set_auto_subscription( bool enable );
135  void set_pending_transaction_callback( std::function<void(const variant& signed_transaction_object)> cb );
140  void set_block_applied_callback( std::function<void(const variant& block_id)> cb );
146  void cancel_all_subscriptions();
147 
149  // Blocks and transactions //
151 
157  optional<block_header> get_block_header(uint32_t block_num)const;
158 
164  map<uint32_t, optional<block_header>> get_block_header_batch(const vector<uint32_t> block_nums)const;
165 
171  optional<signed_block> get_block(uint32_t block_num)const;
172 
179  processed_transaction get_transaction( uint32_t block_num, uint32_t trx_in_block )const;
180 
189  optional<signed_transaction> get_recent_transaction_by_id( const transaction_id_type& txid )const;
190 
192  // Globals //
194 
198  chain_property_object get_chain_properties()const;
199 
203  global_property_object get_global_properties()const;
204 
209 
213  chain_id_type get_chain_id()const;
214 
218  dynamic_global_property_object get_dynamic_global_properties()const;
219 
221  // Keys //
223 
230  vector<flat_set<account_id_type>> get_key_references( vector<public_key_type> keys )const;
231 
239  bool is_public_key_registered(string public_key) const;
240 
242  // Accounts //
244 
251  account_id_type get_account_id_from_string(const std::string& name_or_id) const;
252 
263  vector<optional<account_object>> get_accounts( const vector<std::string>& account_names_or_ids,
264  optional<bool> subscribe = optional<bool>() )const;
265 
279  std::map<string,full_account> get_full_accounts( const vector<string>& names_or_ids,
280  optional<bool> subscribe = optional<bool>() );
281 
287  optional<account_object> get_account_by_name( string name )const;
288 
294  vector<account_id_type> get_account_references( const std::string account_name_or_id )const;
295 
303  vector<optional<account_object>> lookup_account_names(const vector<string>& account_names)const;
304 
317  map<string,account_id_type> lookup_accounts( const string& lower_bound_name,
318  uint32_t limit,
319  optional<bool> subscribe = optional<bool>() )const;
320 
322  // Balances //
324 
331  vector<asset> get_account_balances( const std::string& account_name_or_id,
332  const flat_set<asset_id_type>& assets )const;
333 
335  vector<asset> get_named_account_balances(const std::string& name, const flat_set<asset_id_type>& assets)const;
336 
342  vector<balance_object> get_balance_objects( const vector<address>& addrs )const;
343 
350  vector<asset> get_vested_balances( const vector<balance_id_type>& objs )const;
351 
357  vector<vesting_balance_object> get_vesting_balances( const std::string account_name_or_id )const;
358 
362  uint64_t get_account_count()const;
363 
365  // Assets //
367 
373  asset_id_type get_asset_id_from_string(const std::string& symbol_or_id) const;
374 
385  vector<optional<extended_asset_object>> get_assets( const vector<std::string>& asset_symbols_or_ids,
386  optional<bool> subscribe = optional<bool>() )const;
387 
394  vector<extended_asset_object> list_assets(const string& lower_bound_symbol, uint32_t limit)const;
395 
403  vector<optional<extended_asset_object>> lookup_asset_symbols(const vector<string>& symbols_or_ids)const;
404 
409  uint64_t get_asset_count()const;
410 
418  vector<extended_asset_object> get_assets_by_issuer(const std::string& issuer_name_or_id,
419  asset_id_type start, uint32_t limit)const;
420 
422  // Markets / feeds //
424 
432  vector<limit_order_object> get_limit_orders(std::string a, std::string b, uint32_t limit)const;
433 
449  vector<limit_order_object> get_limit_orders_by_account( const string& account_name_or_id,
450  optional<uint32_t> limit = 101,
451  optional<limit_order_id_type> start_id = optional<limit_order_id_type>() );
452 
476  vector<limit_order_object> get_account_limit_orders( const string& account_name_or_id,
477  const string &base,
478  const string &quote,
479  uint32_t limit = 101,
480  optional<limit_order_id_type> ostart_id = optional<limit_order_id_type>(),
481  optional<price> ostart_price = optional<price>());
482 
489  vector<call_order_object> get_call_orders(const std::string& a, uint32_t limit)const;
490 
498  vector<call_order_object> get_call_orders_by_account(const std::string& account_name_or_id,
499  asset_id_type start, uint32_t limit)const;
500 
507  vector<force_settlement_object> get_settle_orders(const std::string& a, uint32_t limit)const;
508 
516  vector<force_settlement_object> get_settle_orders_by_account( const std::string& account_name_or_id,
517  force_settlement_id_type start,
518  uint32_t limit )const;
519 
527  vector<collateral_bid_object> get_collateral_bids(const std::string& a, uint32_t limit, uint32_t start)const;
528 
536  vector<call_order_object> get_margin_positions( const std::string account_name_or_id )const;
537 
547  void subscribe_to_market(std::function<void(const variant&)> callback,
548  const std::string& a, const std::string& b);
549 
555  void unsubscribe_from_market( const std::string& a, const std::string& b );
556 
563  market_ticker get_ticker( const string& base, const string& quote )const;
564 
571  market_volume get_24_volume( const string& base, const string& quote )const;
572 
580  order_book get_order_book( const string& base, const string& quote, unsigned limit = 50 )const;
581 
588  vector<market_ticker> get_top_markets(uint32_t limit)const;
589 
602  vector<market_trade> get_trade_history( const string& base, const string& quote,
604  unsigned limit = 100 )const;
605 
616  vector<market_trade> get_trade_history_by_sequence( const string& base, const string& quote,
617  int64_t start, fc::time_point_sec stop,
618  unsigned limit = 100 )const;
619 
620 
621 
623  // Witnesses //
625 
633  vector<optional<witness_object>> get_witnesses(const vector<witness_id_type>& witness_ids)const;
634 
640  fc::optional<witness_object> get_witness_by_account(const std::string account_name_or_id)const;
641 
648  map<string, witness_id_type> lookup_witness_accounts(const string& lower_bound_name, uint32_t limit)const;
649 
653  uint64_t get_witness_count()const;
654 
656  // Committee members //
658 
666  vector<optional<committee_member_object>> get_committee_members(
667  const vector<committee_member_id_type>& committee_member_ids)const;
668 
674  fc::optional<committee_member_object> get_committee_member_by_account( const string account_name_or_id )const;
675 
682  map<string, committee_member_id_type> lookup_committee_member_accounts( const string& lower_bound_name,
683  uint32_t limit )const;
684 
688  uint64_t get_committee_count()const;
689 
690 
692  // Worker proposals //
694 
701  vector<worker_object> get_all_workers( const optional<bool> is_expired = optional<bool>() )const;
702 
708  vector<worker_object> get_workers_by_account(const std::string account_name_or_id)const;
709 
713  uint64_t get_worker_count()const;
714 
715 
716 
718  // Votes //
720 
731  vector<variant> lookup_vote_ids( const vector<vote_id_type>& votes )const;
732 
734  // Authority / validation //
736 
742  std::string get_transaction_hex(const signed_transaction& trx)const;
743 
749  std::string get_transaction_hex_without_sig( const signed_transaction &trx ) const;
750 
760  set<public_key_type> get_required_signatures( const signed_transaction& trx,
761  const flat_set<public_key_type>& available_keys )const;
762 
771  set<public_key_type> get_potential_signatures( const signed_transaction& trx )const;
772 
779  set<address> get_potential_address_signatures( const signed_transaction& trx )const;
780 
786  bool verify_authority( const signed_transaction& trx )const;
787 
794  bool verify_account_authority( const string& account_name_or_id,
795  const flat_set<public_key_type>& signers )const;
796 
803  processed_transaction validate_transaction( const signed_transaction& trx )const;
804 
811  vector< fc::variant > get_required_fees( const vector<operation>& ops,
812  const std::string& asset_symbol_or_id )const;
813 
815  // Proposed transactions //
817 
824  vector<proposal_object> get_proposed_transactions( const std::string account_name_or_id )const;
825 
827  // Blinded balances //
829 
835  vector<blinded_balance_object> get_blinded_balances( const flat_set<commitment_type>& commitments )const;
836 
838  // Withdrawals //
840 
849  vector<withdraw_permission_object> get_withdraw_permissions_by_giver( const std::string account_name_or_id,
850  withdraw_permission_id_type start,
851  uint32_t limit )const;
852 
861  vector<withdraw_permission_object> get_withdraw_permissions_by_recipient( const std::string account_name_or_id,
862  withdraw_permission_id_type start,
863  uint32_t limit )const;
864 
866  // HTLC //
868 
877  optional<htlc_object> get_htlc( htlc_id_type id, optional<bool> subscribe = optional<bool>() ) const;
878 
886  vector<htlc_object> get_htlc_by_from( const std::string account_name_or_id,
887  htlc_id_type start,
888  uint32_t limit ) const;
889 
897  vector<htlc_object> get_htlc_by_to( const std::string account_name_or_id,
898  htlc_id_type start,
899  uint32_t limit ) const;
900 
907  vector<htlc_object> list_htlcs(const htlc_id_type start, uint32_t limit) const;
908 
909 
910 private:
911  std::shared_ptr< database_api_impl > my;
912 };
913 
914 } }
915 
916 extern template class fc::api<graphene::app::database_api>;
917 
919  // Objects
920  (get_objects)
921 
922  // Subscriptions
923  (set_subscribe_callback)
924  (set_auto_subscription)
925  (set_pending_transaction_callback)
926  (set_block_applied_callback)
927  (cancel_all_subscriptions)
928 
929  // Blocks and transactions
930  (get_block_header)
931  (get_block_header_batch)
932  (get_block)
933  (get_transaction)
934  (get_recent_transaction_by_id)
935 
936  // Globals
937  (get_chain_properties)
938  (get_global_properties)
939  (get_config)
940  (get_chain_id)
941  (get_dynamic_global_properties)
942 
943  // Keys
944  (get_key_references)
945  (is_public_key_registered)
946 
947  // Accounts
948  (get_account_id_from_string)
949  (get_accounts)
950  (get_full_accounts)
951  (get_account_by_name)
952  (get_account_references)
953  (lookup_account_names)
954  (lookup_accounts)
955  (get_account_count)
956 
957  // Balances
958  (get_account_balances)
959  (get_named_account_balances)
960  (get_balance_objects)
961  (get_vested_balances)
962  (get_vesting_balances)
963 
964  // Assets
965  (get_assets)
966  (list_assets)
967  (lookup_asset_symbols)
968  (get_asset_count)
969  (get_assets_by_issuer)
970  (get_asset_id_from_string)
971 
972  // Markets / feeds
973  (get_order_book)
974  (get_limit_orders)
975  (get_limit_orders_by_account)
976  (get_account_limit_orders)
977  (get_call_orders)
978  (get_call_orders_by_account)
979  (get_settle_orders)
980  (get_settle_orders_by_account)
981  (get_margin_positions)
982  (get_collateral_bids)
983  (subscribe_to_market)
984  (unsubscribe_from_market)
985  (get_ticker)
986  (get_24_volume)
987  (get_top_markets)
988  (get_trade_history)
989  (get_trade_history_by_sequence)
990 
991  // Witnesses
992  (get_witnesses)
993  (get_witness_by_account)
994  (lookup_witness_accounts)
995  (get_witness_count)
996 
997  // Committee members
998  (get_committee_members)
999  (get_committee_member_by_account)
1000  (lookup_committee_member_accounts)
1001  (get_committee_count)
1002 
1003  // workers
1004  (get_all_workers)
1005  (get_workers_by_account)
1006  (get_worker_count)
1007 
1008  // Votes
1009  (lookup_vote_ids)
1010 
1011  // Authority / validation
1012  (get_transaction_hex)
1013  (get_transaction_hex_without_sig)
1014  (get_required_signatures)
1015  (get_potential_signatures)
1016  (get_potential_address_signatures)
1018  (verify_account_authority)
1019  (validate_transaction)
1020  (get_required_fees)
1021 
1022  // Proposed transactions
1023  (get_proposed_transactions)
1024 
1025  // Blinded balances
1026  (get_blinded_balances)
1027 
1028  // Withdrawals
1029  (get_withdraw_permissions_by_giver)
1030  (get_withdraw_permissions_by_recipient)
1031 
1032  // HTLC
1033  (get_htlc)
1034  (get_htlc_by_from)
1035  (get_htlc_by_to)
1036  (list_htlcs)
1037 )
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