Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

get_all_accounts and blockchain_audit_tool #10811

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a85f21d
add get_all_accounts RPC call with tests
praphael Sep 30, 2021
aedbb18
add blockchain_audit_tool.py
praphael Sep 30, 2021
3e18997
get contract tables, add full server version info, detect error on JS…
praphael Sep 30, 2021
691a36b
add account creation and last code update dates
praphael Oct 1, 2021
af4f2c5
get_all_accounts RPC: use 10ms limit, std::advance on iterator, add '…
praphael Oct 1, 2021
f04b1fe
get_all_accounts fix std::distance call
praphael Oct 1, 2021
6cdeb4c
blockchain_audit_tool add kv_tables, add head block time
praphael Oct 1, 2021
b073f3f
get_all_accounts: use lower and upper bound in params which allows s…
praphael Oct 2, 2021
c69f216
address PR comments
praphael Oct 4, 2021
a35944e
continue if error retrieving table data
praphael Oct 5, 2021
6be6435
add deferred transactions
praphael Oct 6, 2021
a53f90e
fix deferred transactions query, add scope and table limits to arguments
praphael Oct 7, 2021
7c85f71
add progress info, use stderr for status and error info
praphael Oct 7, 2021
0831e67
update help info, verify params
praphael Oct 8, 2021
fc16e9e
address PR comments
praphael Oct 8, 2021
8ab0b97
remove resolver_factory accidentally added
praphael Oct 13, 2021
209a20e
add back in FC_REFLECT send_ro_transaction
praphael Oct 13, 2021
96545b1
Merge branch 'develop' of https://github.com/EOSIO/eos into pdr-EPE-1…
praphael Oct 14, 2021
b95f9ae
remove test_HistoryApi inadvertenly added back in
praphael Oct 14, 2021
18f1406
copy blockchain_audit_tool.py to build scripts dir
praphael Oct 14, 2021
aac3ea3
blockchain_audit_tool: add ability to compare to reference, rework ar…
praphael Oct 14, 2021
f54f3eb
update blockchain_audit_tool.py
praphael Nov 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugins/chain_api_plugin/chain_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ void chain_api_plugin::plugin_startup() {
CHAIN_RW_CALL_ASYNC(push_transaction, chain_apis::read_write::push_transaction_results, 202, http_params_types::params_required),
CHAIN_RW_CALL_ASYNC(push_transactions, chain_apis::read_write::push_transactions_results, 202, http_params_types::params_required),
CHAIN_RW_CALL_ASYNC_V2(send_transaction, chain_apis::read_write::push_transaction_results, 202, http_params_types::params_required),
CHAIN_RW_CALL_ASYNC(send_transaction, chain_apis::read_write::send_transaction_results, 202, http_params_types::params_required)
CHAIN_RW_CALL_ASYNC(send_transaction, chain_apis::read_write::send_transaction_results, 202, http_params_types::params_required),
CHAIN_RO_CALL(get_all_accounts, 200, http_params_types::params_required)
});

if (chain.account_queries_enabled()) {
Expand Down
51 changes: 51 additions & 0 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3356,6 +3356,57 @@ eosio::chain::backing_store_type read_only::get_backing_store() const {
return kv_database.get_backing_store();
}

read_only::get_all_accounts_result
read_only::get_all_accounts( const get_all_accounts_params& params ) const
{
get_all_accounts_result result;

using acct_obj_idx_type = chainbase::get_index_type<chain::account_object>::type;
const auto& accts = db.db().get_index<acct_obj_idx_type >().indices().get<chain::by_name>();

auto cur_time = fc::time_point::now();
auto end_time = cur_time + fc::microseconds(1000 * 10); /// 10ms max time

auto begin_itr = params.lower_bound? accts.lower_bound(*params.lower_bound) : accts.begin();
auto end_itr = params.upper_bound? accts.upper_bound(*params.upper_bound) : accts.end();

if( std::distance(begin_itr, end_itr) < 0 )
return result;

auto itr = params.reverse? end_itr : begin_itr;
// since end_itr could potentially be past end of array, subtract one position
if (params.reverse)
--itr;

// this flag will be set to true when we are reversing and we end on the begin iterator
// if this is the case, 'more' field will remain null, and will nto be in JSON response
bool reverse_end_begin = false;

while(cur_time <= end_time
&& result.accounts.size() < params.limit
&& itr != end_itr)
{
const auto &a = *itr;
result.accounts.push_back({a.name, a.creation_date});

cur_time = fc::time_point::now();
if (params.reverse && itr == begin_itr) {
reverse_end_begin = true;
break;
}
params.reverse? --itr : ++itr;
}

if (params.reverse && !reverse_end_begin) {
result.more = itr->name;
}
else if (!params.reverse && itr != end_itr) {
result.more = itr->name;
}

return result;
}

} // namespace chain_apis

fc::variant chain_plugin::get_entire_trx_trace(const transaction_trace_ptr& trx_trace )const {
Expand Down
23 changes: 22 additions & 1 deletion plugins/chain_plugin/include/eosio/chain_plugin/chain_plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,25 @@ class read_only {

chain::symbol extract_core_symbol()const;

struct get_all_accounts_result {
struct account_result {
chain::name name;
chain::block_timestamp_type creation_date;
};

std::vector<account_result> accounts;

std::optional<chain::name> more;
};

struct get_all_accounts_params {
uint32_t limit = 10;
std::optional<chain::name> lower_bound;
std::optional<chain::name> upper_bound;
bool reverse = false;
};

get_all_accounts_result get_all_accounts( const get_all_accounts_params& params) const;
};

class read_write {
Expand Down Expand Up @@ -1150,4 +1169,6 @@ FC_REFLECT( eosio::chain_apis::read_only::get_required_keys_params, (transaction
FC_REFLECT( eosio::chain_apis::read_only::get_required_keys_result, (required_keys) )
FC_REFLECT( eosio::chain_apis::read_only::send_ro_transaction_params_v1, (return_failure_traces)(transaction) )
FC_REFLECT( eosio::chain_apis::read_only::send_ro_transaction_results, (head_block_num)(head_block_id)(last_irreversible_block_num)(last_irreversible_block_id)(code_hash)(pending_transactions)(result) )

FC_REFLECT( eosio::chain_apis::read_only::get_all_accounts_params, (limit)(lower_bound)(upper_bound)(reverse) )
FC_REFLECT( eosio::chain_apis::read_only::get_all_accounts_result::account_result, (name)(creation_date))
FC_REFLECT( eosio::chain_apis::read_only::get_all_accounts_result, (accounts)(more))
3 changes: 2 additions & 1 deletion scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ configure_file(eosio-tn_down.sh eosio-tn_down.sh COPYONLY)
configure_file(eosio-tn_roll.sh eosio-tn_roll.sh COPYONLY)
configure_file(eosio-tn_up.sh eosio-tn_up.sh COPYONLY)
configure_file(abi_is_json.py abi_is_json.py COPYONLY)
configure_file(postgres_control.sh postgres_control.sh COPYONLY)
configure_file(postgres_control.sh postgres_control.sh COPYONLY)
configure_file(blockchain_audit_tool.py blockchain_audit_tool.py COPYONLY)
Loading