BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
api.hpp
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 #pragma once
25 
27 
29 
33 
35 
37 
38 #include <graphene/net/node.hpp>
39 
40 #include <fc/api.hpp>
41 #include <fc/optional.hpp>
42 #include <fc/crypto/elliptic.hpp>
43 #include <fc/network/ip.hpp>
44 
45 #include <boost/container/flat_set.hpp>
46 
47 #include <functional>
48 #include <map>
49 #include <string>
50 #include <vector>
51 
52 namespace graphene { namespace app {
53  using namespace graphene::chain;
54  using namespace graphene::market_history;
55  using namespace graphene::grouped_orders;
56  using namespace graphene::custom_operations;
57 
58  using std::string;
59  using std::vector;
60  using std::map;
61 
62  class application;
63 
70  {
71  public:
72  explicit history_api(application& app);
73 
75  {
76  uint32_t total_count = 0;
77  vector<operation_history_object> operation_history_objs;
78  };
79 
89  vector<operation_history_object> get_account_history(
90  const std::string& account_name_or_id,
91  operation_history_id_type stop = operation_history_id_type(),
92  uint32_t limit = application_options::get_default().api_limit_get_account_history,
93  operation_history_id_type start = operation_history_id_type()
94  )const;
95 
112  vector<operation_history_object> get_account_history_by_time(
113  const std::string& account_name_or_id,
114  const optional<uint32_t>& limit = optional<uint32_t>(),
115  const optional<fc::time_point_sec>& start = optional<fc::time_point_sec>()
116  )const;
117 
128  history_operation_detail get_account_history_by_operations(
129  const std::string& account_name_or_id,
130  const flat_set<uint16_t>& operation_types,
131  uint32_t start,
132  uint32_t limit
133  )const;
134 
146  vector<operation_history_object> get_account_history_operations(
147  const std::string& account_name_or_id,
148  int64_t operation_type,
149  operation_history_id_type start = operation_history_id_type(),
150  operation_history_id_type stop = operation_history_id_type(),
151  uint32_t limit = application_options::get_default().api_limit_get_account_history_operations
152  )const;
153 
167  vector<operation_history_object> get_relative_account_history(
168  const std::string& account_name_or_id,
169  uint64_t stop = 0,
170  uint32_t limit = application_options::get_default().api_limit_get_relative_account_history,
171  uint64_t start = 0) const;
172 
186  vector<operation_history_object> get_block_operation_history(
187  uint32_t block_num,
188  const optional<uint16_t>& trx_in_block = {} ) const;
189 
202  vector<operation_history_object> get_block_operations_by_time(
204 
212  vector<order_history_object> get_fill_order_history(
213  const std::string& a,
214  const std::string& b,
215  uint32_t limit )const;
216 
229  vector<bucket_object> get_market_history( const std::string& a, const std::string& b,
230  uint32_t bucket_seconds,
231  const fc::time_point_sec& start,
232  const fc::time_point_sec& end )const;
233 
239  flat_set<uint32_t> get_market_history_buckets()const;
240 
266  vector<liquidity_pool_history_object> get_liquidity_pool_history(
267  liquidity_pool_id_type pool_id,
270  const optional<uint32_t>& limit = optional<uint32_t>(),
271  const optional<int64_t>& operation_type = optional<int64_t>() )const;
272 
295  vector<liquidity_pool_history_object> get_liquidity_pool_history_by_sequence(
296  liquidity_pool_id_type pool_id,
297  const optional<uint64_t>& start = optional<uint64_t>(),
299  const optional<uint32_t>& limit = optional<uint32_t>(),
300  const optional<int64_t>& operation_type = optional<int64_t>() )const;
301 
302  private:
303  application& _app;
304  };
305 
309  class block_api
310  {
311  public:
312  explicit block_api(const graphene::chain::database& db);
313 
320  vector<optional<signed_block>> get_blocks(uint32_t block_num_from, uint32_t block_num_to)const;
321 
322  private:
323  const graphene::chain::database& _db;
324  };
325 
326 
330  class network_broadcast_api : public std::enable_shared_from_this<network_broadcast_api>
331  {
332  public:
333  explicit network_broadcast_api(application& a);
334 
336  {
338  uint32_t block_num;
339  uint32_t trx_num;
340  processed_transaction trx;
341  };
342 
343  using confirmation_callback = std::function<void(variant/*transaction_confirmation*/)>;
344 
352  void broadcast_transaction(const precomputable_transaction& trx);
353 
360  void broadcast_transaction_with_callback( confirmation_callback cb, const precomputable_transaction& trx);
361 
367  fc::variant broadcast_transaction_synchronous(const precomputable_transaction& trx);
368 
373  void broadcast_block( const signed_block& block );
374 
383  void on_applied_block( const signed_block& b );
384  private:
385  boost::signals2::scoped_connection _applied_block_connection;
386  map<transaction_id_type,confirmation_callback> _callbacks;
387  application& _app;
388  };
389 
394  {
395  public:
396  explicit network_node_api(application& a);
397 
401  fc::variant_object get_info() const;
402 
407  void add_node(const fc::ip::endpoint& ep);
408 
412  std::vector<net::peer_status> get_connected_peers() const;
413 
418  fc::variant_object get_advanced_node_parameters() const;
419 
425  void set_advanced_node_parameters(const fc::variant_object& params);
426 
430  std::vector<net::potential_peer_record> get_potential_peers() const;
431 
432  private:
433  application& _app;
434  };
435 
440  {
441  public:
442 
444  {
445  bool success;
446  uint64_t min_val;
447  uint64_t max_val;
448  };
449 
451  {
452  bool success;
453  uint64_t min_val;
454  uint64_t max_val;
455  uint64_t value_out;
457  string message_out;
458  };
459 
468  fc::ecc::commitment_type blind( const fc::ecc::blind_factor_type& blind, uint64_t value ) const;
469 
476  fc::ecc::blind_factor_type blind_sum( const std::vector<blind_factor_type>& blinds_in,
477  uint32_t non_neg ) const;
478 
487  bool verify_sum(
488  const std::vector<commitment_type>& commits_in,
489  const std::vector<commitment_type>& neg_commits_in,
490  int64_t excess
491  ) const;
492 
500  const std::vector<char>& proof ) const;
501 
514  std::vector<char> range_proof_sign( uint64_t min_value,
515  const commitment_type& commit,
516  const blind_factor_type& commit_blind,
517  const blind_factor_type& nonce,
518  int8_t base10_exp,
519  uint8_t min_bits,
520  uint64_t actual_value ) const;
521 
530  const fc::ecc::commitment_type& commit,
531  const std::vector<char>& proof ) const;
532 
542  fc::ecc::range_proof_info range_get_info( const std::vector<char>& proof ) const;
543  };
544 
548  class asset_api
549  {
550  public:
551  explicit asset_api(graphene::app::application& app);
552 
554  {
555  string name;
556  account_id_type account_id;
558  };
560  {
561  asset_id_type asset_id;
562  int64_t count;
563  };
564 
573  vector<account_asset_balance> get_asset_holders( const std::string& asset_symbol_or_id,
574  uint32_t start, uint32_t limit )const;
575 
581  int64_t get_asset_holders_count( const std::string& asset_symbol_or_id )const;
582 
587  vector<asset_holders> get_all_asset_holders() const;
588 
589  private:
592  };
593 
598  {
599  public:
600  explicit orders_api(application& app);
601 
606  {
607  explicit limit_order_group( const std::pair<limit_order_group_key,limit_order_group_data>& p )
608  : min_price( p.first.min_price ),
609  max_price( p.second.max_price ),
610  total_for_sale( p.second.total_for_sale )
611  {}
612  limit_order_group() = default;
613 
617  };
618 
623  flat_set<uint16_t> get_tracked_groups()const;
624 
636  vector< limit_order_group > get_grouped_limit_orders( const std::string& base_asset,
637  const std::string& quote_asset,
638  uint16_t group,
639  const optional<price>& start,
640  uint32_t limit )const;
641 
642  private:
643  application& _app;
644  };
645 
651  {
652  public:
653  explicit custom_operations_api(application& app);
654 
683  vector<account_storage_object> get_storage_info(
684  const optional<std::string>& account_name_or_id = optional<std::string>(),
685  const optional<std::string>& catalog = optional<std::string>(),
686  const optional<std::string>& key = optional<std::string>(),
687  const optional<uint32_t>& limit = optional<uint32_t>(),
688  const optional<account_storage_id_type>& start_id = optional<account_storage_id_type>() )const;
689 
690  private:
691  application& _app;
692  };
693 
697  struct dummy_api
698  {
699  bool dummy() const { return false; }
700  };
701 } } // graphene::app
702 
703 extern template class fc::api<graphene::app::block_api>;
705 extern template class fc::api<graphene::app::network_node_api>;
706 extern template class fc::api<graphene::app::history_api>;
707 extern template class fc::api<graphene::app::crypto_api>;
708 extern template class fc::api<graphene::app::asset_api>;
709 extern template class fc::api<graphene::app::orders_api>;
710 extern template class fc::api<graphene::debug_witness::debug_api>;
712 extern template class fc::api<graphene::app::dummy_api>;
713 
714 namespace graphene { namespace app {
720  class login_api
721  {
722  public:
723  explicit login_api(application& a);
724 
741  variant login(const optional<string>& user, const optional<string>& password);
742 
746  bool logout();
747 
749  string get_info() const;
750 
754 
756  flat_set<string> get_available_api_sets() const;
757 
759  fc::api<block_api> block();
761  fc::api<network_broadcast_api> network_broadcast();
765  fc::api<history_api> history();
767  fc::api<network_node_api> network_node();
769  fc::api<crypto_api> crypto();
773  fc::api<orders_api> orders();
777  fc::api<custom_operations_api> custom_operations();
778 
780  fc::api<dummy_api> dummy();
781 
784  bool is_database_api_allowed() const;
785 
786  private:
787  application& _app;
788 
789  flat_set< string > _allowed_apis;
790 
791  optional< fc::api<block_api> > _block_api;
792  optional< fc::api<database_api> > _database_api;
793  optional< fc::api<network_broadcast_api> > _network_broadcast_api;
794  optional< fc::api<network_node_api> > _network_node_api;
795  optional< fc::api<history_api> > _history_api;
796  optional< fc::api<crypto_api> > _crypto_api;
797  optional< fc::api<asset_api> > _asset_api;
798  optional< fc::api<orders_api> > _orders_api;
799  optional< fc::api<graphene::debug_witness::debug_api> > _debug_api;
800  optional< fc::api<custom_operations_api> > _custom_operations_api;
801  optional< fc::api<dummy_api> > _dummy_api;
802  };
803 
804 }} // graphene::app
805 
806 extern template class fc::api<graphene::app::login_api>;
807 
809  (id)(block_num)(trx_num)(trx) )
810 
812  (success)(min_val)(max_val) )
814  (success)(min_val)(max_val)(value_out)(blind_out)(message_out) )
815 
817  (total_count)(operation_history_objs) )
818 
820  (min_price)(max_price)(total_for_sale) )
821 
822 FC_REFLECT( graphene::app::asset_api::account_asset_balance, (name)(account_id)(amount) )
824 
826  (get_account_history)
827  (get_account_history_by_time)
828  (get_account_history_by_operations)
829  (get_account_history_operations)
830  (get_relative_account_history)
831  (get_block_operation_history)
832  (get_block_operations_by_time)
833  (get_fill_order_history)
834  (get_market_history)
835  (get_market_history_buckets)
836  (get_liquidity_pool_history)
837  (get_liquidity_pool_history_by_sequence)
838  )
840  (get_blocks)
841  )
843  (broadcast_transaction)
844  (broadcast_transaction_with_callback)
845  (broadcast_transaction_synchronous)
846  (broadcast_block)
847  )
849  (get_info)
850  (add_node)
851  (get_connected_peers)
852  (get_potential_peers)
853  (get_advanced_node_parameters)
854  (set_advanced_node_parameters)
855  )
857  (blind)
858  (blind_sum)
859  (verify_sum)
860  (verify_range)
864  )
866  (get_asset_holders)
867  (get_asset_holders_count)
868  (get_all_asset_holders)
869  )
871  (get_tracked_groups)
872  (get_grouped_limit_orders)
873  )
875  (get_storage_info)
876  )
878  (dummy)
879  )
881  (login)
882  (logout)
883  (get_info)
884  (get_config)
885  (get_available_api_sets)
886  (block)
887  (network_broadcast)
888  (database)
889  (history)
890  (network_node)
891  (crypto)
892  (asset)
893  (orders)
894  (debug)
895  (custom_operations)
896  )
graphene::app::crypto_api::verify_range_result::success
bool success
Definition: api.hpp:445
graphene::app::orders_api::limit_order_group::max_price
price max_price
possible highest price in the group
Definition: api.hpp:615
fc::variant_object
An order-perserving dictionary of variant's.
Definition: variant_object.hpp:20
graphene::app::crypto_api::verify_range_result::max_val
uint64_t max_val
Definition: api.hpp:447
ip.hpp
graphene::app::asset_api::account_asset_balance
Definition: api.hpp:553
fc::ecc::verify_range
bool verify_range(uint64_t &min_val, uint64_t &max_val, const commitment_type &commit, const range_proof_type &proof)
Definition: elliptic_secp256k1.cpp:235
graphene::app::login_api
The login_api class implements the bottom layer of the RPC API.
Definition: api.hpp:720
graphene::chain::database
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
graphene::app::dummy_api::dummy
bool dummy() const
Definition: api.hpp:699
graphene::app::orders_api::limit_order_group::total_for_sale
share_type total_for_sale
total amount of asset for sale, asset id is min_price.base.asset_id
Definition: api.hpp:616
graphene::app::crypto_api::verify_range_proof_rewind_result::value_out
uint64_t value_out
Definition: api.hpp:455
graphene::app::crypto_api::verify_range_proof_rewind_result
Definition: api.hpp:450
graphene::app::asset_api
The asset_api class allows query of info about asset holders.
Definition: api.hpp:548
graphene::protocol::price
The price struct stores asset prices in the BitShares system.
Definition: asset.hpp:108
graphene::app::history_api
The history_api class implements the RPC API for account history.
Definition: api.hpp:69
fc::ecc::range_proof_info
Definition: elliptic.hpp:196
fc::typelist::first
at< List, 0 > first
Get the type at the beginning of the list.
Definition: typelist.hpp:190
fc::ecc::range_proof_sign
range_proof_type range_proof_sign(uint64_t min_value, const commitment_type &commit, const blind_factor_type &commit_blind, const blind_factor_type &nonce, int8_t base10_exp, uint8_t min_bits, uint64_t actual_value)
Definition: elliptic_secp256k1.cpp:240
fc::ecc::blind_sum
blind_factor_type blind_sum(const std::vector< blind_factor_type > &blinds, uint32_t non_neg)
Definition: elliptic_secp256k1.cpp:215
graphene::protocol::transaction_id_type
fc::ripemd160 transaction_id_type
Definition: types.hpp:306
graphene::app::crypto_api::verify_range_result::min_val
uint64_t min_val
Definition: api.hpp:446
graphene::grouped_orders
Definition: grouped_orders_plugin.cpp:29
node.hpp
fc::ecc::blind
commitment_type blind(const blind_factor_type &blind, uint64_t value)
Definition: elliptic_secp256k1.cpp:208
graphene::chain::get_config
fc::variant_object get_config()
Definition: get_config.cpp:31
graphene::app::history_api::history_operation_detail
Definition: api.hpp:74
graphene::app::orders_api::limit_order_group
summary data of a group of limit orders
Definition: api.hpp:605
market_history_plugin.hpp
fc::sha256
Definition: sha256.hpp:10
graphene::app::crypto_api::verify_range_proof_rewind_result::max_val
uint64_t max_val
Definition: api.hpp:454
fc::zero_initialized_array< unsigned char, 33 >
graphene::app::history_api::history_operation_detail::operation_history_objs
vector< operation_history_object > operation_history_objs
Definition: api.hpp:77
graphene::app::crypto_api::verify_range_result
Definition: api.hpp:443
graphene::app::orders_api
the orders_api class exposes access to data processed with grouped orders plugin.
Definition: api.hpp:597
graphene::app::network_broadcast_api::transaction_confirmation::block_num
uint32_t block_num
Definition: api.hpp:338
graphene::app::application_options::get_default
static constexpr application_options get_default()
Definition: application.hpp:84
graphene::app::block_api
Block api.
Definition: api.hpp:309
fc::ip::endpoint
Definition: ip.hpp:65
graphene::app::application
Definition: application.hpp:91
graphene::app::network_node_api
The network_node_api class allows maintenance of p2p connections.
Definition: api.hpp:393
fc::ecc::range_get_info
range_proof_info range_get_info(const range_proof_type &proof)
Definition: elliptic_secp256k1.cpp:291
types.hpp
graphene::app::asset_api::account_asset_balance::name
string name
Definition: api.hpp:555
fc::ecc::verify_range_proof_rewind
bool verify_range_proof_rewind(blind_factor_type &blind_out, uint64_t &value_out, string &message_out, const blind_factor_type &nonce, uint64_t &min_val, uint64_t &max_val, commitment_type commit, const range_proof_type &proof)
Definition: elliptic_secp256k1.cpp:264
graphene::custom_operations
Definition: custom_evaluators.cpp:30
graphene::app::crypto_api::verify_range_proof_rewind_result::min_val
uint64_t min_val
Definition: api.hpp:453
graphene::app::custom_operations_api
The custom_operations_api class exposes access to standard custom objects parsed by the custom_operat...
Definition: api.hpp:650
elasticsearch_plugin.hpp
graphene::app::asset_api::asset_holders::asset_id
asset_id_type asset_id
Definition: api.hpp:561
graphene::app::network_broadcast_api::transaction_confirmation::id
transaction_id_type id
Definition: api.hpp:337
graphene::app::crypto_api::verify_range_proof_rewind_result::success
bool success
Definition: api.hpp:452
fc::time_point_sec
Definition: time.hpp:74
api.hpp
fc::ecc::commitment_type
zero_initialized_array< unsigned char, 33 > commitment_type
Definition: elliptic.hpp:22
graphene::app::crypto_api::verify_range_proof_rewind_result::blind_out
fc::ecc::blind_factor_type blind_out
Definition: api.hpp:456
graphene::app::network_broadcast_api
The network_broadcast_api class allows broadcasting of transactions.
Definition: api.hpp:330
graphene::app::asset_api::account_asset_balance::amount
share_type amount
Definition: api.hpp:557
graphene::app::orders_api::limit_order_group::min_price
price min_price
possible lowest price in the group
Definition: api.hpp:614
graphene::app::orders_api::limit_order_group::limit_order_group
limit_order_group(const std::pair< limit_order_group_key, limit_order_group_data > &p)
Definition: api.hpp:607
graphene::app::dummy_api
A dummy API class that does nothing, used when access to database_api is not allowed.
Definition: api.hpp:697
graphene::market_history
Definition: market_history_plugin.hpp:35
graphene::app::network_broadcast_api::transaction_confirmation::trx
processed_transaction trx
Definition: api.hpp:340
FC_API
#define FC_API(CLASS, METHODS)
Definition: api.hpp:197
fc::scoped_connection
boost::signals2::scoped_connection scoped_connection
Definition: signals.hpp:22
fc::variant
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition: variant.hpp:198
graphene::app::network_broadcast_api::confirmation_callback
std::function< void(variant)> confirmation_callback
Definition: api.hpp:343
graphene::app::crypto_api
The crypto_api class allows computations related to blinded transfers.
Definition: api.hpp:439
custom_operations_plugin.hpp
graphene::app::crypto_api::verify_range_proof_rewind_result::message_out
string message_out
Definition: api.hpp:457
graphene::app::asset_api::account_asset_balance::account_id
account_id_type account_id
Definition: api.hpp:556
graphene::app::network_broadcast_api::transaction_confirmation
Definition: api.hpp:335
fc::ecc::blind_factor_type
fc::sha256 blind_factor_type
Definition: elliptic.hpp:21
elliptic.hpp
graphene::app::asset_api::asset_holders::count
int64_t count
Definition: api.hpp:562
grouped_orders_plugin.hpp
FC_REFLECT
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition: reflect.hpp:388
graphene::app::asset_api::asset_holders
Definition: api.hpp:559
database_api.hpp
fc::optional
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
graphene::app::network_broadcast_api::transaction_confirmation::trx_num
uint32_t trx_num
Definition: api.hpp:339
graphene::protocol::asset
Definition: asset.hpp:31
graphene::protocol::signed_block
Definition: block.hpp:64
fc::ecc::verify_sum
bool verify_sum(const std::vector< commitment_type > &commits, const std::vector< commitment_type > &neg_commits, int64_t excess)
Definition: elliptic_secp256k1.cpp:225
fc::api
Definition: api.hpp:120
graphene::chain
Definition: util.hpp:32
debug_api.hpp
graphene
Definition: api.cpp:48
graphene::app::application_options
Definition: application.hpp:38
fc::safe
Definition: safe.hpp:26
optional.hpp