BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface 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 
30 
34 
36 
38 
39 #include <graphene/net/node.hpp>
40 
41 #include <fc/api.hpp>
42 #include <fc/optional.hpp>
43 #include <fc/crypto/elliptic.hpp>
44 #include <fc/network/ip.hpp>
45 
46 #include <boost/container/flat_set.hpp>
47 
48 #include <functional>
49 #include <map>
50 #include <string>
51 #include <vector>
52 
53 namespace graphene { namespace app {
54  using namespace graphene::chain;
55  using namespace graphene::market_history;
56  using namespace graphene::grouped_orders;
57  using namespace graphene::custom_operations;
58 
59  using namespace fc::ecc;
60  using std::string;
61  using std::vector;
62  using std::map;
63 
64  class application;
65 
67  {
68  bool success;
69  uint64_t min_val;
70  uint64_t max_val;
71  };
72 
74  {
75  bool success;
76  uint64_t min_val;
77  uint64_t max_val;
78  uint64_t value_out;
80  string message_out;
81  };
82 
84  {
85  string name;
86  account_id_type account_id;
88  };
90  {
91  asset_id_type asset_id;
92  int count;
93  };
94 
96  uint32_t total_count = 0;
97  vector<operation_history_object> operation_history_objs;
98  };
99 
104  {
105  limit_order_group( const std::pair<limit_order_group_key,limit_order_group_data>& p )
106  : min_price( p.first.min_price ),
107  max_price( p.second.max_price ),
108  total_for_sale( p.second.total_for_sale )
109  {}
111 
112  price min_price;
113  price max_price;
115  };
116 
123  {
124  public:
126  :_app(app), database_api( std::ref(*app.chain_database()), &(app.get_options())) {}
127 
136  vector<operation_history_object> get_account_history(
137  const std::string account_id_or_name,
138  operation_history_id_type stop = operation_history_id_type(),
139  unsigned limit = 100,
140  operation_history_id_type start = operation_history_id_type()
141  )const;
142 
152  history_operation_detail get_account_history_by_operations(
153  const std::string account_id_or_name,
154  flat_set<uint16_t> operation_types,
155  uint32_t start,
156  unsigned limit
157  )const;
158 
169  vector<operation_history_object> get_account_history_operations(
170  const std::string account_id_or_name,
171  int operation_type,
172  operation_history_id_type start = operation_history_id_type(),
173  operation_history_id_type stop = operation_history_id_type(),
174  unsigned limit = 100
175  )const;
176 
189  vector<operation_history_object> get_relative_account_history( const std::string account_id_or_name,
190  uint64_t stop = 0,
191  unsigned limit = 100,
192  uint64_t start = 0) const;
193 
201  vector<order_history_object> get_fill_order_history( std::string a, std::string b, uint32_t limit )const;
202 
214  vector<bucket_object> get_market_history( std::string a, std::string b, uint32_t bucket_seconds,
215  fc::time_point_sec start, fc::time_point_sec end )const;
216 
222  flat_set<uint32_t> get_market_history_buckets()const;
223  private:
224  application& _app;
226  };
227 
231  class block_api
232  {
233  public:
235  ~block_api();
236 
243  vector<optional<signed_block>> get_blocks(uint32_t block_num_from, uint32_t block_num_to)const;
244 
245  private:
247  };
248 
249 
253  class network_broadcast_api : public std::enable_shared_from_this<network_broadcast_api>
254  {
255  public:
257 
259  {
261  uint32_t block_num;
262  uint32_t trx_num;
264  };
265 
266  typedef std::function<void(variant/*transaction_confirmation*/)> confirmation_callback;
267 
275  void broadcast_transaction(const precomputable_transaction& trx);
276 
283  void broadcast_transaction_with_callback( confirmation_callback cb, const precomputable_transaction& trx);
284 
290  fc::variant broadcast_transaction_synchronous(const precomputable_transaction& trx);
291 
296  void broadcast_block( const signed_block& block );
297 
306  void on_applied_block( const signed_block& b );
307  private:
308  boost::signals2::scoped_connection _applied_block_connection;
309  map<transaction_id_type,confirmation_callback> _callbacks;
310  application& _app;
311  };
312 
317  {
318  public:
320 
324  fc::variant_object get_info() const;
325 
330  void add_node(const fc::ip::endpoint& ep);
331 
335  std::vector<net::peer_status> get_connected_peers() const;
336 
341  fc::variant_object get_advanced_node_parameters() const;
342 
348  void set_advanced_node_parameters(const fc::variant_object& params);
349 
353  std::vector<net::potential_peer_record> get_potential_peers() const;
354 
355  private:
356  application& _app;
357  };
358 
363  {
364  public:
365  crypto_api();
366 
376 
383  fc::ecc::blind_factor_type blind_sum( const std::vector<blind_factor_type>& blinds_in, uint32_t non_neg );
384 
393  bool verify_sum(
394  const std::vector<commitment_type>& commits_in,
395  const std::vector<commitment_type>& neg_commits_in,
396  int64_t excess
397  );
398 
405  verify_range_result verify_range( const fc::ecc::commitment_type& commit, const std::vector<char>& proof );
406 
419  std::vector<char> range_proof_sign( uint64_t min_value,
420  const commitment_type& commit,
421  const blind_factor_type& commit_blind,
422  const blind_factor_type& nonce,
423  int8_t base10_exp,
424  uint8_t min_bits,
425  uint64_t actual_value );
426 
435  const fc::ecc::commitment_type& commit,
436  const std::vector<char>& proof );
437 
447  range_proof_info range_get_info( const std::vector<char>& proof );
448  };
449 
453  class asset_api
454  {
455  public:
457  ~asset_api();
458 
466  vector<account_asset_balance> get_asset_holders( std::string asset, uint32_t start, uint32_t limit )const;
467 
473  int get_asset_holders_count( std::string asset )const;
474 
479  vector<asset_holders> get_all_asset_holders() const;
480 
481  private:
485  };
486 
491  {
492  public:
494  :_app(app), database_api( std::ref(*app.chain_database()), &(app.get_options()) ){}
495  //virtual ~orders_api() {}
496 
501  flat_set<uint16_t> get_tracked_groups()const;
502 
513  vector< limit_order_group > get_grouped_limit_orders( std::string base_asset,
514  std::string quote_asset,
515  uint16_t group,
516  optional<price> start,
517  uint32_t limit )const;
518 
519  private:
520  application& _app;
522  };
523 
529  {
530  public:
531  custom_operations_api(application& app):_app(app), database_api( *app.chain_database(),
532  &(app.get_options()) ){}
533 
542  vector<account_storage_object> get_storage_info(std::string account_id_or_name, std::string catalog)const;
543 
544  private:
545  application& _app;
547  };
548 } } // graphene::app
549 
550 extern template class fc::api<graphene::app::block_api>;
552 extern template class fc::api<graphene::app::network_node_api>;
553 extern template class fc::api<graphene::app::history_api>;
554 extern template class fc::api<graphene::app::crypto_api>;
555 extern template class fc::api<graphene::app::asset_api>;
556 extern template class fc::api<graphene::app::orders_api>;
557 extern template class fc::api<graphene::debug_witness::debug_api>;
559 
560 namespace graphene { namespace app {
566  class login_api
567  {
568  public:
570  ~login_api();
571 
581  bool login(const string& user, const string& password);
583  fc::api<block_api> block()const;
585  fc::api<network_broadcast_api> network_broadcast()const;
589  fc::api<history_api> history()const;
591  fc::api<network_node_api> network_node()const;
593  fc::api<crypto_api> crypto()const;
595  fc::api<asset_api> asset()const;
597  fc::api<orders_api> orders()const;
601  fc::api<custom_operations_api> custom_operations()const;
602 
604  void enable_api( const string& api_name );
605  private:
606 
607  application& _app;
608  optional< fc::api<block_api> > _block_api;
609  optional< fc::api<database_api> > _database_api;
610  optional< fc::api<network_broadcast_api> > _network_broadcast_api;
611  optional< fc::api<network_node_api> > _network_node_api;
612  optional< fc::api<history_api> > _history_api;
613  optional< fc::api<crypto_api> > _crypto_api;
614  optional< fc::api<asset_api> > _asset_api;
615  optional< fc::api<orders_api> > _orders_api;
617  optional< fc::api<custom_operations_api> > _custom_operations_api;
618  };
619 
620 }} // graphene::app
621 
622 extern template class fc::api<graphene::app::login_api>;
623 
625  (id)(block_num)(trx_num)(trx) )
627  (success)(min_val)(max_val) )
629  (success)(min_val)(max_val)(value_out)(blind_out)(message_out) )
631  (total_count)(operation_history_objs) )
633  (min_price)(max_price)(total_for_sale) )
634 //FC_REFLECT_TYPENAME( fc::ecc::compact_signature )
635 //FC_REFLECT_TYPENAME( fc::ecc::commitment_type )
636 
637 FC_REFLECT( graphene::app::account_asset_balance, (name)(account_id)(amount) )
638 FC_REFLECT( graphene::app::asset_holders, (asset_id)(count) )
639 
641  (get_account_history)
642  (get_account_history_by_operations)
643  (get_account_history_operations)
644  (get_relative_account_history)
645  (get_fill_order_history)
646  (get_market_history)
647  (get_market_history_buckets)
648  )
650  (get_blocks)
651  )
653  (broadcast_transaction)
654  (broadcast_transaction_with_callback)
655  (broadcast_transaction_synchronous)
656  (broadcast_block)
657  )
659  (get_info)
660  (add_node)
661  (get_connected_peers)
662  (get_potential_peers)
663  (get_advanced_node_parameters)
664  (set_advanced_node_parameters)
665  )
667  (blind)
668  (blind_sum)
669  (verify_sum)
670  (verify_range)
674  )
676  (get_asset_holders)
677  (get_asset_holders_count)
678  (get_all_asset_holders)
679  )
681  (get_tracked_groups)
682  (get_grouped_limit_orders)
683  )
685  (get_storage_info)
686  )
688  (login)
689  (block)
690  (network_broadcast)
691  (database)
692  (history)
693  (network_node)
694  (crypto)
695  (asset)
696  (orders)
697  (debug)
698  (custom_operations)
699  )
asset_id_type asset_id
Definition: api.hpp:91
The login_api class implements the bottom layer of the RPC API.
Definition: api.hpp:566
price max_price
possible highest price in the group
Definition: api.hpp:113
the orders_api class exposes access to data processed with grouped orders plugin. ...
Definition: api.hpp:490
The network_node_api class allows maintenance of p2p connections.
Definition: api.hpp:316
bool verify_range(uint64_t &min_val, uint64_t &max_val, const commitment_type &commit, const range_proof_type &proof)
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition: reflect.hpp:386
bool verify_sum(const std::vector< commitment_type > &commits, const std::vector< commitment_type > &neg_commits, int64_t excess)
tracks the blockchain state in an extensible manner
Definition: database.hpp:70
An order-perserving dictionary of variant&#39;s.
Definition: api.cpp:56
range_proof_info range_get_info(const range_proof_type &proof)
The crypto_api class allows computations related to blinded transfers.
Definition: api.hpp:362
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
limit_order_group(const std::pair< limit_order_group_key, limit_order_group_data > &p)
Definition: api.hpp:105
#define FC_API(CLASS, METHODS)
Definition: api.hpp:197
commitment_type blind(const blind_factor_type &blind, uint64_t value)
The custom_operations_api class exposes access to standard custom objects parsed by the custom_operat...
Definition: api.hpp:528
vector< operation_history_object > operation_history_objs
Definition: api.hpp:97
price min_price
possible lowest price in the group
Definition: api.hpp:112
history_api(application &app)
Definition: api.hpp:125
summary data of a group of limit orders
Definition: api.hpp:103
The database_api class implements the RPC API for the chain database.
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object&#39;s.
Definition: variant.hpp:198
std::function< void(variant)> confirmation_callback
Definition: api.hpp:266
share_type total_for_sale
total amount of asset for sale, asset id is min_price.base.asset_id
Definition: api.hpp:114
at< List, 0 > first
Get the type at the beginning of the list.
Definition: typelist.hpp:190
custom_operations_api(application &app)
Definition: api.hpp:531
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)
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)
blind_factor_type blind_sum(const std::vector< blind_factor_type > &blinds, uint32_t non_neg)
safe< int64_t > share_type
Definition: types.hpp:247
orders_api(application &app)
Definition: api.hpp:493
The history_api class implements the RPC API for account history.
Definition: api.hpp:122
The network_broadcast_api class allows broadcasting of transactions.
Definition: api.hpp:253
The asset_api class allows query of info about asset holders.
Definition: api.hpp:453
boost::signals2::scoped_connection scoped_connection
Definition: signals.hpp:22
fc::ecc::blind_factor_type blind_out
Definition: api.hpp:79
captures the result of evaluating the operations contained in the transaction
Definition: api.hpp:120