BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface software
api.cpp
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 #include <cctype>
25 
26 #include <graphene/app/api.hpp>
38 
39 #include <fc/crypto/base64.hpp>
40 #include <fc/crypto/hex.hpp>
42 #include <fc/thread/future.hpp>
43 
54 
55 
56 namespace graphene { namespace app {
57 
58  login_api::login_api(application& a)
59  :_app(a)
60  {
61  }
62 
64  {
65  }
66 
67  bool login_api::login(const string& user, const string& password)
68  {
70  if( !acc.valid() )
71  return false;
72  if( acc->password_hash_b64 != "*" )
73  {
74  std::string password_salt = fc::base64_decode( acc->password_salt_b64 );
75  std::string acc_password_hash = fc::base64_decode( acc->password_hash_b64 );
76 
77  fc::sha256 hash_obj = fc::sha256::hash( password + password_salt );
78  if( hash_obj.data_size() != acc_password_hash.length() )
79  return false;
80  if( memcmp( hash_obj.data(), acc_password_hash.c_str(), hash_obj.data_size() ) != 0 )
81  return false;
82  }
83 
84  for( const std::string& api_name : acc->allowed_apis )
85  enable_api( api_name );
86  return true;
87  }
88 
89  void login_api::enable_api( const std::string& api_name )
90  {
91  if( api_name == "database_api" )
92  {
93  _database_api = std::make_shared< database_api >( std::ref( *_app.chain_database() ), &( _app.get_options() ) );
94  }
95  else if( api_name == "block_api" )
96  {
97  _block_api = std::make_shared< block_api >( std::ref( *_app.chain_database() ) );
98  }
99  else if( api_name == "network_broadcast_api" )
100  {
101  _network_broadcast_api = std::make_shared< network_broadcast_api >( std::ref( _app ) );
102  }
103  else if( api_name == "history_api" )
104  {
105  _history_api = std::make_shared< history_api >( _app );
106  }
107  else if( api_name == "network_node_api" )
108  {
109  _network_node_api = std::make_shared< network_node_api >( std::ref(_app) );
110  }
111  else if( api_name == "crypto_api" )
112  {
113  _crypto_api = std::make_shared< crypto_api >();
114  }
115  else if( api_name == "asset_api" )
116  {
117  _asset_api = std::make_shared< asset_api >( _app );
118  }
119  else if( api_name == "orders_api" )
120  {
121  _orders_api = std::make_shared< orders_api >( std::ref( _app ) );
122  }
123  else if( api_name == "custom_operations_api" )
124  {
125  if( _app.get_plugin( "custom_operations" ) )
126  _custom_operations_api = std::make_shared< custom_operations_api >( std::ref( _app ) );
127  }
128  else if( api_name == "debug_api" )
129  {
130  // can only enable this API if the plugin was loaded
131  if( _app.get_plugin( "debug_witness" ) )
132  _debug_api = std::make_shared< graphene::debug_witness::debug_api >( std::ref(_app) );
133  }
134  return;
135  }
136 
137  // block_api
140 
141  vector<optional<signed_block>> block_api::get_blocks(uint32_t block_num_from, uint32_t block_num_to)const
142  {
143  FC_ASSERT( block_num_to >= block_num_from );
144  vector<optional<signed_block>> res;
145  for(uint32_t block_num=block_num_from; block_num<=block_num_to; block_num++) {
146  res.push_back(_db.fetch_block_by_number(block_num));
147  }
148  return res;
149  }
150 
152  {
153  _applied_block_connection = _app.chain_database()->applied_block.connect([this](const signed_block& b){ on_applied_block(b); });
154  }
155 
156  void network_broadcast_api::on_applied_block( const signed_block& b )
157  {
158  if( _callbacks.size() )
159  {
161  auto capture_this = shared_from_this();
162  for( uint32_t trx_num = 0; trx_num < b.transactions.size(); ++trx_num )
163  {
164  const auto& trx = b.transactions[trx_num];
165  auto id = trx.id();
166  auto itr = _callbacks.find(id);
167  if( itr != _callbacks.end() )
168  {
169  auto block_num = b.block_num();
170  auto& callback = _callbacks.find(id)->second;
171  auto v = fc::variant( transaction_confirmation{ id, block_num, trx_num, trx }, GRAPHENE_MAX_NESTED_OBJECTS );
172  fc::async( [capture_this,v,callback]() {
173  callback(v);
174  } );
175  }
176  }
177  }
178  }
179 
180  void network_broadcast_api::broadcast_transaction(const precomputable_transaction& trx)
181  {
182  _app.chain_database()->precompute_parallel( trx ).wait();
183  _app.chain_database()->push_transaction(trx);
184  if( _app.p2p_node() != nullptr )
185  _app.p2p_node()->broadcast_transaction(trx);
186  }
187 
189  {
192  prom->set_value(v);
193  }, trx );
194 
195  return fc::future<fc::variant>(prom).wait();
196  }
197 
198  void network_broadcast_api::broadcast_block( const signed_block& b )
199  {
200  _app.chain_database()->precompute_parallel( b ).wait();
201  _app.chain_database()->push_block(b);
202  if( _app.p2p_node() != nullptr )
203  _app.p2p_node()->broadcast( net::block_message( b ));
204  }
205 
207  {
208  _app.chain_database()->precompute_parallel( trx ).wait();
209  _callbacks[trx.id()] = cb;
210  _app.chain_database()->push_transaction(trx);
211  if( _app.p2p_node() != nullptr )
212  _app.p2p_node()->broadcast_transaction(trx);
213  }
214 
216  {
217  }
218 
220  {
221  fc::mutable_variant_object result = _app.p2p_node()->network_get_info();
222  result["connection_count"] = _app.p2p_node()->get_connection_count();
223  return result;
224  }
225 
227  {
228  _app.p2p_node()->add_node(ep);
229  }
230 
231  std::vector<net::peer_status> network_node_api::get_connected_peers() const
232  {
233  return _app.p2p_node()->get_connected_peers();
234  }
235 
236  std::vector<net::potential_peer_record> network_node_api::get_potential_peers() const
237  {
238  return _app.p2p_node()->get_potential_peers();
239  }
240 
242  {
243  return _app.p2p_node()->get_advanced_node_parameters();
244  }
245 
247  {
248  return _app.p2p_node()->set_advanced_node_parameters(params);
249  }
250 
252  {
253  FC_ASSERT(_network_broadcast_api);
254  return *_network_broadcast_api;
255  }
256 
258  {
259  FC_ASSERT(_block_api);
260  return *_block_api;
261  }
262 
264  {
265  FC_ASSERT(_network_node_api);
266  return *_network_node_api;
267  }
268 
270  {
271  FC_ASSERT(_database_api);
272  return *_database_api;
273  }
274 
276  {
277  FC_ASSERT(_history_api);
278  return *_history_api;
279  }
280 
282  {
283  FC_ASSERT(_crypto_api);
284  return *_crypto_api;
285  }
286 
288  {
289  FC_ASSERT(_asset_api);
290  return *_asset_api;
291  }
292 
294  {
295  FC_ASSERT(_orders_api);
296  return *_orders_api;
297  }
298 
300  {
301  FC_ASSERT(_debug_api);
302  return *_debug_api;
303  }
304 
306  {
307  FC_ASSERT(_custom_operations_api);
308  return *_custom_operations_api;
309  }
310 
311  vector<order_history_object> history_api::get_fill_order_history( std::string asset_a, std::string asset_b,
312  uint32_t limit )const
313  {
314  auto market_hist_plugin = _app.get_plugin<market_history_plugin>( "market_history" );
315  FC_ASSERT( market_hist_plugin, "Market history plugin is not enabled" );
316  FC_ASSERT(_app.chain_database());
317  const auto& db = *_app.chain_database();
318  asset_id_type a = database_api.get_asset_id_from_string( asset_a );
319  asset_id_type b = database_api.get_asset_id_from_string( asset_b );
320  if( a > b ) std::swap(a,b);
321  const auto& history_idx = db.get_index_type<graphene::market_history::history_index>().indices().get<by_key>();
322  history_key hkey;
323  hkey.base = a;
324  hkey.quote = b;
325  hkey.sequence = std::numeric_limits<int64_t>::min();
326 
327  uint32_t count = 0;
328  auto itr = history_idx.lower_bound( hkey );
329  vector<order_history_object> result;
330  while( itr != history_idx.end() && count < limit)
331  {
332  if( itr->key.base != a || itr->key.quote != b ) break;
333  result.push_back( *itr );
334  ++itr;
335  ++count;
336  }
337 
338  return result;
339  }
340 
341  vector<operation_history_object> history_api::get_account_history( const std::string account_id_or_name,
342  operation_history_id_type stop,
343  unsigned limit,
344  operation_history_id_type start ) const
345  {
346  FC_ASSERT( _app.chain_database() );
347  const auto& db = *_app.chain_database();
348 
349  const auto configured_limit = _app.get_options().api_limit_get_account_history;
350  FC_ASSERT( limit <= configured_limit,
351  "limit can not be greater than ${configured_limit}",
352  ("configured_limit", configured_limit) );
353 
354  vector<operation_history_object> result;
355  account_id_type account;
356  try {
357  account = database_api.get_account_id_from_string(account_id_or_name);
358  const account_transaction_history_object& node = account(db).statistics(db).most_recent_op(db);
359  if(start == operation_history_id_type() || start.instance.value > node.operation_id.instance.value)
360  start = node.operation_id;
361  } catch(...) { return result; }
362 
363  if(_app.is_plugin_enabled("elasticsearch")) {
364  auto es = _app.get_plugin<elasticsearch::elasticsearch_plugin>("elasticsearch");
365  if(es.get()->get_running_mode() != elasticsearch::mode::only_save) {
366  if(!_app.elasticsearch_thread)
367  _app.elasticsearch_thread= std::make_shared<fc::thread>("elasticsearch");
368 
369  return _app.elasticsearch_thread->async([&es, &account, &stop, &limit, &start]() {
370  return es->get_account_history(account, stop, limit, start);
371  }, "thread invoke for method " BOOST_PP_STRINGIZE(method_name)).wait();
372  }
373  }
374 
375  const auto& hist_idx = db.get_index_type<account_transaction_history_index>();
376  const auto& by_op_idx = hist_idx.indices().get<by_op>();
377  auto index_start = by_op_idx.begin();
378  auto itr = by_op_idx.lower_bound(boost::make_tuple(account, start));
379 
380  while(itr != index_start && itr->account == account && itr->operation_id.instance.value > stop.instance.value && result.size() < limit)
381  {
382  if(itr->operation_id.instance.value <= start.instance.value)
383  result.push_back(itr->operation_id(db));
384  --itr;
385  }
386  if(stop.instance.value == 0 && result.size() < limit && itr->account == account) {
387  result.push_back(itr->operation_id(db));
388  }
389 
390  return result;
391  }
392 
393  vector<operation_history_object> history_api::get_account_history_operations( const std::string account_id_or_name,
394  int operation_type,
395  operation_history_id_type start,
396  operation_history_id_type stop,
397  unsigned limit ) const
398  {
399  FC_ASSERT( _app.chain_database() );
400  const auto& db = *_app.chain_database();
401 
402  const auto configured_limit = _app.get_options().api_limit_get_account_history_operations;
403  FC_ASSERT( limit <= configured_limit,
404  "limit can not be greater than ${configured_limit}",
405  ("configured_limit", configured_limit) );
406 
407  vector<operation_history_object> result;
408  account_id_type account;
409  try {
410  account = database_api.get_account_id_from_string(account_id_or_name);
411  } catch(...) { return result; }
412  const auto& stats = account(db).statistics(db);
413  if( stats.most_recent_op == account_transaction_history_id_type() ) return result;
414  const account_transaction_history_object* node = &stats.most_recent_op(db);
415  if( start == operation_history_id_type() )
416  start = node->operation_id;
417 
418  while(node && node->operation_id.instance.value > stop.instance.value && result.size() < limit)
419  {
420  if( node->operation_id.instance.value <= start.instance.value ) {
421 
422  if(node->operation_id(db).op.which() == operation_type)
423  result.push_back( node->operation_id(db) );
424  }
425  if( node->next == account_transaction_history_id_type() )
426  node = nullptr;
427  else node = &node->next(db);
428  }
429  if( stop.instance.value == 0 && result.size() < limit ) {
430  auto head = db.find(account_transaction_history_id_type());
431  if (head != nullptr && head->account == account && head->operation_id(db).op.which() == operation_type)
432  result.push_back(head->operation_id(db));
433  }
434  return result;
435  }
436 
437 
438  vector<operation_history_object> history_api::get_relative_account_history( const std::string account_id_or_name,
439  uint64_t stop,
440  unsigned limit,
441  uint64_t start ) const
442  {
443  FC_ASSERT( _app.chain_database() );
444  const auto& db = *_app.chain_database();
445 
446  const auto configured_limit = _app.get_options().api_limit_get_relative_account_history;
447  FC_ASSERT( limit <= configured_limit,
448  "limit can not be greater than ${configured_limit}",
449  ("configured_limit", configured_limit) );
450 
451  vector<operation_history_object> result;
452  account_id_type account;
453  try {
454  account = database_api.get_account_id_from_string(account_id_or_name);
455  } catch(...) { return result; }
456  const auto& stats = account(db).statistics(db);
457  if( start == 0 )
458  start = stats.total_ops;
459  else
460  start = std::min( stats.total_ops, start );
461 
462  if( start >= stop && start > stats.removed_ops && limit > 0 )
463  {
464  const auto& hist_idx = db.get_index_type<account_transaction_history_index>();
465  const auto& by_seq_idx = hist_idx.indices().get<by_seq>();
466 
467  auto itr = by_seq_idx.upper_bound( boost::make_tuple( account, start ) );
468  auto itr_stop = by_seq_idx.lower_bound( boost::make_tuple( account, stop ) );
469 
470  do
471  {
472  --itr;
473  result.push_back( itr->operation_id(db) );
474  }
475  while ( itr != itr_stop && result.size() < limit );
476  }
477  return result;
478  }
479 
480  flat_set<uint32_t> history_api::get_market_history_buckets()const
481  {
482  auto market_hist_plugin = _app.get_plugin<market_history_plugin>( "market_history" );
483  FC_ASSERT( market_hist_plugin, "Market history plugin is not enabled" );
484  return market_hist_plugin->tracked_buckets();
485  }
486 
488  flat_set<uint16_t> operation_types,
489  uint32_t start, unsigned limit )const
490  {
491  const auto configured_limit = _app.get_options().api_limit_get_account_history_by_operations;
492  FC_ASSERT( limit <= configured_limit,
493  "limit can not be greater than ${configured_limit}",
494  ("configured_limit", configured_limit) );
495 
497  vector<operation_history_object> objs = get_relative_account_history( account_id_or_name, start, limit,
498  limit + start - 1 );
499  result.total_count = objs.size();
500 
501  if( operation_types.empty() )
502  result.operation_history_objs = std::move(objs);
503  else
504  {
505  for( const operation_history_object &o : objs )
506  {
507  if( operation_types.find(o.op.which()) != operation_types.end() ) {
508  result.operation_history_objs.push_back(o);
509  }
510  }
511  }
512 
513  return result;
514  }
515 
516  vector<bucket_object> history_api::get_market_history( std::string asset_a, std::string asset_b,
517  uint32_t bucket_seconds,
518  fc::time_point_sec start, fc::time_point_sec end )const
519  { try {
520 
521  auto market_hist_plugin = _app.get_plugin<market_history_plugin>( "market_history" );
522  FC_ASSERT( market_hist_plugin, "Market history plugin is not enabled" );
523  FC_ASSERT(_app.chain_database());
524 
525  const auto& db = *_app.chain_database();
526  asset_id_type a = database_api.get_asset_id_from_string( asset_a );
527  asset_id_type b = database_api.get_asset_id_from_string( asset_b );
528  vector<bucket_object> result;
529  result.reserve(200);
530 
531  if( a > b ) std::swap(a,b);
532 
533  const auto& bidx = db.get_index_type<bucket_index>();
534  const auto& by_key_idx = bidx.indices().get<by_key>();
535 
536  auto itr = by_key_idx.lower_bound( bucket_key( a, b, bucket_seconds, start ) );
537  while( itr != by_key_idx.end() && itr->key.open <= end && result.size() < 200 )
538  {
539  if( !(itr->key.base == a && itr->key.quote == b && itr->key.seconds == bucket_seconds) )
540  {
541  return result;
542  }
543  result.push_back(*itr);
544  ++itr;
545  }
546  return result;
547  } FC_CAPTURE_AND_RETHROW( (asset_a)(asset_b)(bucket_seconds)(start)(end) ) }
548 
550 
552  {
553  return fc::ecc::blind( blind, value );
554  }
555 
556  blind_factor_type crypto_api::blind_sum( const std::vector<blind_factor_type>& blinds_in, uint32_t non_neg )
557  {
558  return fc::ecc::blind_sum( blinds_in, non_neg );
559  }
560 
561  bool crypto_api::verify_sum( const std::vector<commitment_type>& commits_in, const std::vector<commitment_type>& neg_commits_in, int64_t excess )
562  {
563  return fc::ecc::verify_sum( commits_in, neg_commits_in, excess );
564  }
565 
566  verify_range_result crypto_api::verify_range( const commitment_type& commit, const std::vector<char>& proof )
567  {
568  verify_range_result result;
569  result.success = fc::ecc::verify_range( result.min_val, result.max_val, commit, proof );
570  return result;
571  }
572 
573  std::vector<char> crypto_api::range_proof_sign( uint64_t min_value,
574  const commitment_type& commit,
575  const blind_factor_type& commit_blind,
576  const blind_factor_type& nonce,
577  int8_t base10_exp,
578  uint8_t min_bits,
579  uint64_t actual_value )
580  {
581  return fc::ecc::range_proof_sign( min_value, commit, commit_blind, nonce, base10_exp, min_bits, actual_value );
582  }
583 
585  const commitment_type& commit,
586  const std::vector<char>& proof )
587  {
590  result.value_out,
591  result.message_out,
592  nonce,
593  result.min_val,
594  result.max_val,
595  const_cast< commitment_type& >( commit ),
596  proof );
597  return result;
598  }
599 
600  range_proof_info crypto_api::range_get_info( const std::vector<char>& proof )
601  {
602  return fc::ecc::range_get_info( proof );
603  }
604 
605  // asset_api
607  _app(app),
608  _db( *app.chain_database()),
609  database_api( std::ref(*app.chain_database()), &(app.get_options())
610  ) { }
612 
613  vector<account_asset_balance> asset_api::get_asset_holders( std::string asset, uint32_t start, uint32_t limit ) const
614  {
615  const auto configured_limit = _app.get_options().api_limit_get_asset_holders;
616  FC_ASSERT( limit <= configured_limit,
617  "limit can not be greater than ${configured_limit}",
618  ("configured_limit", configured_limit) );
619 
620  asset_id_type asset_id = database_api.get_asset_id_from_string( asset );
621  const auto& bal_idx = _db.get_index_type< account_balance_index >().indices().get< by_asset_balance >();
622  auto range = bal_idx.equal_range( boost::make_tuple( asset_id ) );
623 
624  vector<account_asset_balance> result;
625 
626  uint32_t index = 0;
627  for( const account_balance_object& bal : boost::make_iterator_range( range.first, range.second ) )
628  {
629  if( result.size() >= limit )
630  break;
631 
632  if( bal.balance.value == 0 )
633  continue;
634 
635  if( index++ < start )
636  continue;
637 
638  const auto account = _db.find(bal.owner);
639 
641  aab.name = account->name;
642  aab.account_id = account->id;
643  aab.amount = bal.balance.value;
644 
645  result.push_back(aab);
646  }
647 
648  return result;
649  }
650  // get number of asset holders.
651  int asset_api::get_asset_holders_count( std::string asset ) const {
652  const auto& bal_idx = _db.get_index_type< account_balance_index >().indices().get< by_asset_balance >();
653  asset_id_type asset_id = database_api.get_asset_id_from_string( asset );
654  auto range = bal_idx.equal_range( boost::make_tuple( asset_id ) );
655 
656  int count = boost::distance(range) - 1;
657 
658  return count;
659  }
660  // function to get vector of system assets with holders count.
661  vector<asset_holders> asset_api::get_all_asset_holders() const {
662  vector<asset_holders> result;
663  vector<asset_id_type> total_assets;
664  for( const asset_object& asset_obj : _db.get_index_type<asset_index>().indices() )
665  {
666  const auto& dasset_obj = asset_obj.dynamic_asset_data_id(_db);
667 
668  asset_id_type asset_id;
669  asset_id = dasset_obj.id;
670 
671  const auto& bal_idx = _db.get_index_type< account_balance_index >().indices().get< by_asset_balance >();
672  auto range = bal_idx.equal_range( boost::make_tuple( asset_id ) );
673 
674  int count = boost::distance(range) - 1;
675 
676  asset_holders ah;
677  ah.asset_id = asset_id;
678  ah.count = count;
679 
680  result.push_back(ah);
681  }
682 
683  return result;
684  }
685 
686  // orders_api
687  flat_set<uint16_t> orders_api::get_tracked_groups()const
688  {
689  auto plugin = _app.get_plugin<grouped_orders_plugin>( "grouped_orders" );
690  FC_ASSERT( plugin );
691  return plugin->tracked_groups();
692  }
693 
694  vector< limit_order_group > orders_api::get_grouped_limit_orders( std::string base_asset,
695  std::string quote_asset,
696  uint16_t group,
697  optional<price> start,
698  uint32_t limit )const
699  {
700  const auto configured_limit = _app.get_options().api_limit_get_grouped_limit_orders;
701  FC_ASSERT( limit <= configured_limit,
702  "limit can not be greater than ${configured_limit}",
703  ("configured_limit", configured_limit) );
704 
705  auto plugin = _app.get_plugin<graphene::grouped_orders::grouped_orders_plugin>( "grouped_orders" );
706  FC_ASSERT( plugin );
707  const auto& limit_groups = plugin->limit_order_groups();
708  vector< limit_order_group > result;
709 
710  asset_id_type base_asset_id = database_api.get_asset_id_from_string( base_asset );
711  asset_id_type quote_asset_id = database_api.get_asset_id_from_string( quote_asset );
712 
713  price max_price = price::max( base_asset_id, quote_asset_id );
714  price min_price = price::min( base_asset_id, quote_asset_id );
715  if( start.valid() && !start->is_null() )
716  max_price = std::max( std::min( max_price, *start ), min_price );
717 
718  auto itr = limit_groups.lower_bound( limit_order_group_key( group, max_price ) );
719  // use an end iterator to try to avoid expensive price comparison
720  auto end = limit_groups.upper_bound( limit_order_group_key( group, min_price ) );
721  while( itr != end && result.size() < limit )
722  {
723  result.emplace_back( *itr );
724  ++itr;
725  }
726  return result;
727  }
728 
729  // custom operations api
730  vector<account_storage_object> custom_operations_api::get_storage_info(std::string account_id_or_name,
731  std::string catalog)const
732  {
734  FC_ASSERT( plugin );
735 
736  const auto account_id = database_api.get_account_id_from_string(account_id_or_name);
737  vector<account_storage_object> results;
738  const auto& storage_index = _app.chain_database()->get_index_type<account_storage_index>();
739  const auto& by_account_catalog_idx = storage_index.indices().get<by_account_catalog_key>();
740  auto range = by_account_catalog_idx.equal_range(make_tuple(account_id, catalog));
741  for( const account_storage_object& aso : boost::make_iterator_range( range.first, range.second ) )
742  results.push_back(aso);
743  return results;
744  }
745 
746 } } // graphene::app
asset_id_type asset_id
Definition: api.hpp:91
fc::optional< api_access_info > get_api_access_info(const string &username) const
Tracks the balance of a single account/asset pairThis object is indexed on owner and asset_type so th...
std::shared_ptr< fc::thread > elasticsearch_thread
vector< optional< signed_block > > get_blocks(uint32_t block_num_from, uint32_t block_num_to) const
Get signed blocks.
Definition: api.cpp:141
fc::api< graphene::debug_witness::debug_api > debug() const
Retrieve the debug API (if available)
Definition: api.cpp:299
fc::variant broadcast_transaction_synchronous(const precomputable_transaction &trx)
Definition: api.cpp:188
auto async(Functor &&f, const char *desc FC_TASK_NAME_DEFAULT_ARG, priority prio=priority()) -> fc::future< decltype(f())>
Definition: thread.hpp:227
history_operation_detail get_account_history_by_operations(const std::string account_id_or_name, flat_set< uint16_t > operation_types, uint32_t start, unsigned limit) const
Get operations relevant to the specified account filtering by operation type.
Definition: api.cpp:487
static ptr create(const char *desc FC_TASK_NAME_DEFAULT_ARG)
Definition: future.hpp:114
a placeholder for the result of an asynchronous operation.
Definition: future.hpp:211
virtual void open(const fc::path &db)=0
void broadcast_transaction_with_callback(confirmation_callback cb, const precomputable_transaction &trx)
Definition: api.cpp:206
const T * find(object_id_type id) const
bool verify_range(uint64_t &min_val, uint64_t &max_val, const commitment_type &commit, const range_proof_type &proof)
fc::api< database_api > database() const
Retrieve the database API.
Definition: api.cpp:269
vector< operation_history_object > get_relative_account_history(const std::string account_id_or_name, uint64_t stop=0, unsigned limit=100, uint64_t start=0) const
Get operations relevant to the specified account referenced by an event numbering specific to the acc...
Definition: api.cpp:438
void on_applied_block(const signed_block &b)
Not reflected, thus not accessible to API clients.
Definition: api.cpp:156
static constexpr size_t data_size()
Definition: sha256.hpp:21
T wait(boost::signals2::signal< void(T)> &sig, const microseconds &timeout_us=microseconds::maximum())
Definition: signals.hpp:38
bool verify_sum(const std::vector< commitment_type > &commits, const std::vector< commitment_type > &neg_commits, int64_t excess)
#define GRAPHENE_MAX_NESTED_OBJECTS
Definition: config.hpp:31
tracks the history of all logical operations on blockchain stateAll operations and virtual operations...
flat_set< uint16_t > get_tracked_groups() const
Get tracked groups configured by the server.
Definition: api.cpp:687
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)
vector< account_storage_object > get_storage_info(std::string account_id_or_name, std::string catalog) const
Get all stored objects of an account in a particular catalog.
Definition: api.cpp:730
std::vector< char > 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)
Proves with respect to min_value the range for pedersen commitment which has the provided blinding fa...
Definition: api.cpp:573
void set_advanced_node_parameters(const fc::variant_object &params)
Set advanced node parameters, such as desired and max number of connections.
Definition: api.cpp:246
fc::api< crypto_api > crypto() const
Retrieve the cryptography API.
Definition: api.cpp:281
a node in a linked list of operation_history_objectsAccount history is important for users and wallet...
bool login(const string &user, const string &password)
Authenticate to the RPC server.
Definition: api.cpp:67
fc::api< history_api > history() const
Retrieve the history API.
Definition: api.cpp:275
bool valid() const
Definition: optional.hpp:186
block_api(graphene::chain::database &db)
Definition: api.cpp:138
fc::api< network_broadcast_api > network_broadcast() const
Retrieve the network broadcast API.
Definition: api.cpp:251
void enable_api(const string &api_name)
Called to enable an API, not reflected.
Definition: api.cpp:89
asset_id_type get_asset_id_from_string(const std::string &symbol_or_id) const
Get asset ID from an asset symbol or ID.
std::vector< net::potential_peer_record > get_potential_peers() const
Return list of potential peers.
Definition: api.cpp:236
fc::api< block_api > block() const
Retrieve the network block API.
Definition: api.cpp:257
bool is_plugin_enabled(const string &name) const
fc::api< network_node_api > network_node() const
Retrieve the network node API.
Definition: api.cpp:263
network_node_api(application &a)
Definition: api.cpp:215
vector< operation_history_object > get_account_history_operations(const std::string account_id_or_name, int operation_type, operation_history_id_type start=operation_history_id_type(), operation_history_id_type stop=operation_history_id_type(), unsigned limit=100) const
Get only asked operations relevant to the specified account.
Definition: api.cpp:393
fc::ecc::commitment_type blind(const fc::ecc::blind_factor_type &blind, uint64_t value)
Generates a pedersen commitment: *commit = blind * G + value * G2. The commitment is 33 bytes...
Definition: api.cpp:551
price min() const
Definition: asset.hpp:131
optional< signed_block > fetch_block_by_number(uint32_t num) const
Definition: db_block.cpp:75
int get_asset_holders_count(std::string asset) const
Get asset holders count for a specific asset.
Definition: api.cpp:651
static sha256 hash(const char *d, uint32_t dlen)
Definition: sha256.cpp:41
provides stack-based nullable value similar to boost::optional
Definition: optional.hpp:20
void broadcast_transaction(const precomputable_transaction &trx)
Broadcast a transaction to the network.
Definition: api.cpp:180
commitment_type blind(const blind_factor_type &blind, uint64_t value)
fc::api< orders_api > orders() const
Retrieve the orders API.
Definition: api.cpp:293
asset_api(graphene::app::application &app)
Definition: api.cpp:606
char * data() const
Definition: sha256.cpp:29
std::shared_ptr< abstract_plugin > get_plugin(const string &name) const
vector< operation_history_object > operation_history_objs
Definition: api.hpp:97
void add_node(const fc::ip::endpoint &ep)
add_node Connect to a new peer
Definition: api.cpp:226
bool verify_sum(const std::vector< commitment_type > &commits_in, const std::vector< commitment_type > &neg_commits_in, int64_t excess)
Verifies that commits + neg_commits + excess == 0.
Definition: api.cpp:561
range_proof_info range_get_info(const std::vector< char > &proof)
Gets "range proof" info. The cli_wallet includes functionality for sending blind transfers in which t...
Definition: api.cpp:600
void set_value(const T &v)
Definition: future.hpp:136
account_id_type get_account_id_from_string(const std::string &name_or_id) const
Get account object from a name or ID.
verify_range_result verify_range(const fc::ecc::commitment_type &commit, const std::vector< char > &proof)
Verifies range proof for 33-byte pedersen commitment.
Definition: api.cpp:566
fc::variant_object get_info() const
Return general network information, such as p2p port.
Definition: api.cpp:219
void broadcast_block(const signed_block &block)
Broadcast a signed block to the network.
Definition: api.cpp:198
#define FC_CAPTURE_AND_RETHROW(...)
Definition: exception.hpp:478
flat_set< uint32_t > get_market_history_buckets() const
Get OHLCV time bucket lengths supported (configured) by this API server.
Definition: api.cpp:480
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
Definition: exception.hpp:345
vector< asset_holders > get_all_asset_holders() const
Get all asset holders.
Definition: api.cpp:661
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
vector< limit_order_group > get_grouped_limit_orders(std::string base_asset, std::string quote_asset, uint16_t group, optional< price > start, uint32_t limit) const
Get grouped limit orders in given market.
Definition: api.cpp:694
vector< bucket_object > get_market_history(std::string a, std::string b, uint32_t bucket_seconds, fc::time_point_sec start, fc::time_point_sec end) const
Get OHLCV data of a trading pair in a time range.
Definition: api.cpp:516
std::function< void(variant)> confirmation_callback
Definition: api.hpp:266
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)
vector< account_asset_balance > get_asset_holders(std::string asset, uint32_t start, uint32_t limit) const
Get asset holders for a specific asset.
Definition: api.cpp:613
fc::ecc::blind_factor_type blind_sum(const std::vector< blind_factor_type > &blinds_in, uint32_t non_neg)
Get sha-256 blind factor type.
Definition: api.cpp:556
verify_range_proof_rewind_result verify_range_proof_rewind(const blind_factor_type &nonce, const fc::ecc::commitment_type &commit, const std::vector< char > &proof)
Verifies range proof rewind for 33-byte pedersen commitment.
Definition: api.cpp:584
fc::api< asset_api > asset() const
Retrieve the asset API.
Definition: api.cpp:287
tracks the parameters of an assetAll assets have a globally unique symbol name that controls how they...
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)
const application_options & get_options()
std::vector< net::peer_status > get_connected_peers() const
Get status of all current connections to peers.
Definition: api.cpp:231
blind_factor_type blind_sum(const std::vector< blind_factor_type > &blinds, uint32_t non_neg)
const object & get(object_id_type id) const
Definition: index.hpp:111
std::string base64_decode(const std::string &encoded_string)
Definition: base64.cpp:96
account_transaction_history_id_type next
the operation position within the given account
abstract base class for accessing objects indexed in various ways.
Definition: index.hpp:71
std::shared_ptr< chain::database > chain_database() const
vector< operation_history_object > get_account_history(const std::string account_id_or_name, operation_history_id_type stop=operation_history_id_type(), unsigned limit=100, operation_history_id_type start=operation_history_id_type()) const
Get operations relevant to the specificed account.
Definition: api.cpp:341
vector< order_history_object > get_fill_order_history(std::string a, std::string b, uint32_t limit) const
Get details of order executions occurred most recently in a trading pair.
Definition: api.cpp:311
fc::ecc::blind_factor_type blind_out
Definition: api.hpp:79
std::shared_ptr< promise< T > > ptr
Definition: future.hpp:111
price max() const
Definition: asset.hpp:130
fc::variant_object get_advanced_node_parameters() const
Get advanced node parameters, such as desired and max number of connections.
Definition: api.cpp:241
An order-perserving dictionary of variant&#39;s.
const IndexType & get_index_type() const
operation_history_id_type operation_id
the account this operation applies to
T value
Definition: safe.hpp:22
fc::api< custom_operations_api > custom_operations() const
Retrieve the custom operations API.
Definition: api.cpp:305
const index_type & indices() const
Definition: api.hpp:120
network_broadcast_api(application &a)
Definition: api.cpp:151