BitShares-Core  6.0.1
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_name_or_id,
138  operation_history_id_type stop = operation_history_id_type(),
139  uint32_t 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_name_or_id,
154  flat_set<uint16_t> operation_types,
155  uint32_t start,
156  uint32_t limit
157  )const;
158 
169  vector<operation_history_object> get_account_history_operations(
170  const std::string account_name_or_id,
171  int64_t operation_type,
172  operation_history_id_type start = operation_history_id_type(),
173  operation_history_id_type stop = operation_history_id_type(),
174  uint32_t limit = 100
175  )const;
176 
189  vector<operation_history_object> get_relative_account_history( const std::string account_name_or_id,
190  uint64_t stop = 0,
191  uint32_t 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 
246  vector<liquidity_pool_history_object> get_liquidity_pool_history(
247  liquidity_pool_id_type pool_id,
248  optional<fc::time_point_sec> start = optional<fc::time_point_sec>(),
249  optional<fc::time_point_sec> stop = optional<fc::time_point_sec>(),
250  optional<uint32_t> limit = 101,
251  optional<int64_t> operation_type = optional<int64_t>() )const;
252 
275  vector<liquidity_pool_history_object> get_liquidity_pool_history_by_sequence(
276  liquidity_pool_id_type pool_id,
277  optional<uint64_t> start = optional<uint64_t>(),
278  optional<fc::time_point_sec> stop = optional<fc::time_point_sec>(),
279  optional<uint32_t> limit = 101,
280  optional<int64_t> operation_type = optional<int64_t>() )const;
281 
282  private:
283  application& _app;
285  };
286 
290  class block_api
291  {
292  public:
294  ~block_api();
295 
302  vector<optional<signed_block>> get_blocks(uint32_t block_num_from, uint32_t block_num_to)const;
303 
304  private:
306  };
307 
308 
312  class network_broadcast_api : public std::enable_shared_from_this<network_broadcast_api>
313  {
314  public:
316 
318  {
320  uint32_t block_num;
321  uint32_t trx_num;
323  };
324 
325  typedef std::function<void(variant/*transaction_confirmation*/)> confirmation_callback;
326 
334  void broadcast_transaction(const precomputable_transaction& trx);
335 
342  void broadcast_transaction_with_callback( confirmation_callback cb, const precomputable_transaction& trx);
343 
349  fc::variant broadcast_transaction_synchronous(const precomputable_transaction& trx);
350 
355  void broadcast_block( const signed_block& block );
356 
365  void on_applied_block( const signed_block& b );
366  private:
367  boost::signals2::scoped_connection _applied_block_connection;
368  map<transaction_id_type,confirmation_callback> _callbacks;
369  application& _app;
370  };
371 
376  {
377  public:
379 
383  fc::variant_object get_info() const;
384 
389  void add_node(const fc::ip::endpoint& ep);
390 
394  std::vector<net::peer_status> get_connected_peers() const;
395 
400  fc::variant_object get_advanced_node_parameters() const;
401 
407  void set_advanced_node_parameters(const fc::variant_object& params);
408 
412  std::vector<net::potential_peer_record> get_potential_peers() const;
413 
414  private:
415  application& _app;
416  };
417 
422  {
423  public:
424  crypto_api();
425 
435 
442  fc::ecc::blind_factor_type blind_sum( const std::vector<blind_factor_type>& blinds_in, uint32_t non_neg );
443 
452  bool verify_sum(
453  const std::vector<commitment_type>& commits_in,
454  const std::vector<commitment_type>& neg_commits_in,
455  int64_t excess
456  );
457 
464  verify_range_result verify_range( const fc::ecc::commitment_type& commit, const std::vector<char>& proof );
465 
478  std::vector<char> range_proof_sign( uint64_t min_value,
479  const commitment_type& commit,
480  const blind_factor_type& commit_blind,
481  const blind_factor_type& nonce,
482  int8_t base10_exp,
483  uint8_t min_bits,
484  uint64_t actual_value );
485 
494  const fc::ecc::commitment_type& commit,
495  const std::vector<char>& proof );
496 
506  range_proof_info range_get_info( const std::vector<char>& proof );
507  };
508 
512  class asset_api
513  {
514  public:
516  ~asset_api();
517 
525  vector<account_asset_balance> get_asset_holders( std::string asset, uint32_t start, uint32_t limit )const;
526 
532  int get_asset_holders_count( std::string asset )const;
533 
538  vector<asset_holders> get_all_asset_holders() const;
539 
540  private:
544  };
545 
550  {
551  public:
553  :_app(app), database_api( std::ref(*app.chain_database()), &(app.get_options()) ){}
554  //virtual ~orders_api() {}
555 
560  flat_set<uint16_t> get_tracked_groups()const;
561 
572  vector< limit_order_group > get_grouped_limit_orders( std::string base_asset,
573  std::string quote_asset,
574  uint16_t group,
575  optional<price> start,
576  uint32_t limit )const;
577 
578  private:
579  application& _app;
581  };
582 
588  {
589  public:
590  custom_operations_api(application& app):_app(app), database_api( *app.chain_database(),
591  &(app.get_options()) ){}
592 
601  vector<account_storage_object> get_storage_info(std::string account_name_or_id, std::string catalog)const;
602 
603  private:
604  application& _app;
606  };
607 } } // graphene::app
608 
609 extern template class fc::api<graphene::app::block_api>;
611 extern template class fc::api<graphene::app::network_node_api>;
612 extern template class fc::api<graphene::app::history_api>;
613 extern template class fc::api<graphene::app::crypto_api>;
614 extern template class fc::api<graphene::app::asset_api>;
615 extern template class fc::api<graphene::app::orders_api>;
616 extern template class fc::api<graphene::debug_witness::debug_api>;
618 
619 namespace graphene { namespace app {
625  class login_api
626  {
627  public:
629  ~login_api();
630 
640  bool login(const string& user, const string& password);
642  fc::api<block_api> block()const;
644  fc::api<network_broadcast_api> network_broadcast()const;
648  fc::api<history_api> history()const;
650  fc::api<network_node_api> network_node()const;
652  fc::api<crypto_api> crypto()const;
654  fc::api<asset_api> asset()const;
656  fc::api<orders_api> orders()const;
660  fc::api<custom_operations_api> custom_operations()const;
661 
663  void enable_api( const string& api_name );
664  private:
665 
666  application& _app;
667  optional< fc::api<block_api> > _block_api;
668  optional< fc::api<database_api> > _database_api;
669  optional< fc::api<network_broadcast_api> > _network_broadcast_api;
670  optional< fc::api<network_node_api> > _network_node_api;
671  optional< fc::api<history_api> > _history_api;
672  optional< fc::api<crypto_api> > _crypto_api;
673  optional< fc::api<asset_api> > _asset_api;
674  optional< fc::api<orders_api> > _orders_api;
676  optional< fc::api<custom_operations_api> > _custom_operations_api;
677  };
678 
679 }} // graphene::app
680 
681 extern template class fc::api<graphene::app::login_api>;
682 
684  (id)(block_num)(trx_num)(trx) )
686  (success)(min_val)(max_val) )
688  (success)(min_val)(max_val)(value_out)(blind_out)(message_out) )
690  (total_count)(operation_history_objs) )
692  (min_price)(max_price)(total_for_sale) )
693 //FC_REFLECT_TYPENAME( fc::ecc::compact_signature )
694 //FC_REFLECT_TYPENAME( fc::ecc::commitment_type )
695 
696 FC_REFLECT( graphene::app::account_asset_balance, (name)(account_id)(amount) )
697 FC_REFLECT( graphene::app::asset_holders, (asset_id)(count) )
698 
700  (get_account_history)
701  (get_account_history_by_operations)
702  (get_account_history_operations)
703  (get_relative_account_history)
704  (get_fill_order_history)
705  (get_market_history)
706  (get_market_history_buckets)
707  (get_liquidity_pool_history)
708  (get_liquidity_pool_history_by_sequence)
709  )
711  (get_blocks)
712  )
714  (broadcast_transaction)
715  (broadcast_transaction_with_callback)
716  (broadcast_transaction_synchronous)
717  (broadcast_block)
718  )
720  (get_info)
721  (add_node)
722  (get_connected_peers)
723  (get_potential_peers)
724  (get_advanced_node_parameters)
725  (set_advanced_node_parameters)
726  )
728  (blind)
729  (blind_sum)
730  (verify_sum)
731  (verify_range)
735  )
737  (get_asset_holders)
738  (get_asset_holders_count)
739  (get_all_asset_holders)
740  )
742  (get_tracked_groups)
743  (get_grouped_limit_orders)
744  )
746  (get_storage_info)
747  )
749  (login)
750  (block)
751  (network_broadcast)
752  (database)
753  (history)
754  (network_node)
755  (crypto)
756  (asset)
757  (orders)
758  (debug)
759  (custom_operations)
760  )
asset_id_type asset_id
Definition: api.hpp:91
The login_api class implements the bottom layer of the RPC API.
Definition: api.hpp:625
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:549
The network_node_api class allows maintenance of p2p connections.
Definition: api.hpp:375
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:388
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:421
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:587
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:325
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:590
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:274
orders_api(application &app)
Definition: api.hpp:552
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:312
The asset_api class allows query of info about asset holders.
Definition: api.hpp:512
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