Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::chain_apis::read_only Class Reference

#include <chain_plugin.hpp>

Classes

struct  abi_bin_to_json_params
 
struct  abi_bin_to_json_result
 
struct  abi_json_to_bin_params
 
struct  abi_json_to_bin_result
 
struct  compute_transaction_params
 
struct  compute_transaction_results
 
struct  get_abi_params
 
struct  get_abi_results
 
struct  get_account_params
 
struct  get_account_results
 
struct  get_activated_protocol_features_params
 
struct  get_activated_protocol_features_results
 
struct  get_block_header_state_params
 
struct  get_block_info_params
 
struct  get_block_params
 
struct  get_code_hash_params
 
struct  get_code_hash_results
 
struct  get_code_params
 
struct  get_code_results
 
struct  get_currency_balance_params
 
struct  get_currency_stats_params
 
struct  get_currency_stats_result
 
struct  get_info_results
 
struct  get_producer_schedule_params
 
struct  get_producer_schedule_result
 
struct  get_producers_params
 
struct  get_producers_result
 
struct  get_raw_abi_params
 
struct  get_raw_abi_results
 
struct  get_raw_code_and_abi_params
 
struct  get_raw_code_and_abi_results
 
struct  get_required_keys_params
 
struct  get_required_keys_result
 
struct  get_scheduled_transactions_params
 
struct  get_scheduled_transactions_result
 
struct  get_table_by_scope_params
 
struct  get_table_by_scope_result
 
struct  get_table_by_scope_result_row
 
struct  get_table_rows_params
 
struct  get_table_rows_result
 
struct  get_transaction_status_params
 
struct  get_transaction_status_results
 
struct  producer_info
 

Public Types

using get_info_params = empty
 
using account_resource_limit = chain::resource_limits::account_resource_limit
 
using get_transaction_id_params = transaction
 
using get_transaction_id_result = transaction_id_type
 
using get_accounts_by_authorizers_result = account_query_db::get_accounts_by_authorizers_result
 
using get_accounts_by_authorizers_params = account_query_db::get_accounts_by_authorizers_params
 

Public Member Functions

 read_only (const controller &db, const std::optional< account_query_db > &aqdb, const fc::microseconds &abi_serializer_max_time, const producer_plugin *producer_plug, const trx_finality_status_processing *trx_finality_status_proc)
 
void validate () const
 
void set_shorten_abi_errors (bool f)
 
get_info_results get_info (const get_info_params &) const
 
get_transaction_status_results get_transaction_status (const get_transaction_status_params &params) const
 
get_activated_protocol_features_results get_activated_protocol_features (const get_activated_protocol_features_params &params) const
 
get_account_results get_account (const get_account_params &params) const
 
get_code_results get_code (const get_code_params &params) const
 
get_code_hash_results get_code_hash (const get_code_hash_params &params) const
 
get_abi_results get_abi (const get_abi_params &params) const
 
get_raw_code_and_abi_results get_raw_code_and_abi (const get_raw_code_and_abi_params &params) const
 
get_raw_abi_results get_raw_abi (const get_raw_abi_params &params) const
 
abi_json_to_bin_result abi_json_to_bin (const abi_json_to_bin_params &params) const
 
abi_bin_to_json_result abi_bin_to_json (const abi_bin_to_json_params &params) const
 
get_required_keys_result get_required_keys (const get_required_keys_params &params) const
 
get_transaction_id_result get_transaction_id (const get_transaction_id_params &params) const
 
fc::variant get_block (const get_block_params &params) const
 
fc::variant get_block_info (const get_block_info_params &params) const
 
fc::variant get_block_header_state (const get_block_header_state_params &params) const
 
get_table_rows_result get_table_rows (const get_table_rows_params &params) const
 
get_table_by_scope_result get_table_by_scope (const get_table_by_scope_params &params) const
 
vector< assetget_currency_balance (const get_currency_balance_params &params) const
 
fc::variant get_currency_stats (const get_currency_stats_params &params) const
 
get_producers_result get_producers (const get_producers_params &params) const
 
get_producer_schedule_result get_producer_schedule (const get_producer_schedule_params &params) const
 
get_scheduled_transactions_result get_scheduled_transactions (const get_scheduled_transactions_params &params) const
 
void compute_transaction (const compute_transaction_params &params, chain::plugin_interface::next_function< compute_transaction_results > next) const
 
template<typename Function >
void walk_key_value_table (const name &code, const name &scope, const name &table, Function f) const
 
template<typename IndexType , typename SecKeyType , typename ConvFn >
read_only::get_table_rows_result get_table_rows_by_seckey (const read_only::get_table_rows_params &p, const abi_def &abi, ConvFn conv) const
 
template<typename IndexType >
read_only::get_table_rows_result get_table_rows_ex (const read_only::get_table_rows_params &p, const abi_def &abi) const
 
get_accounts_by_authorizers_result get_accounts_by_authorizers (const get_accounts_by_authorizers_params &args) const
 
chain::symbol extract_core_symbol () const
 

Static Public Member Functions

static void copy_inline_row (const chain::key_value_object &obj, vector< char > &data)
 
static uint64_t get_table_index_name (const read_only::get_table_rows_params &p, bool &primary)
 

Static Public Attributes

static const string KEYi64 = "i64"
 

Detailed Description

Definition at line 88 of file chain_plugin.hpp.

Member Typedef Documentation

◆ account_resource_limit

◆ get_accounts_by_authorizers_params

◆ get_accounts_by_authorizers_result

◆ get_info_params

◆ get_transaction_id_params

◆ get_transaction_id_result

Constructor & Destructor Documentation

◆ read_only()

sysio::chain_apis::read_only::read_only ( const controller & db,
const std::optional< account_query_db > & aqdb,
const fc::microseconds & abi_serializer_max_time,
const producer_plugin * producer_plug,
const trx_finality_status_processing * trx_finality_status_proc )
inline

Definition at line 99 of file chain_plugin.hpp.

100 : db(db), aqdb(aqdb), abi_serializer_max_time(abi_serializer_max_time), producer_plug(producer_plug), trx_finality_status_proc(trx_finality_status_proc) {
101 }
const fc::microseconds abi_serializer_max_time
Definition main.cpp:173

Member Function Documentation

◆ abi_bin_to_json()

abi_bin_to_json_result sysio::chain_apis::read_only::abi_bin_to_json ( const abi_bin_to_json_params & params) const

◆ abi_json_to_bin()

read_only::abi_json_to_bin_result sysio::chain_apis::read_only::abi_json_to_bin ( const abi_json_to_bin_params & params) const

Definition at line 2601 of file chain_plugin.cpp.

2601 {
2602 abi_json_to_bin_result result;
2603 const auto code_account = db.db().find<account_object,by_name>( params.code );
2604 SYS_ASSERT(code_account != nullptr, contract_query_exception, "Contract can't be found ${contract}", ("contract", params.code));
2605
2606 abi_def abi;
2607 if( abi_serializer::to_abi(code_account->abi, abi) ) {
2608 abi_serializer abis( abi, abi_serializer::create_yield_function( abi_serializer_max_time ) );
2609 auto action_type = abis.get_action_type(params.action);
2610 SYS_ASSERT(!action_type.empty(), action_validate_exception, "Unknown action ${action} in contract ${contract}", ("action", params.action)("contract", params.code));
2611 try {
2612 result.binargs = abis.variant_to_binary( action_type, params.args, abi_serializer::create_yield_function( abi_serializer_max_time ), shorten_abi_errors );
2613 } SYS_RETHROW_EXCEPTIONS(chain::invalid_action_args_exception,
2614 "'${args}' is invalid args for action '${action}' code '${code}'. expected '${proto}'",
2615 ("args", params.args)("action", params.action)("code", params.code)("proto", action_abi_to_variant(abi, action_type)))
2616 } else {
2617 SYS_ASSERT(false, abi_not_found_exception, "No ABI found for ${contract}", ("contract", params.code));
2618 }
2619 return result;
2620} FC_RETHROW_EXCEPTIONS( warn, "code: ${code}, action: ${action}, args: ${args}",
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
#define SYS_RETHROW_EXCEPTIONS(exception_type, FORMAT,...)
const ObjectType * find(CompatibleKey &&key) const
const chainbase::database & db() const
#define FC_RETHROW_EXCEPTIONS(LOG_LEVEL, FORMAT,...)
Catchs all exception's, std::exceptions, and ... and rethrows them after appending the provided log m...
key Invalid authority Invalid transaction Invalid block ID Invalid packed transaction Invalid chain ID Invalid symbol Signature type is not a currently activated type Block can not be found Unlinkable block Block does not guarantee concurrent execution without conflicts Block exhausted allowed resources Block is from the future Block is not signed by expected producer Block includes an ill formed protocol feature activation extension Block includes an ill formed additional block signature extension Error decompressing transaction Transaction should have at least one required authority Expired Transaction Invalid Reference Block Duplicate deferred transaction The transaction can not be found Transaction is too big Invalid transaction extension Transaction includes disallowed Transaction exceeded transient resource limit action_validate_exception
static yield_function_t create_yield_function(const fc::microseconds &max_serialization_time)
static bool to_abi(const Vec &abi_vec, abi_def &abi)
account_query_db::get_accounts_by_authorizers_params params
Here is the call graph for this function:

◆ compute_transaction()

void sysio::chain_apis::read_only::compute_transaction ( const compute_transaction_params & params,
chain::plugin_interface::next_function< compute_transaction_results > next ) const

◆ copy_inline_row()

static void sysio::chain_apis::read_only::copy_inline_row ( const chain::key_value_object & obj,
vector< char > & data )
inlinestatic

Definition at line 453 of file chain_plugin.hpp.

453 {
454 data.resize( obj.value.size() );
455 memcpy( data.data(), obj.value.data(), obj.value.size() );
456 }
memcpy((char *) pInfo->slotDescription, s, l)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_core_symbol()

chain::symbol sysio::chain_apis::read_only::extract_core_symbol ( ) const

◆ get_abi()

read_only::get_abi_results sysio::chain_apis::read_only::get_abi ( const get_abi_params & params) const

Definition at line 2348 of file chain_plugin.cpp.

2348 {
2349 get_abi_results result;
2350 result.account_name = params.account_name;
2351 const auto& d = db.db();
2352 const auto& accnt = d.get<account_object,by_name>( params.account_name );
2353
2354 abi_def abi;
2355 if( abi_serializer::to_abi(accnt.abi, abi) ) {
2356 result.abi = std::move(abi);
2357 }
2358
2359 return result;
2360}
CK_ULONG d
Here is the call graph for this function:

◆ get_account()

read_only::get_account_results sysio::chain_apis::read_only::get_account ( const get_account_params & params) const

TODO: lookup perm->parent name

Definition at line 2429 of file chain_plugin.cpp.

2429 {
2430 get_account_results result;
2431 result.account_name = params.account_name;
2432
2433 const auto& d = db.db();
2434 const auto& rm = db.get_resource_limits_manager();
2435
2436 result.head_block_num = db.head_block_num();
2437 result.head_block_time = db.head_block_time();
2438
2439 rm.get_account_limits( result.account_name, result.ram_quota, result.net_weight, result.cpu_weight );
2440
2441 const auto& accnt_obj = db.get_account( result.account_name );
2442 const auto& accnt_metadata_obj = db.db().get<account_metadata_object,by_name>( result.account_name );
2443
2444 result.privileged = accnt_metadata_obj.is_privileged();
2445 result.last_code_update = accnt_metadata_obj.last_code_update;
2446 result.created = accnt_obj.creation_date;
2447
2448 uint32_t greylist_limit = db.is_resource_greylisted(result.account_name) ? 1 : config::maximum_elastic_resource_multiplier;
2449 result.net_limit = rm.get_account_net_limit_ex( result.account_name, greylist_limit).first;
2450 result.cpu_limit = rm.get_account_cpu_limit_ex( result.account_name, greylist_limit).first;
2451 result.ram_usage = rm.get_account_ram_usage( result.account_name );
2452
2453 if ( producer_plug ) { // producer_plug is null when called from chain_plugin_tests.cpp and get_table_tests.cpp
2454 account_resource_limit subjective_cpu_bill_limit;
2455 subjective_cpu_bill_limit.used = producer_plug->get_subjective_bill( result.account_name, fc::time_point::now() );
2456 result.subjective_cpu_bill_limit = subjective_cpu_bill_limit;
2457 }
2458
2459 const auto linked_action_map = ([&](){
2460 const auto& links = d.get_index<permission_link_index,by_permission_name>();
2461 auto iter = links.lower_bound( boost::make_tuple( params.account_name ) );
2462
2463 std::multimap<name, linked_action> result;
2464 while (iter != links.end() && iter->account == params.account_name ) {
2465 auto action = iter->message_type.empty() ? std::optional<name>() : std::optional<name>(iter->message_type);
2466 result.emplace(std::make_pair(iter->required_permission, linked_action{iter->code, std::move(action)}));
2467 ++iter;
2468 }
2469
2470 return result;
2471 })();
2472
2473 auto get_linked_actions = [&](chain::name perm_name) {
2474 auto link_bounds = linked_action_map.equal_range(perm_name);
2475 auto linked_actions = std::vector<linked_action>();
2476 linked_actions.reserve(linked_action_map.count(perm_name));
2477 for (auto link = link_bounds.first; link != link_bounds.second; ++link) {
2478 linked_actions.push_back(link->second);
2479 }
2480 return linked_actions;
2481 };
2482
2483 const auto& permissions = d.get_index<permission_index,by_owner>();
2484 auto perm = permissions.lower_bound( boost::make_tuple( params.account_name ) );
2485 while( perm != permissions.end() && perm->owner == params.account_name ) {
2487 name parent;
2488
2489 // Don't lookup parent if null
2490 if( perm->parent._id ) {
2491 const auto* p = d.find<permission_object,by_id>( perm->parent );
2492 if( p ) {
2493 SYS_ASSERT(perm->owner == p->owner, invalid_parent_permission, "Invalid parent permission");
2494 parent = p->name;
2495 }
2496 }
2497
2498 auto linked_actions = get_linked_actions(perm->name);
2499
2500 result.permissions.push_back( permission{ perm->name, parent, perm->auth.to_authority(), std::move(linked_actions)} );
2501 ++perm;
2502 }
2503
2504 // add sysio.any linked authorizations
2505 result.sysio_any_linked_actions = get_linked_actions(chain::config::sysio_any_name);
2506
2507 const auto& code_account = db.db().get<account_object,by_name>( config::system_account_name );
2508
2509 abi_def abi;
2510 if( abi_serializer::to_abi(code_account.abi, abi) ) {
2511 abi_serializer abis( abi, abi_serializer::create_yield_function( abi_serializer_max_time ) );
2512
2513 const auto token_code = "sysio.token"_n;
2514
2515 auto core_symbol = extract_core_symbol();
2516
2517 if (params.expected_core_symbol)
2518 core_symbol = *(params.expected_core_symbol);
2519
2520 const auto* t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( token_code, params.account_name, "accounts"_n ));
2521 if( t_id != nullptr ) {
2522 const auto &idx = d.get_index<key_value_index, by_scope_primary>();
2523 auto it = idx.find(boost::make_tuple( t_id->id, core_symbol.to_symbol_code() ));
2524 if( it != idx.end() && it->value.size() >= sizeof(asset) ) {
2525 asset bal;
2526 fc::datastream<const char *> ds(it->value.data(), it->value.size());
2527 fc::raw::unpack(ds, bal);
2528
2529 if( bal.get_symbol().valid() && bal.get_symbol() == core_symbol ) {
2530 result.core_liquid_balance = bal;
2531 }
2532 }
2533 }
2534
2535 t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( config::system_account_name, params.account_name, "userres"_n ));
2536 if (t_id != nullptr) {
2537 const auto &idx = d.get_index<key_value_index, by_scope_primary>();
2538 auto it = idx.find(boost::make_tuple( t_id->id, params.account_name.to_uint64_t() ));
2539 if ( it != idx.end() ) {
2540 vector<char> data;
2541 copy_inline_row(*it, data);
2542 result.total_resources = abis.binary_to_variant( "user_resources", data, abi_serializer::create_yield_function( abi_serializer_max_time ), shorten_abi_errors );
2543 }
2544 }
2545
2546 t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( config::system_account_name, params.account_name, "delband"_n ));
2547 if (t_id != nullptr) {
2548 const auto &idx = d.get_index<key_value_index, by_scope_primary>();
2549 auto it = idx.find(boost::make_tuple( t_id->id, params.account_name.to_uint64_t() ));
2550 if ( it != idx.end() ) {
2551 vector<char> data;
2552 copy_inline_row(*it, data);
2553 result.self_delegated_bandwidth = abis.binary_to_variant( "delegated_bandwidth", data, abi_serializer::create_yield_function( abi_serializer_max_time ), shorten_abi_errors );
2554 }
2555 }
2556
2557 t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( config::system_account_name, params.account_name, "refunds"_n ));
2558 if (t_id != nullptr) {
2559 const auto &idx = d.get_index<key_value_index, by_scope_primary>();
2560 auto it = idx.find(boost::make_tuple( t_id->id, params.account_name.to_uint64_t() ));
2561 if ( it != idx.end() ) {
2562 vector<char> data;
2563 copy_inline_row(*it, data);
2564 result.refund_request = abis.binary_to_variant( "refund_request", data, abi_serializer::create_yield_function( abi_serializer_max_time ), shorten_abi_errors );
2565 }
2566 }
2567
2568 t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( config::system_account_name, config::system_account_name, "voters"_n ));
2569 if (t_id != nullptr) {
2570 const auto &idx = d.get_index<key_value_index, by_scope_primary>();
2571 auto it = idx.find(boost::make_tuple( t_id->id, params.account_name.to_uint64_t() ));
2572 if ( it != idx.end() ) {
2573 vector<char> data;
2574 copy_inline_row(*it, data);
2575 result.voter_info = abis.binary_to_variant( "voter_info", data, abi_serializer::create_yield_function( abi_serializer_max_time ), shorten_abi_errors );
2576 }
2577 }
2578
2579 t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple( config::system_account_name, config::system_account_name, "rexbal"_n ));
2580 if (t_id != nullptr) {
2581 const auto &idx = d.get_index<key_value_index, by_scope_primary>();
2582 auto it = idx.find(boost::make_tuple( t_id->id, params.account_name.to_uint64_t() ));
2583 if( it != idx.end() ) {
2584 vector<char> data;
2585 copy_inline_row(*it, data);
2586 result.rex_info = abis.binary_to_variant( "rex_balance", data, abi_serializer::create_yield_function( abi_serializer_max_time ), shorten_abi_errors );
2587 }
2588 }
2589 }
2590 return result;
2591}
const mie::Vuint & p
Definition bn.cpp:27
std::string name
const ObjectType & get(CompatibleKey &&key) const
static time_point now()
Definition time.cpp:14
uint32_t head_block_num() const
bool is_resource_greylisted(const account_name &name) const
const account_object & get_account(account_name n) const
time_point head_block_time() const
const resource_limits_manager & get_resource_limits_manager() const
controller_impl
static void copy_inline_row(const chain::key_value_object &obj, vector< char > &data)
chain::resource_limits::account_resource_limit account_resource_limit
chain::symbol extract_core_symbol() const
int64_t get_subjective_bill(const account_name &first_auth, const fc::time_point &now) const
static const Segment ds(Segment::ds)
void unpack(Stream &s, std::deque< T > &value)
Definition raw.hpp:540
Definition name.hpp:106
chainbase::shared_multi_index_container< permission_link_object, indexed_by< ordered_unique< tag< by_id >, >, ordered_unique< tag< by_action_name >, composite_key< permission_link_object, BOOST_MULTI_INDEX_MEMBER(permission_link_object, account_name, account), BOOST_MULTI_INDEX_MEMBER(permission_link_object, account_name, code), > >, ordered_unique< tag< by_permission_name >, composite_key< permission_link_object, BOOST_MULTI_INDEX_MEMBER(permission_link_object, account_name, account), BOOST_MULTI_INDEX_MEMBER(permission_link_object, permission_name, required_permission), > > > > permission_link_index
chainbase::shared_multi_index_container< permission_object, indexed_by< ordered_unique< tag< by_id >, member< permission_object, permission_object::id_type, &permission_object::id > >, ordered_unique< tag< by_parent >, composite_key< permission_object, member< permission_object, permission_object::id_type, &permission_object::parent >, member< permission_object, permission_object::id_type, &permission_object::id > > >, ordered_unique< tag< by_owner >, composite_key< permission_object, member< permission_object, account_name, &permission_object::owner >, member< permission_object, permission_name, &permission_object::name > > >, ordered_unique< tag< by_name >, composite_key< permission_object, member< permission_object, permission_name, &permission_object::name >, member< permission_object, permission_object::id_type, &permission_object::id > > > > > permission_index
chainbase::shared_multi_index_container< key_value_object, indexed_by< ordered_unique< tag< by_id >, member< key_value_object, key_value_object::id_type, &key_value_object::id > >, ordered_unique< tag< by_scope_primary >, composite_key< key_value_object, member< key_value_object, table_id, &key_value_object::t_id >, member< key_value_object, uint64_t, &key_value_object::primary_key > >, composite_key_compare< std::less< table_id >, std::less< uint64_t > > > > > key_value_index
unsigned int uint32_t
Definition stdint.h:126
int64_t used
quantity used in current window
Here is the call graph for this function:

◆ get_accounts_by_authorizers()

get_accounts_by_authorizers_result sysio::chain_apis::read_only::get_accounts_by_authorizers ( const get_accounts_by_authorizers_params & args) const

◆ get_activated_protocol_features()

read_only::get_activated_protocol_features_results sysio::chain_apis::read_only::get_activated_protocol_features ( const get_activated_protocol_features_params & params) const

10ms max time

Definition at line 1472 of file chain_plugin.cpp.

1472 {
1473 read_only::get_activated_protocol_features_results result;
1474 const auto& pfm = db.get_protocol_feature_manager();
1475
1476 uint32_t lower_bound_value = std::numeric_limits<uint32_t>::lowest();
1477 uint32_t upper_bound_value = std::numeric_limits<uint32_t>::max();
1478
1479 if( params.lower_bound ) {
1480 lower_bound_value = *params.lower_bound;
1481 }
1482
1483 if( params.upper_bound ) {
1484 upper_bound_value = *params.upper_bound;
1485 }
1486
1487 if( upper_bound_value < lower_bound_value )
1488 return result;
1489
1490 auto walk_range = [&]( auto itr, auto end_itr, auto&& convert_iterator ) {
1492 mvo( "activation_ordinal", 0 );
1493 mvo( "activation_block_num", 0 );
1494
1495 auto& activation_ordinal_value = mvo["activation_ordinal"];
1496 auto& activation_block_num_value = mvo["activation_block_num"];
1497
1498 auto cur_time = fc::time_point::now();
1499 auto end_time = cur_time + fc::microseconds(1000 * 10);
1500 for( unsigned int count = 0;
1501 cur_time <= end_time && count < params.limit && itr != end_itr;
1502 ++itr, cur_time = fc::time_point::now() )
1503 {
1504 const auto& conv_itr = convert_iterator( itr );
1505 activation_ordinal_value = conv_itr.activation_ordinal();
1506 activation_block_num_value = conv_itr.activation_block_num();
1507
1508 result.activated_protocol_features.emplace_back( conv_itr->to_variant( false, &mvo ) );
1509 ++count;
1510 }
1511 if( itr != end_itr ) {
1512 result.more = convert_iterator( itr ).activation_ordinal() ;
1513 }
1514 };
1515
1516 auto get_next_if_not_end = [&pfm]( auto&& itr ) {
1517 if( itr == pfm.cend() ) return itr;
1518
1519 ++itr;
1520 return itr;
1521 };
1522
1523 auto lower = ( params.search_by_block_num ? pfm.lower_bound( lower_bound_value )
1524 : pfm.at_activation_ordinal( lower_bound_value ) );
1525
1526 auto upper = ( params.search_by_block_num ? pfm.upper_bound( upper_bound_value )
1527 : get_next_if_not_end( pfm.at_activation_ordinal( upper_bound_value ) ) );
1528
1529 if( params.reverse ) {
1530 walk_range( std::make_reverse_iterator(upper), std::make_reverse_iterator(lower),
1531 []( auto&& ritr ) { return --(ritr.base()); } );
1532 } else {
1533 walk_range( lower, upper, []( auto&& itr ) { return itr; } );
1534 }
1535
1536 return result;
1537}
An order-preserving dictionary of variants.
const protocol_feature_manager & get_protocol_feature_manager() const
int * count
Here is the call graph for this function:

◆ get_block()

fc::variant sysio::chain_apis::read_only::get_block ( const get_block_params & params) const

Definition at line 2041 of file chain_plugin.cpp.

2041 {
2042 signed_block_ptr block;
2043 std::optional<uint64_t> block_num;
2044
2045 SYS_ASSERT( !params.block_num_or_id.empty() && params.block_num_or_id.size() <= 64,
2046 chain::block_id_type_exception,
2047 "Invalid Block number or ID, must be greater than 0 and less than 64 characters"
2048 );
2049
2050 try {
2051 block_num = fc::to_uint64(params.block_num_or_id);
2052 } catch( ... ) {}
2053
2054 if( block_num ) {
2055 block = db.fetch_block_by_number( *block_num );
2056 } else {
2057 try {
2058 block = db.fetch_block_by_id( fc::variant(params.block_num_or_id).as<block_id_type>() );
2059 } SYS_RETHROW_EXCEPTIONS(chain::block_id_type_exception, "Invalid block ID: ${block_num_or_id}", ("block_num_or_id", params.block_num_or_id))
2060 }
2061
2062 SYS_ASSERT( block, unknown_block_exception, "Could not find block: ${block}", ("block", params.block_num_or_id));
2063
2064 fc::variant pretty_output;
2065 abi_serializer::to_variant(*block, pretty_output, make_resolver(db, abi_serializer::create_yield_function( abi_serializer_max_time )),
2066 abi_serializer::create_yield_function( abi_serializer_max_time ));
2067
2068 const auto block_id = block->calculate_id();
2069 uint32_t ref_block_prefix = block_id._hash[1];
2070
2071 return fc::mutable_variant_object(pretty_output.get_object())
2072 ("id", block_id)
2073 ("block_num",block->block_num())
2074 ("ref_block_prefix", ref_block_prefix);
2075}
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
variant_object & get_object()
Definition variant.cpp:554
T as() const
Definition variant.hpp:327
signed_block_ptr fetch_block_by_number(uint32_t block_num) const
signed_block_ptr fetch_block_by_id(block_id_type id) const
uint64_t to_uint64(const fc::string &)
Definition string.cpp:105
auto make_resolver(const controller &control, abi_serializer::yield_function_t yield)
fc::sha256 block_id_type
Definition types.hpp:231
std::shared_ptr< signed_block > signed_block_ptr
Definition block.hpp:105
static void to_variant(const T &o, fc::variant &vo, Resolver resolver, const yield_function_t &yield)
namespace sysio::chain::impl
Here is the call graph for this function:

◆ get_block_header_state()

fc::variant sysio::chain_apis::read_only::get_block_header_state ( const get_block_header_state_params & params) const

Definition at line 2106 of file chain_plugin.cpp.

2106 {
2108 std::optional<uint64_t> block_num;
2109 std::exception_ptr e;
2110 try {
2111 block_num = fc::to_uint64(params.block_num_or_id);
2112 } catch( ... ) {}
2113
2114 if( block_num ) {
2115 b = db.fetch_block_state_by_number(*block_num);
2116 } else {
2117 try {
2118 b = db.fetch_block_state_by_id(fc::variant(params.block_num_or_id).as<block_id_type>());
2119 } SYS_RETHROW_EXCEPTIONS(chain::block_id_type_exception, "Invalid block ID: ${block_num_or_id}", ("block_num_or_id", params.block_num_or_id))
2120 }
2121
2122 SYS_ASSERT( b, unknown_block_exception, "Could not find reversible block: ${block}", ("block", params.block_num_or_id));
2123
2124 fc::variant vo;
2125 fc::to_variant( static_cast<const block_header_state&>(*b), vo );
2126 return vo;
2127}
block_state_ptr fetch_block_state_by_number(uint32_t block_num) const
block_state_ptr fetch_block_state_by_id(block_id_type id) const
void to_variant(const sysio::chain::shared_public_key &var, fc::variant &vo)
Definition authority.cpp:4
std::shared_ptr< block_state > block_state_ptr
Here is the call graph for this function:

◆ get_block_info()

fc::variant sysio::chain_apis::read_only::get_block_info ( const get_block_info_params & params) const

Definition at line 2077 of file chain_plugin.cpp.

2077 {
2078
2079 signed_block_ptr block;
2080 try {
2081 block = db.fetch_block_by_number( params.block_num );
2082 } catch (...) {
2083 // assert below will handle the invalid block num
2084 }
2085
2086 SYS_ASSERT( block, unknown_block_exception, "Could not find block: ${block}", ("block", params.block_num));
2087
2088 const auto id = block->calculate_id();
2089 const uint32_t ref_block_prefix = id._hash[1];
2090
2092 ("block_num", block->block_num())
2093 ("ref_block_num", static_cast<uint16_t>(block->block_num()))
2094 ("id", id)
2095 ("timestamp", block->timestamp)
2096 ("producer", block->producer)
2097 ("confirmed", block->confirmed)
2098 ("previous", block->previous)
2099 ("transaction_mroot", block->transaction_mroot)
2100 ("action_mroot", block->action_mroot)
2101 ("schedule_version", block->schedule_version)
2102 ("producer_signature", block->producer_signature)
2103 ("ref_block_prefix", ref_block_prefix);
2104}
uint64_t id
Definition code_cache.cpp:0
unsigned short uint16_t
Definition stdint.h:125
Here is the call graph for this function:

◆ get_code()

read_only::get_code_results sysio::chain_apis::read_only::get_code ( const get_code_params & params) const

Definition at line 2362 of file chain_plugin.cpp.

2362 {
2363 get_code_results result;
2364 result.account_name = params.account_name;
2365 const auto& d = db.db();
2366 const auto& accnt_obj = d.get<account_object,by_name>( params.account_name );
2367 const auto& accnt_metadata_obj = d.get<account_metadata_object,by_name>( params.account_name );
2368
2369 SYS_ASSERT( params.code_as_wasm, unsupported_feature, "Returning WAST from get_code is no longer supported" );
2370
2371 if( accnt_metadata_obj.code_hash != digest_type() ) {
2372 const auto& code_obj = d.get<code_object, by_code_hash>(accnt_metadata_obj.code_hash);
2373 result.wasm = string(code_obj.code.begin(), code_obj.code.end());
2374 result.code_hash = code_obj.code_hash;
2375 }
2376
2377 abi_def abi;
2378 if( abi_serializer::to_abi(accnt_obj.abi, abi) ) {
2379 result.abi = std::move(abi);
2380 }
2381
2382 return result;
2383}
std::string string
Definition string.hpp:10
checksum_type digest_type
Definition types.hpp:237
Here is the call graph for this function:

◆ get_code_hash()

read_only::get_code_hash_results sysio::chain_apis::read_only::get_code_hash ( const get_code_hash_params & params) const

Definition at line 2385 of file chain_plugin.cpp.

2385 {
2386 get_code_hash_results result;
2387 result.account_name = params.account_name;
2388 const auto& d = db.db();
2389 const auto& accnt = d.get<account_metadata_object,by_name>( params.account_name );
2390
2391 if( accnt.code_hash != digest_type() )
2392 result.code_hash = accnt.code_hash;
2393
2394 return result;
2395}

◆ get_currency_balance()

vector< asset > sysio::chain_apis::read_only::get_currency_balance ( const get_currency_balance_params & params) const

Definition at line 1797 of file chain_plugin.cpp.

1797 {
1798
1799 const abi_def abi = sysio::chain_apis::get_abi( db, p.code );
1800 (void)get_table_type( abi, name("accounts") );
1801
1802 vector<asset> results;
1803 walk_key_value_table(p.code, p.account, "accounts"_n, [&](const key_value_object& obj){
1804 SYS_ASSERT( obj.value.size() >= sizeof(asset), chain::asset_type_exception, "Invalid data on table");
1805
1806 asset cursor;
1807 fc::datastream<const char *> ds(obj.value.data(), obj.value.size());
1808 fc::raw::unpack(ds, cursor);
1809
1810 SYS_ASSERT( cursor.get_symbol().valid(), chain::asset_type_exception, "Invalid asset");
1811
1812 if( !p.symbol || boost::iequals(cursor.symbol_name(), *p.symbol) ) {
1813 results.emplace_back(cursor);
1814 }
1815
1816 // return false if we are looking for one and found it, true otherwise
1817 return !(p.symbol && boost::iequals(cursor.symbol_name(), *p.symbol));
1818 });
1819
1820 return results;
1821}
void walk_key_value_table(const name &code, const name &scope, const name &table, Function f) const
string get_table_type(const abi_def &abi, const name &table_name)
abi_def get_abi(const controller &db, const name &account)
account_query_db::get_accounts_by_authorizers_result results
Here is the call graph for this function:

◆ get_currency_stats()

fc::variant sysio::chain_apis::read_only::get_currency_stats ( const get_currency_stats_params & params) const

Definition at line 1823 of file chain_plugin.cpp.

1823 {
1825
1826 const abi_def abi = sysio::chain_apis::get_abi( db, p.code );
1827 (void)get_table_type( abi, name("stat") );
1828
1829 uint64_t scope = ( sysio::chain::string_to_symbol( 0, boost::algorithm::to_upper_copy(p.symbol).c_str() ) >> 8 );
1830
1831 walk_key_value_table(p.code, name(scope), "stat"_n, [&](const key_value_object& obj){
1832 SYS_ASSERT( obj.value.size() >= sizeof(read_only::get_currency_stats_result), chain::asset_type_exception, "Invalid data on table");
1833
1834 fc::datastream<const char *> ds(obj.value.data(), obj.value.size());
1835 read_only::get_currency_stats_result result;
1836
1837 fc::raw::unpack(ds, result.supply);
1838 fc::raw::unpack(ds, result.max_supply);
1839 fc::raw::unpack(ds, result.issuer);
1840
1841 results[result.supply.symbol_name()] = result;
1842 return true;
1843 });
1844
1845 return results;
1846}
unsigned __int64 uint64_t
Definition stdint.h:136
Here is the call graph for this function:

◆ get_info()

read_only::get_info_results sysio::chain_apis::read_only::get_info ( const get_info_params & ) const

Definition at line 1416 of file chain_plugin.cpp.

1416 {
1417 const auto& rm = db.get_resource_limits_manager();
1418
1419 return {
1420 itoh(static_cast<uint32_t>(app().version())),
1421 db.get_chain_id(),
1422 db.head_block_num(),
1425 db.head_block_id(),
1426 db.head_block_time(),
1428 rm.get_virtual_block_cpu_limit(),
1429 rm.get_virtual_block_net_limit(),
1430 rm.get_block_cpu_limit(),
1431 rm.get_block_net_limit(),
1432 //std::bitset<64>(db.get_dynamic_global_properties().recent_slots_filled).to_string(),
1433 //__builtin_popcountll(db.get_dynamic_global_properties().recent_slots_filled) / 64.0,
1434 app().version_string(),
1438 rm.get_total_cpu_weight(),
1439 rm.get_total_net_weight(),
1442 };
1443}
string version_string() const
Get version string; generated from git describe if available.
string full_version_string() const
Get full version string; same as version_string() unless set differently.
block_id_type fork_db_pending_head_block_id() const
account_name head_block_producer() const
block_id_type head_block_id() const
uint32_t last_irreversible_block_num() const
uint32_t fork_db_pending_head_block_num() const
time_point last_irreversible_block_time() const
block_id_type last_irreversible_block_id() const
chain_id_type get_chain_id() const
uint32_t earliest_available_block_num() const
application & app()
std::string itoh(I n, size_t hlen=sizeof(I)<< 1)
Here is the call graph for this function:

◆ get_producer_schedule()

read_only::get_producer_schedule_result sysio::chain_apis::read_only::get_producer_schedule ( const get_producer_schedule_params & params) const

Definition at line 1937 of file chain_plugin.cpp.

1937 {
1938 read_only::get_producer_schedule_result result;
1939 to_variant(db.active_producers(), result.active);
1940 if(!db.pending_producers().producers.empty())
1941 to_variant(db.pending_producers(), result.pending);
1942 auto proposed = db.proposed_producers();
1943 if(proposed && !proposed->producers.empty())
1944 to_variant(*proposed, result.proposed);
1945 return result;
1946}
std::optional< producer_authority_schedule > proposed_producers() const
const producer_authority_schedule & pending_producers() const
const producer_authority_schedule & active_producers() const
Here is the call graph for this function:

◆ get_producers()

read_only::get_producers_result sysio::chain_apis::read_only::get_producers ( const get_producers_params & params) const

Definition at line 1864 of file chain_plugin.cpp.

1864 {
1865 const abi_def abi = sysio::chain_apis::get_abi(db, config::system_account_name);
1866 const auto table_type = get_table_type(abi, "producers"_n);
1867 const abi_serializer abis{ abi, abi_serializer::create_yield_function( abi_serializer_max_time ) };
1868 SYS_ASSERT(table_type == KEYi64, chain::contract_table_query_exception, "Invalid table type ${type} for table producers", ("type",table_type));
1869
1870 const auto& d = db.db();
1871 const auto lower = name{p.lower_bound};
1872
1873 static const uint8_t secondary_index_num = 0;
1874 const auto* const table_id = d.find<chain::table_id_object, chain::by_code_scope_table>(
1875 boost::make_tuple(config::system_account_name, config::system_account_name, "producers"_n));
1876 const auto* const secondary_table_id = d.find<chain::table_id_object, chain::by_code_scope_table>(
1877 boost::make_tuple(config::system_account_name, config::system_account_name, name("producers"_n.to_uint64_t() | secondary_index_num)));
1878 SYS_ASSERT(table_id && secondary_table_id, chain::contract_table_query_exception, "Missing producers table");
1879
1880 const auto& kv_index = d.get_index<key_value_index, by_scope_primary>();
1881 const auto& secondary_index = d.get_index<index_double_index>().indices();
1882 const auto& secondary_index_by_primary = secondary_index.get<by_primary>();
1883 const auto& secondary_index_by_secondary = secondary_index.get<by_secondary>();
1884
1885 read_only::get_producers_result result;
1886 const auto stopTime = fc::time_point::now() + fc::microseconds(1000 * 10); // 10ms
1887 vector<char> data;
1888
1889 auto it = [&]{
1890 if(lower.to_uint64_t() == 0)
1891 return secondary_index_by_secondary.lower_bound(
1892 boost::make_tuple(secondary_table_id->id, to_softfloat64(std::numeric_limits<double>::lowest()), 0));
1893 else
1894 return secondary_index.project<by_secondary>(
1895 secondary_index_by_primary.lower_bound(
1896 boost::make_tuple(secondary_table_id->id, lower.to_uint64_t())));
1897 }();
1898
1899 for( ; it != secondary_index_by_secondary.end() && it->t_id == secondary_table_id->id; ++it ) {
1900 if (result.rows.size() >= p.limit || fc::time_point::now() > stopTime) {
1901 result.more = name{it->primary_key}.to_string();
1902 break;
1903 }
1904 copy_inline_row(*kv_index.find(boost::make_tuple(table_id->id, it->primary_key)), data);
1905 if (p.json)
1906 result.rows.emplace_back( abis.binary_to_variant( abis.get_table_type("producers"_n), data, abi_serializer::create_yield_function( abi_serializer_max_time ), shorten_abi_errors ) );
1907 else
1908 result.rows.emplace_back(fc::variant(data));
1909 }
1910
1911 result.total_producer_vote_weight = get_global_row(d, abi, abis, abi_serializer_max_time, shorten_abi_errors)["total_producer_vote_weight"].as_double();
1912 return result;
1913} catch (...) {
1914 read_only::get_producers_result result;
1915
1916 for (auto p : db.active_producers().producers) {
1917 auto row = fc::mutable_variant_object()
1918 ("owner", p.producer_name)
1919 ("producer_authority", p.authority)
1920 ("url", "")
1921 ("total_votes", 0.0f);
1922
1923 // detect a legacy key and maintain API compatibility for those entries
1924 if (std::holds_alternative<block_signing_authority_v0>(p.authority)) {
1925 const auto& auth = std::get<block_signing_authority_v0>(p.authority);
1926 if (auth.keys.size() == 1 && auth.keys.back().weight == auth.threshold) {
1927 row("producer_key", auth.keys.back().key);
1928 }
1929 }
1930
1931 result.rows.push_back(row);
1932 }
1933
1934 return result;
1935}
double as_double() const
Definition variant.cpp:420
static const string KEYi64
fc::variant get_global_row(const database &db, const abi_def &abi, const abi_serializer &abis, const fc::microseconds &abi_serializer_max_time_us, bool shorten_abi_errors)
table_id_object::id_type table_id
secondary_index< float64_t, index_double_object_type, soft_double_less >::index_index index_double_index
float64_t to_softfloat64(double d)
unsigned char uint8_t
Definition stdint.h:124
Here is the call graph for this function:

◆ get_raw_abi()

read_only::get_raw_abi_results sysio::chain_apis::read_only::get_raw_abi ( const get_raw_abi_params & params) const

Definition at line 2413 of file chain_plugin.cpp.

2413 {
2414 get_raw_abi_results result;
2415 result.account_name = params.account_name;
2416
2417 const auto& d = db.db();
2418 const auto& accnt_obj = d.get<account_object,by_name>(params.account_name);
2419 const auto& accnt_metadata_obj = d.get<account_metadata_object,by_name>(params.account_name);
2420 result.abi_hash = fc::sha256::hash( accnt_obj.abi.data(), accnt_obj.abi.size() );
2421 if( accnt_metadata_obj.code_hash != digest_type() )
2422 result.code_hash = accnt_metadata_obj.code_hash;
2423 if( !params.abi_hash || *params.abi_hash != result.abi_hash )
2424 result.abi = blob{{accnt_obj.abi.begin(), accnt_obj.abi.end()}};
2425
2426 return result;
2427}
static sha256 hash(const char *d, uint32_t dlen)
Definition sha256.cpp:44
Here is the call graph for this function:

◆ get_raw_code_and_abi()

read_only::get_raw_code_and_abi_results sysio::chain_apis::read_only::get_raw_code_and_abi ( const get_raw_code_and_abi_params & params) const

Definition at line 2397 of file chain_plugin.cpp.

2397 {
2398 get_raw_code_and_abi_results result;
2399 result.account_name = params.account_name;
2400
2401 const auto& d = db.db();
2402 const auto& accnt_obj = d.get<account_object,by_name>(params.account_name);
2403 const auto& accnt_metadata_obj = d.get<account_metadata_object,by_name>(params.account_name);
2404 if( accnt_metadata_obj.code_hash != digest_type() ) {
2405 const auto& code_obj = d.get<code_object, by_code_hash>(accnt_metadata_obj.code_hash);
2406 result.wasm = blob{{code_obj.code.begin(), code_obj.code.end()}};
2407 }
2408 result.abi = blob{{accnt_obj.abi.begin(), accnt_obj.abi.end()}};
2409
2410 return result;
2411}

◆ get_required_keys()

get_required_keys_result sysio::chain_apis::read_only::get_required_keys ( const get_required_keys_params & params) const

◆ get_scheduled_transactions()

read_only::get_scheduled_transactions_result sysio::chain_apis::read_only::get_scheduled_transactions ( const get_scheduled_transactions_params & params) const

10ms max time

Definition at line 1969 of file chain_plugin.cpp.

1969 {
1970 const auto& d = db.db();
1971
1972 const auto& idx_by_delay = d.get_index<generated_transaction_multi_index,by_delay>();
1973 auto itr = ([&](){
1974 if (!p.lower_bound.empty()) {
1975 try {
1976 auto when = time_point::from_iso_string( p.lower_bound );
1977 return idx_by_delay.lower_bound(boost::make_tuple(when));
1978 } catch (...) {
1979 try {
1980 auto txid = transaction_id_type(p.lower_bound);
1981 const auto& by_txid = d.get_index<generated_transaction_multi_index,by_trx_id>();
1982 auto itr = by_txid.find( txid );
1983 if (itr == by_txid.end()) {
1984 SYS_THROW(transaction_exception, "Unknown Transaction ID: ${txid}", ("txid", txid));
1985 }
1986
1987 return d.get_index<generated_transaction_multi_index>().indices().project<by_delay>(itr);
1988
1989 } catch (...) {
1990 return idx_by_delay.end();
1991 }
1992 }
1993 } else {
1994 return idx_by_delay.begin();
1995 }
1996 })();
1997
1998 read_only::get_scheduled_transactions_result result;
1999
2000 auto resolver = make_resolver(db, abi_serializer::create_yield_function( abi_serializer_max_time ));
2001
2002 uint32_t remaining = p.limit;
2003 auto time_limit = fc::time_point::now() + fc::microseconds(1000 * 10);
2004 while (itr != idx_by_delay.end() && remaining > 0 && time_limit > fc::time_point::now()) {
2005 auto row = fc::mutable_variant_object()
2006 ("trx_id", itr->trx_id)
2007 ("sender", itr->sender)
2008 ("sender_id", itr->sender_id)
2009 ("payer", itr->payer)
2010 ("delay_until", itr->delay_until)
2011 ("expiration", itr->expiration)
2012 ("published", itr->published)
2013 ;
2014
2015 if (p.json) {
2016 fc::variant pretty_transaction;
2017
2018 transaction trx;
2019 fc::datastream<const char*> ds( itr->packed_trx.data(), itr->packed_trx.size() );
2020 fc::raw::unpack(ds,trx);
2021
2022 abi_serializer::to_variant(trx, pretty_transaction, resolver, abi_serializer::create_yield_function( abi_serializer_max_time ));
2023 row("transaction", pretty_transaction);
2024 } else {
2025 auto packed_transaction = bytes(itr->packed_trx.begin(), itr->packed_trx.end());
2026 row("transaction", packed_transaction);
2027 }
2028
2029 result.transactions.emplace_back(std::move(row));
2030 ++itr;
2031 remaining--;
2032 }
2033
2034 if (itr != idx_by_delay.end()) {
2035 result.more = string(itr->trx_id);
2036 }
2037
2038 return result;
2039}
#define SYS_THROW(exc_type, FORMAT,...)
static time_point from_iso_string(const fc::string &s)
Definition time.cpp:67
key Invalid authority Invalid transaction Invalid block ID Invalid packed transaction Invalid chain ID Invalid symbol Signature type is not a currently activated type Block can not be found Unlinkable block Block does not guarantee concurrent execution without conflicts Block exhausted allowed resources Block is from the future Block is not signed by expected producer Block includes an ill formed protocol feature activation extension Block includes an ill formed additional block signature extension transaction_exception
chainbase::shared_multi_index_container< generated_transaction_object, indexed_by< ordered_unique< tag< by_id >, BOOST_MULTI_INDEX_MEMBER(generated_transaction_object, generated_transaction_object::id_type, id)>, ordered_unique< tag< by_trx_id >, BOOST_MULTI_INDEX_MEMBER(generated_transaction_object, transaction_id_type, trx_id)>, ordered_unique< tag< by_expiration >, composite_key< generated_transaction_object, BOOST_MULTI_INDEX_MEMBER(generated_transaction_object, time_point, expiration), > >, ordered_unique< tag< by_delay >, composite_key< generated_transaction_object, BOOST_MULTI_INDEX_MEMBER(generated_transaction_object, time_point, delay_until), > >, ordered_unique< tag< by_sender_id >, composite_key< generated_transaction_object, BOOST_MULTI_INDEX_MEMBER(generated_transaction_object, account_name, sender), > > > > generated_transaction_multi_index
checksum_type transaction_id_type
Definition types.hpp:236
vector< char > bytes
Definition types.hpp:243
Here is the call graph for this function:

◆ get_table_by_scope()

read_only::get_table_by_scope_result sysio::chain_apis::read_only::get_table_by_scope ( const get_table_by_scope_params & params) const

10ms max time

Definition at line 1749 of file chain_plugin.cpp.

1749 {
1750 read_only::get_table_by_scope_result result;
1751 const auto& d = db.db();
1752
1753 const auto& idx = d.get_index<chain::table_id_multi_index, chain::by_code_scope_table>();
1754 auto lower_bound_lookup_tuple = std::make_tuple( p.code, name(std::numeric_limits<uint64_t>::lowest()), p.table );
1755 auto upper_bound_lookup_tuple = std::make_tuple( p.code, name(std::numeric_limits<uint64_t>::max()),
1756 (p.table.empty() ? name(std::numeric_limits<uint64_t>::max()) : p.table) );
1757
1758 if( p.lower_bound.size() ) {
1759 uint64_t scope = convert_to_type<uint64_t>(p.lower_bound, "lower_bound scope");
1760 std::get<1>(lower_bound_lookup_tuple) = name(scope);
1761 }
1762
1763 if( p.upper_bound.size() ) {
1764 uint64_t scope = convert_to_type<uint64_t>(p.upper_bound, "upper_bound scope");
1765 std::get<1>(upper_bound_lookup_tuple) = name(scope);
1766 }
1767
1768 if( upper_bound_lookup_tuple < lower_bound_lookup_tuple )
1769 return result;
1770
1771 auto walk_table_range = [&]( auto itr, auto end_itr ) {
1772 auto cur_time = fc::time_point::now();
1773 auto end_time = cur_time + fc::microseconds(1000 * 10);
1774 for( unsigned int count = 0; cur_time <= end_time && count < p.limit && itr != end_itr; ++itr, cur_time = fc::time_point::now() ) {
1775 if( p.table && itr->table != p.table ) continue;
1776
1777 result.rows.push_back( {itr->code, itr->scope, itr->table, itr->payer, itr->count} );
1778
1779 ++count;
1780 }
1781 if( itr != end_itr ) {
1782 result.more = itr->scope.to_string();
1783 }
1784 };
1785
1786 auto lower = idx.lower_bound( lower_bound_lookup_tuple );
1787 auto upper = idx.upper_bound( upper_bound_lookup_tuple );
1788 if( p.reverse && *p.reverse ) {
1789 walk_table_range( boost::make_reverse_iterator(upper), boost::make_reverse_iterator(lower) );
1790 } else {
1791 walk_table_range( lower, upper );
1792 }
1793
1794 return result;
1795}
uint64_t convert_to_type(const string &str, const string &desc)
chainbase::shared_multi_index_container< table_id_object, indexed_by< ordered_unique< tag< by_id >, member< table_id_object, table_id_object::id_type, &table_id_object::id > >, ordered_unique< tag< by_code_scope_table >, composite_key< table_id_object, member< table_id_object, account_name, &table_id_object::code >, member< table_id_object, scope_name, &table_id_object::scope >, member< table_id_object, table_name, &table_id_object::table > > > > > table_id_multi_index
size_t size() const
Definition zm.h:519
Here is the call graph for this function:

◆ get_table_index_name()

uint64_t sysio::chain_apis::read_only::get_table_index_name ( const read_only::get_table_rows_params & p,
bool & primary )
static

Definition at line 1539 of file chain_plugin.cpp.

1539 {
1540 using boost::algorithm::starts_with;
1541 // see multi_index packing of index name
1542 const uint64_t table = p.table.to_uint64_t();
1543 uint64_t index = table & 0xFFFFFFFFFFFFFFF0ULL;
1544 SYS_ASSERT( index == table, chain::contract_table_query_exception, "Unsupported table name: ${n}", ("n", p.table) );
1545
1546 primary = false;
1547 uint64_t pos = 0;
1548 if (p.index_position.empty() || p.index_position == "first" || p.index_position == "primary" || p.index_position == "one") {
1549 primary = true;
1550 } else if (starts_with(p.index_position, "sec") || p.index_position == "two") { // second, secondary
1551 } else if (starts_with(p.index_position , "ter") || starts_with(p.index_position, "th")) { // tertiary, ternary, third, three
1552 pos = 1;
1553 } else if (starts_with(p.index_position, "fou")) { // four, fourth
1554 pos = 2;
1555 } else if (starts_with(p.index_position, "fi")) { // five, fifth
1556 pos = 3;
1557 } else if (starts_with(p.index_position, "six")) { // six, sixth
1558 pos = 4;
1559 } else if (starts_with(p.index_position, "sev")) { // seven, seventh
1560 pos = 5;
1561 } else if (starts_with(p.index_position, "eig")) { // eight, eighth
1562 pos = 6;
1563 } else if (starts_with(p.index_position, "nin")) { // nine, ninth
1564 pos = 7;
1565 } else if (starts_with(p.index_position, "ten")) { // ten, tenth
1566 pos = 8;
1567 } else {
1568 try {
1569 pos = fc::to_uint64( p.index_position );
1570 } catch(...) {
1571 SYS_ASSERT( false, chain::contract_table_query_exception, "Invalid index_position: ${p}", ("p", p.index_position));
1572 }
1573 if (pos < 2) {
1574 primary = true;
1575 pos = 0;
1576 } else {
1577 pos -= 2;
1578 }
1579 }
1580 index |= (pos & 0x000000000000000FULL);
1581 return index;
1582}
bool starts_with(std::string const &str, std::string const &pref)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_table_rows()

read_only::get_table_rows_result sysio::chain_apis::read_only::get_table_rows ( const get_table_rows_params & params) const

Definition at line 1682 of file chain_plugin.cpp.

1682 {
1683 const abi_def abi = sysio::chain_apis::get_abi( db, p.code );
1684 bool primary = false;
1685 auto table_with_index = get_table_index_name( p, primary );
1686 if( primary ) {
1687 SYS_ASSERT( p.table == table_with_index, chain::contract_table_query_exception, "Invalid table name ${t}", ( "t", p.table ));
1688 auto table_type = get_table_type( abi, p.table );
1689 if( table_type == KEYi64 || p.key_type == "i64" || p.key_type == "name" ) {
1691 }
1692 SYS_ASSERT( false, chain::contract_table_query_exception, "Invalid table type ${type}", ("type",table_type)("abi",abi));
1693 } else {
1694 SYS_ASSERT( !p.key_type.empty(), chain::contract_table_query_exception, "key type required for non-primary index" );
1695
1696 if (p.key_type == chain_apis::i64 || p.key_type == "name") {
1698 return v;
1699 });
1700 }
1701 else if (p.key_type == chain_apis::i128) {
1703 return v;
1704 });
1705 }
1706 else if (p.key_type == chain_apis::i256) {
1707 if ( p.encode_type == chain_apis::hex) {
1708 using conv = keytype_converter<chain_apis::sha256,chain_apis::hex>;
1710 }
1711 using conv = keytype_converter<chain_apis::i256>;
1713 }
1714 else if (p.key_type == chain_apis::float64) {
1716 float64_t f;
1717 double_to_float64(v, f);
1718 return f;
1719 });
1720 }
1721 else if (p.key_type == chain_apis::float128) {
1722 if ( p.encode_type == chain_apis::hex) {
1724 float128_t f;
1726 return f;
1727 });
1728 }
1730 float64_t f;
1731 double_to_float64(v, f);
1732 float128_t f128;
1733 f64_to_f128M(f, &f128);
1734 return f128;
1735 });
1736 }
1737 else if (p.key_type == chain_apis::sha256) {
1738 using conv = keytype_converter<chain_apis::sha256,chain_apis::hex>;
1740 }
1741 else if(p.key_type == chain_apis::ripemd160) {
1742 using conv = keytype_converter<chain_apis::ripemd160,chain_apis::hex>;
1744 }
1745 SYS_ASSERT(false, chain::contract_table_query_exception, "Unsupported secondary index type: ${t}", ("t", p.key_type));
1746 }
1747}
read_only::get_table_rows_result get_table_rows_by_seckey(const read_only::get_table_rows_params &p, const abi_def &abi, ConvFn conv) const
read_only::get_table_rows_result get_table_rows_ex(const read_only::get_table_rows_params &p, const abi_def &abi) const
static uint64_t get_table_index_name(const read_only::get_table_rows_params &p, bool &primary)
void uint128_to_float128(const sysio::chain::uint128_t &u, float128_t &f)
void double_to_float64(const double &d, float64_t &f)
__uint128_t uint128_t
Definition config.hpp:8
constexpr const char hex[]
constexpr const char i256[]
constexpr const char float64[]
constexpr const char i64[]
constexpr const char i128[]
constexpr const char ripemd160[]
constexpr const char sha256[]
constexpr const char float128[]
void f64_to_f128M(float64_t a, float128_t *zPtr)
Here is the call graph for this function:

◆ get_table_rows_by_seckey()

template<typename IndexType , typename SecKeyType , typename ConvFn >
read_only::get_table_rows_result sysio::chain_apis::read_only::get_table_rows_by_seckey ( const read_only::get_table_rows_params & p,
const abi_def & abi,
ConvFn conv ) const
inline

10ms max time

Definition at line 480 of file chain_plugin.hpp.

480 {
481 read_only::get_table_rows_result result;
482 const auto& d = db.db();
483
484 name scope{ convert_to_type<uint64_t>(p.scope, "scope") };
485
486 abi_serializer abis;
487 abis.set_abi(abi, abi_serializer::create_yield_function( abi_serializer_max_time ) );
488 bool primary = false;
489 const uint64_t table_with_index = get_table_index_name(p, primary);
490 const auto* t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple(p.code, scope, p.table));
491 const auto* index_t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple(p.code, scope, name(table_with_index)));
492 if( t_id != nullptr && index_t_id != nullptr ) {
493 using secondary_key_type = std::result_of_t<decltype(conv)(SecKeyType)>;
494 static_assert( std::is_same<typename IndexType::value_type::secondary_key_type, secondary_key_type>::value, "Return type of conv does not match type of secondary key for IndexType" );
495
496 const auto& secidx = d.get_index<IndexType, chain::by_secondary>();
497 auto lower_bound_lookup_tuple = std::make_tuple( index_t_id->id._id,
499 std::numeric_limits<uint64_t>::lowest() );
500 auto upper_bound_lookup_tuple = std::make_tuple( index_t_id->id._id,
502 std::numeric_limits<uint64_t>::max() );
503
504 if( p.lower_bound.size() ) {
505 if( p.key_type == "name" ) {
506 name s(p.lower_bound);
507 SecKeyType lv = convert_to_type<SecKeyType>( s.to_string(), "lower_bound name" ); // avoids compiler error
508 std::get<1>(lower_bound_lookup_tuple) = conv( lv );
509 } else {
510 SecKeyType lv = convert_to_type<SecKeyType>( p.lower_bound, "lower_bound" );
511 std::get<1>(lower_bound_lookup_tuple) = conv( lv );
512 }
513 }
514
515 if( p.upper_bound.size() ) {
516 if( p.key_type == "name" ) {
517 name s(p.upper_bound);
518 SecKeyType uv = convert_to_type<SecKeyType>( s.to_string(), "upper_bound name" );
519 std::get<1>(upper_bound_lookup_tuple) = conv( uv );
520 } else {
521 SecKeyType uv = convert_to_type<SecKeyType>( p.upper_bound, "upper_bound" );
522 std::get<1>(upper_bound_lookup_tuple) = conv( uv );
523 }
524 }
525
526 if( upper_bound_lookup_tuple < lower_bound_lookup_tuple )
527 return result;
528
529 auto walk_table_row_range = [&]( auto itr, auto end_itr ) {
530 auto cur_time = fc::time_point::now();
531 auto end_time = cur_time + fc::microseconds(1000 * 10);
532 vector<char> data;
533 for( unsigned int count = 0; cur_time <= end_time && count < p.limit && itr != end_itr; ++itr, cur_time = fc::time_point::now() ) {
534 const auto* itr2 = d.find<chain::key_value_object, chain::by_scope_primary>( boost::make_tuple(t_id->id, itr->primary_key) );
535 if( itr2 == nullptr ) continue;
536 copy_inline_row(*itr2, data);
537
538 fc::variant data_var;
539 if( p.json ) {
540 data_var = abis.binary_to_variant( abis.get_table_type(p.table), data, abi_serializer::create_yield_function( abi_serializer_max_time ), shorten_abi_errors );
541 } else {
542 data_var = fc::variant( data );
543 }
544
545 if( p.show_payer && *p.show_payer ) {
546 result.rows.emplace_back( fc::mutable_variant_object("data", std::move(data_var))("payer", itr->payer) );
547 } else {
548 result.rows.emplace_back( std::move(data_var) );
549 }
550
551 ++count;
552 }
553 if( itr != end_itr ) {
554 result.more = true;
555 result.next_key = convert_to_string(itr->secondary_key, p.key_type, p.encode_type, "next_key - next lower bound");
556 }
557 };
558
559 auto lower = secidx.lower_bound( lower_bound_lookup_tuple );
560 auto upper = secidx.upper_bound( upper_bound_lookup_tuple );
561 if( p.reverse && *p.reverse ) {
562 walk_table_row_range( boost::make_reverse_iterator(upper), boost::make_reverse_iterator(lower) );
563 } else {
564 walk_table_row_range( lower, upper );
565 }
566 }
567 return result;
568 }
string convert_to_string(const Type &source, const string &key_type, const string &encode_type, const string &desc)
char * s
Here is the call graph for this function:

◆ get_table_rows_ex()

template<typename IndexType >
read_only::get_table_rows_result sysio::chain_apis::read_only::get_table_rows_ex ( const read_only::get_table_rows_params & p,
const abi_def & abi ) const
inline

10ms max time

Definition at line 571 of file chain_plugin.hpp.

571 {
572 read_only::get_table_rows_result result;
573 const auto& d = db.db();
574
575 uint64_t scope = convert_to_type<uint64_t>(p.scope, "scope");
576
577 abi_serializer abis;
578 abis.set_abi(abi, abi_serializer::create_yield_function( abi_serializer_max_time ));
579 const auto* t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple(p.code, name(scope), p.table));
580 if( t_id != nullptr ) {
581 const auto& idx = d.get_index<IndexType, chain::by_scope_primary>();
582 auto lower_bound_lookup_tuple = std::make_tuple( t_id->id, std::numeric_limits<uint64_t>::lowest() );
583 auto upper_bound_lookup_tuple = std::make_tuple( t_id->id, std::numeric_limits<uint64_t>::max() );
584
585 if( p.lower_bound.size() ) {
586 if( p.key_type == "name" ) {
587 name s(p.lower_bound);
588 std::get<1>(lower_bound_lookup_tuple) = s.to_uint64_t();
589 } else {
590 auto lv = convert_to_type<typename IndexType::value_type::key_type>( p.lower_bound, "lower_bound" );
591 std::get<1>(lower_bound_lookup_tuple) = lv;
592 }
593 }
594
595 if( p.upper_bound.size() ) {
596 if( p.key_type == "name" ) {
597 name s(p.upper_bound);
598 std::get<1>(upper_bound_lookup_tuple) = s.to_uint64_t();
599 } else {
600 auto uv = convert_to_type<typename IndexType::value_type::key_type>( p.upper_bound, "upper_bound" );
601 std::get<1>(upper_bound_lookup_tuple) = uv;
602 }
603 }
604
605 if( upper_bound_lookup_tuple < lower_bound_lookup_tuple )
606 return result;
607
608 auto walk_table_row_range = [&]( auto itr, auto end_itr ) {
609 auto cur_time = fc::time_point::now();
610 auto end_time = cur_time + fc::microseconds(1000 * 10);
611 vector<char> data;
612 for( unsigned int count = 0; cur_time <= end_time && count < p.limit && itr != end_itr; ++count, ++itr, cur_time = fc::time_point::now() ) {
613 copy_inline_row(*itr, data);
614
615 fc::variant data_var;
616 if( p.json ) {
617 data_var = abis.binary_to_variant( abis.get_table_type(p.table), data, abi_serializer::create_yield_function( abi_serializer_max_time ), shorten_abi_errors );
618 } else {
619 data_var = fc::variant( data );
620 }
621
622 if( p.show_payer && *p.show_payer ) {
623 result.rows.emplace_back( fc::mutable_variant_object("data", std::move(data_var))("payer", itr->payer) );
624 } else {
625 result.rows.emplace_back( std::move(data_var) );
626 }
627 }
628 if( itr != end_itr ) {
629 result.more = true;
630 result.next_key = convert_to_string(itr->primary_key, p.key_type, p.encode_type, "next_key - next lower bound");
631 }
632 };
633
634 auto lower = idx.lower_bound( lower_bound_lookup_tuple );
635 auto upper = idx.upper_bound( upper_bound_lookup_tuple );
636 if( p.reverse && *p.reverse ) {
637 walk_table_row_range( boost::make_reverse_iterator(upper), boost::make_reverse_iterator(lower) );
638 } else {
639 walk_table_row_range( lower, upper );
640 }
641 }
642 return result;
643 }
Here is the call graph for this function:

◆ get_transaction_id()

get_transaction_id_result sysio::chain_apis::read_only::get_transaction_id ( const get_transaction_id_params & params) const

◆ get_transaction_status()

read_only::get_transaction_status_results sysio::chain_apis::read_only::get_transaction_status ( const get_transaction_status_params & params) const

Definition at line 1445 of file chain_plugin.cpp.

1445 {
1446 SYS_ASSERT(trx_finality_status_proc, unsupported_feature, "Transaction Status Interface not enabled. To enable, configure nodeop with '--transaction-finality-status-max-storage-size-gb <size>'.");
1447
1448 trx_finality_status_processing::chain_state ch_state = trx_finality_status_proc->get_chain_state();
1449
1450 const auto trx_st = trx_finality_status_proc->get_trx_state(param.id);
1451 // check if block_id is set to a valid value, since trx_finality_status_proc does not use optionals for the block data
1452 const auto trx_block_valid = trx_st && trx_st->block_id != chain::block_id_type{};
1453
1454 return {
1455 trx_st ? trx_st->status : "UNKNOWN",
1456 trx_block_valid ? std::optional<uint32_t>(chain::block_header::num_from_id(trx_st->block_id)) : std::optional<uint32_t>{},
1457 trx_block_valid ? std::optional<chain::block_id_type>(trx_st->block_id) : std::optional<chain::block_id_type>{},
1458 trx_block_valid ? std::optional<fc::time_point>(trx_st->block_timestamp) : std::optional<fc::time_point>{},
1459 trx_st ? std::optional<fc::time_point_sec>(trx_st->expiration) : std::optional<fc::time_point_sec>{},
1460 chain::block_header::num_from_id(ch_state.head_id),
1461 ch_state.head_id,
1462 ch_state.head_block_timestamp,
1463 chain::block_header::num_from_id(ch_state.irr_id),
1464 ch_state.irr_id,
1465 ch_state.irr_block_timestamp,
1466 ch_state.earliest_tracked_block_id,
1467 chain::block_header::num_from_id(ch_state.earliest_tracked_block_id)
1468 };
1469}
std::optional< trx_state > get_trx_state(const chain::transaction_id_type &id) const
namespace sysio::chain
Definition authority.cpp:3
static uint32_t num_from_id(const block_id_type &id)

◆ set_shorten_abi_errors()

void sysio::chain_apis::read_only::set_shorten_abi_errors ( bool f)
inline

Definition at line 105 of file chain_plugin.hpp.

105{ shorten_abi_errors = f; }

◆ validate()

void sysio::chain_apis::read_only::validate ( ) const
inline

Definition at line 103 of file chain_plugin.hpp.

103{}

◆ walk_key_value_table()

template<typename Function >
void sysio::chain_apis::read_only::walk_key_value_table ( const name & code,
const name & scope,
const name & table,
Function f ) const
inline

Definition at line 459 of file chain_plugin.hpp.

460 {
461 const auto& d = db.db();
462 const auto* t_id = d.find<chain::table_id_object, chain::by_code_scope_table>(boost::make_tuple(code, scope, table));
463 if (t_id != nullptr) {
464 const auto &idx = d.get_index<chain::key_value_index, chain::by_scope_primary>();
465 decltype(t_id->id) next_tid(t_id->id._id + 1);
466 auto lower = idx.lower_bound(boost::make_tuple(t_id->id));
467 auto upper = idx.lower_bound(boost::make_tuple(next_tid));
468
469 for (auto itr = lower; itr != upper; ++itr) {
470 if (!f(*itr)) {
471 break;
472 }
473 }
474 }
475 }
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ KEYi64

const string sysio::chain_apis::read_only::KEYi64 = "i64"
static

Definition at line 97 of file chain_plugin.hpp.


The documentation for this class was generated from the following files: