From d449c8d5709fb596987d29cb24bbfbb4e6efda7a Mon Sep 17 00:00:00 2001 From: adsorptionenthalpy Date: Tue, 26 May 2020 12:58:19 -0600 Subject: [PATCH 01/22] Add get_transfers endpoint --- .../history_api_plugin/history_api_plugin.cpp | 3 +- plugins/history_plugin/history_plugin.cpp | 108 +++++++++++++++++- .../eosio/history_plugin/history_plugin.hpp | 17 ++- 3 files changed, 125 insertions(+), 3 deletions(-) diff --git a/plugins/history_api_plugin/history_api_plugin.cpp b/plugins/history_api_plugin/history_api_plugin.cpp index b1a0cb0e15..ed1620f85b 100644 --- a/plugins/history_api_plugin/history_api_plugin.cpp +++ b/plugins/history_api_plugin/history_api_plugin.cpp @@ -47,7 +47,8 @@ namespace eosio { CHAIN_RO_CALL(get_transaction), CHAIN_RO_CALL(get_block_txids), CHAIN_RO_CALL(get_key_accounts), - CHAIN_RO_CALL(get_controlled_accounts) + CHAIN_RO_CALL(get_controlled_accounts), + CHAIN_RO_CALL(get_transfers) }); } diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index 1b94437b5b..d8f48f11b1 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -509,6 +509,7 @@ namespace eosio { get_actions_result result; result.last_irreversible_block = chain.last_irreversible_block_num(); + digest_type ad; while (start_itr != end_itr) { uint64_t action_sequence_num; int64_t account_sequence_num; @@ -549,9 +550,114 @@ namespace eosio { } } return result; - } + } //get actions + + read_only::get_transfers_result read_only::get_transfers(const read_only::get_transfers_params ¶ms) const { + // edump((params)); + auto &chain = history->chain_plug->chain(); + const auto& hdb = chain.hdb(); + const auto& hidb = chain.hidb(); + const auto abi_serializer_max_time = history->chain_plug->get_abi_serializer_max_time(); + const auto& idx = hidb.get_index(); + + int64_t start = 0; + int64_t pos = params.pos ? *params.pos : -1; + int64_t end = 0; + int64_t offset = params.offset ? *params.offset : -20; + auto n = params.account_name; + // idump((pos)); + if (pos == -1) { + auto itr = idx.lower_bound(boost::make_tuple(name(n.value + 1), 0)); + if (itr == idx.begin()) { + if (itr->account == n) + pos = itr->account_sequence_num + 1; + } else if (itr != idx.begin()) --itr; + + if (itr->account == n) + pos = itr->account_sequence_num + 1; + } + + if (pos == -1) pos = 0xfffffffffffffff; + + if (offset > 0) { + start = pos; + end = start + offset; + } else { + start = pos + offset; + if (start > pos) start = 0; + end = pos; + } + EOS_ASSERT(end >= start, chain::plugin_exception, "end position is earlier than start position"); + + // idump((start)(end)); + + // Find latest stored action (will have lowest available ACCOUNT seq number) + const auto max_itr = idx.lower_bound( boost::make_tuple( n, 0 ) ); + const auto min_seq_number = max_itr->account_sequence_num; + if (min_seq_number > 0) { // Reject outside of retention policy boundary. + const auto max_seq_number = min_seq_number + history->history_per_account; + EOS_ASSERT( start >= min_seq_number, chain::plugin_range_not_satisfiable, "start position is earlier than account retention policy (${p}). Latest available: ${l}. Requested start: ${r}", ("p",history->history_per_account)("l",min_seq_number)("r",start) ); + // Below should actually never occur..? + EOS_ASSERT( end >= min_seq_number, chain::plugin_range_not_satisfiable, "end position is earlier than account retention policy (${p}). Latest available: ${l}. Requested end: ${r}", ("p",history->history_per_account)("l",min_seq_number)("r",end) ); + } + auto start_itr = idx.lower_bound(boost::make_tuple(n, start)); + auto end_itr = idx.upper_bound(boost::make_tuple(n, end)); + + auto start_time = fc::time_point::now(); + auto end_time = start_time; + + get_transfers_result result; + result.last_irreversible_block = chain.last_irreversible_block_num(); + digest_type ad; + while (start_itr != end_itr) { + uint64_t action_sequence_num; + int64_t account_sequence_num; + if (params.pos < 0) { + --end_itr; + action_sequence_num = end_itr->action_sequence_num; + account_sequence_num = end_itr->account_sequence_num; + } else { + action_sequence_num = start_itr->action_sequence_num; + account_sequence_num = start_itr->account_sequence_num; + ++start_itr; + } + + const auto& a = hdb.get( action_sequence_num ); + fc::datastream ds(a.packed_action_trace.data(), a.packed_action_trace.size()); + action_trace t; + fc::raw::unpack(ds, t); + if (ad == t.receipt->act_digest) { + if (t.receipt->receiver != params.account_name) { + continue; + } + } + ad = t.receipt->act_digest; + if (params.pos < 0) { + result.actions.emplace(result.actions.begin(), ordered_action_result{ + action_sequence_num, + account_sequence_num, + a.block_num, a.block_time, + chain.to_variant_with_abi(t, abi_serializer_max_time) + }); + } else { + result.actions.emplace_back( ordered_action_result{ + action_sequence_num, + account_sequence_num, + a.block_num, a.block_time, + chain.to_variant_with_abi(t, abi_serializer_max_time) + }); + } + + end_time = fc::time_point::now(); + if (end_time - start_time > fc::microseconds(100000)) { + result.time_limit_exceeded_error = true; + break; + } + } + return result; + } //get actions read_only::get_transaction_result read_only::get_transaction(const read_only::get_transaction_params &p) const { auto &chain = history->chain_plug->chain(); const auto abi_serializer_max_time = history->chain_plug->get_abi_serializer_max_time(); diff --git a/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp b/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp index 38bf64d29c..f03d75f613 100644 --- a/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp +++ b/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp @@ -50,9 +50,21 @@ namespace eosio { uint32_t last_irreversible_block; optional time_limit_exceeded_error; }; + get_actions_result get_actions(const get_actions_params &) const; + struct get_transfers_params { + chain::account_name account_name; + optional pos; /// a absolute sequence positon -1 is the end/last action + optional offset; ///< the number of actions relative to pos, negative numbers return [pos-offset,pos), positive numbers return [pos,pos+offset) + }; - get_actions_result get_actions(const get_actions_params &) const; + struct get_transfers_result { + vector actions; + uint32_t last_irreversible_block; + optional time_limit_exceeded_error; + }; + + get_transfers_result get_transfers(const get_transfers_params &) const; struct get_transaction_params { @@ -152,6 +164,9 @@ namespace eosio { FC_REFLECT(eosio::history_apis::read_only::get_actions_params, (account_name)(pos)(offset)) FC_REFLECT(eosio::history_apis::read_only::get_actions_result, (actions)(last_irreversible_block)(time_limit_exceeded_error)) +FC_REFLECT(eosio::history_apis::read_only::get_transfers_params, (account_name)(pos)(offset)) +FC_REFLECT(eosio::history_apis::read_only::get_transfers_result, + (actions)(last_irreversible_block)(time_limit_exceeded_error)) FC_REFLECT(eosio::history_apis::read_only::ordered_action_result, (global_action_seq)(account_action_seq)(block_num)(block_time)(action_trace)) From 241db07eb1b00f9422ad04f11449cbeb3b3b3bfe Mon Sep 17 00:00:00 2001 From: adsorptionenthalpy Date: Tue, 26 May 2020 13:24:31 -0600 Subject: [PATCH 02/22] remove unused digest_type --- plugins/history_plugin/history_plugin.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index d8f48f11b1..970afe22d1 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -509,7 +509,6 @@ namespace eosio { get_actions_result result; result.last_irreversible_block = chain.last_irreversible_block_num(); - digest_type ad; while (start_itr != end_itr) { uint64_t action_sequence_num; int64_t account_sequence_num; From a56f45b7a21edb536834aaa22f3b8e6beb127ee1 Mon Sep 17 00:00:00 2001 From: adsorptionenthalpy Date: Wed, 27 May 2020 19:58:47 -0600 Subject: [PATCH 03/22] make get_transfers return specific transfer information --- .../include/eosio/chain/contract_types.hpp | 17 +++++ plugins/history_plugin/history_plugin.cpp | 72 ++++++++++++++----- .../eosio/history_plugin/history_plugin.hpp | 20 +++++- 3 files changed, 91 insertions(+), 18 deletions(-) diff --git a/libraries/chain/include/eosio/chain/contract_types.hpp b/libraries/chain/include/eosio/chain/contract_types.hpp index 6a64cdc895..e4ceadf287 100644 --- a/libraries/chain/include/eosio/chain/contract_types.hpp +++ b/libraries/chain/include/eosio/chain/contract_types.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace eosio { namespace chain { @@ -25,6 +26,21 @@ namespace eosio { } }; + struct transfer { + name from; + name to; + eosio::chain::asset quantity; + string memo; + + static account_name get_account() { + return N(fio.token); + } + + static action_name get_name() { + return N(transfer); + } + }; + struct trnsfiopubky { string payee_public_key; int64_t amount; @@ -257,3 +273,4 @@ FC_REFLECT(eosio::chain::regaddress, (fio_address)(owner_fio_public_key)(max_fee FC_REFLECT(eosio::chain::regdomain, (fio_domain)(owner_fio_public_key)(max_fee)(actor)(tpid)) FC_REFLECT(eosio::chain::xferdomain, (fio_domain)(new_owner_fio_public_key)(max_fee)(actor)(tpid)) FC_REFLECT(eosio::chain::xferaddress, (fio_address)(new_owner_fio_public_key)(max_fee)(actor)(tpid)) +FC_REFLECT(eosio::chain::transfer, (from)(to)(quantity)(memo)) diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index 970afe22d1..e0f134f5ab 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -607,9 +607,10 @@ namespace eosio { auto start_time = fc::time_point::now(); auto end_time = start_time; + get_actions_result action_result; get_transfers_result result; - result.last_irreversible_block = chain.last_irreversible_block_num(); - digest_type ad; + + action_result.last_irreversible_block = chain.last_irreversible_block_num(); while (start_itr != end_itr) { uint64_t action_sequence_num; int64_t account_sequence_num; @@ -627,34 +628,73 @@ namespace eosio { fc::datastream ds(a.packed_action_trace.data(), a.packed_action_trace.size()); action_trace t; fc::raw::unpack(ds, t); - if (ad == t.receipt->act_digest) { - if (t.receipt->receiver != params.account_name) { - continue; + if (t.receipt->receiver == params.account_name) { // skip emplacing results where receiver field does not match account_name parameter + + transfer_information ti; + ti.transaction_id = t.trx_id; + ti.block_height = t.block_num; + ti.block_time = t.block_time; + + if (t.act.name == N(trnsfiopubky)) { + const auto transferdata = t.act.data_as(); + ti.action = "trnsfiopubky"; + ti.tpid = transferdata.tpid; + ti.memo = ""; + ti.sender = transferdata.actor.to_string(); + ti.receiver = fioio::key_to_account(transferdata.payee_public_key); + ti.payee_public_key = transferdata.payee_public_key; + ti.fee_amount = transferdata.max_fee; + //ti.fee_amount = t.receipt->response; // this needs parsed for fee paid value + ti.transaction_total = transferdata.max_fee + transferdata.amount; //max_fee temporary + ti.transfer_amount = transferdata.amount ; } - } - ad = t.receipt->act_digest; - if (params.pos < 0) { - result.actions.emplace(result.actions.begin(), ordered_action_result{ + if (t.act.name == N(transfer)) { + const auto transferdata = t.act.data_as(); + ti.action = "transfer"; + ti.tpid = ""; + ti.memo = transferdata.memo; + ti.sender = transferdata.from.to_string(); + ti.receiver = transferdata.to.to_string(); + ti.payee_public_key = ""; + ti.fee_amount = 0; + ti.transaction_total = transferdata.quantity.get_amount(); + ti.transfer_amount = transferdata.quantity.get_amount() ; + } + if (params.pos < 0) { + + result.transfers.emplace(result.transfers.begin(), ti ); + + } else { + + result.transfers.emplace_back( ti ); + + /* + action_result.actions.emplace(action_result.actions.begin(), ordered_action_result{ action_sequence_num, account_sequence_num, a.block_num, a.block_time, chain.to_variant_with_abi(t, abi_serializer_max_time) }); } else { - result.actions.emplace_back( ordered_action_result{ + action_result.actions.emplace_back( ordered_action_result{ action_sequence_num, account_sequence_num, a.block_num, a.block_time, chain.to_variant_with_abi(t, abi_serializer_max_time) - }); - } + }); */ + } + + /* DISABLING THE LOOKUP TIME LIMIT + end_time = fc::time_point::now(); + if (end_time - start_time > fc::microseconds(100000)) { + action_result.time_limit_exceeded_error = true; + break; + } + */ - end_time = fc::time_point::now(); - if (end_time - start_time > fc::microseconds(100000)) { - result.time_limit_exceeded_error = true; - break; } } + return result; } //get actions read_only::get_transaction_result read_only::get_transaction(const read_only::get_transaction_params &p) const { diff --git a/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp b/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp index f03d75f613..294bb0e063 100644 --- a/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp +++ b/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp @@ -58,8 +58,23 @@ namespace eosio { optional offset; ///< the number of actions relative to pos, negative numbers return [pos-offset,pos), positive numbers return [pos,pos+offset) }; + struct transfer_information { + uint32_t block_height; + chain::block_timestamp_type block_time; + string receiver; + string sender; + string payee_public_key; + uint64_t transfer_amount; + uint64_t fee_amount; + uint64_t transaction_total; + string memo; + string action; + string tpid; + string transaction_id; + }; + struct get_transfers_result { - vector actions; + vector transfers; uint32_t last_irreversible_block; optional time_limit_exceeded_error; }; @@ -166,7 +181,8 @@ FC_REFLECT(eosio::history_apis::read_only::get_actions_result, (actions)(last_irreversible_block)(time_limit_exceeded_error)) FC_REFLECT(eosio::history_apis::read_only::get_transfers_params, (account_name)(pos)(offset)) FC_REFLECT(eosio::history_apis::read_only::get_transfers_result, - (actions)(last_irreversible_block)(time_limit_exceeded_error)) + (transfers)(last_irreversible_block)(time_limit_exceeded_error)) +FC_REFLECT(eosio::history_apis::read_only::transfer_information,) FC_REFLECT(eosio::history_apis::read_only::ordered_action_result, (global_action_seq)(account_action_seq)(block_num)(block_time)(action_trace)) From 59b9621826a99ae228391b7a7ff16c9c147fdb56 Mon Sep 17 00:00:00 2001 From: adsorptionenthalpy Date: Wed, 27 May 2020 20:06:39 -0600 Subject: [PATCH 04/22] Add transfer_information members to FC REFLECT --- .../include/eosio/history_plugin/history_plugin.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp b/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp index 294bb0e063..70b3849115 100644 --- a/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp +++ b/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp @@ -182,7 +182,9 @@ FC_REFLECT(eosio::history_apis::read_only::get_actions_result, FC_REFLECT(eosio::history_apis::read_only::get_transfers_params, (account_name)(pos)(offset)) FC_REFLECT(eosio::history_apis::read_only::get_transfers_result, (transfers)(last_irreversible_block)(time_limit_exceeded_error)) -FC_REFLECT(eosio::history_apis::read_only::transfer_information,) +FC_REFLECT(eosio::history_apis::read_only::transfer_information, (block_height) + (block_time)(receiver)(sender)(payee_public_key)(transfer_amount)(fee_amount) + (transaction_total)(memo)(action)(tpid)(transaction_id) ) FC_REFLECT(eosio::history_apis::read_only::ordered_action_result, (global_action_seq)(account_action_seq)(block_num)(block_time)(action_trace)) From eaa17efdc0742ddcbc5bc5b9e69e0a3d87857f16 Mon Sep 17 00:00:00 2001 From: adsorptionenthalpy Date: Thu, 28 May 2020 10:00:54 -0600 Subject: [PATCH 05/22] Add get_transfers support for xferdomain/xferaddress --- plugins/history_plugin/history_plugin.cpp | 30 +++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index e0f134f5ab..729659b20a 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -609,7 +609,7 @@ namespace eosio { get_actions_result action_result; get_transfers_result result; - + result.last_irreversible_block = chain.last_irreversible_block_num(); action_result.last_irreversible_block = chain.last_irreversible_block_num(); while (start_itr != end_itr) { uint64_t action_sequence_num; @@ -656,10 +656,36 @@ namespace eosio { ti.sender = transferdata.from.to_string(); ti.receiver = transferdata.to.to_string(); ti.payee_public_key = ""; - ti.fee_amount = 0; + ti.fee_amount = 0; // there is no fee for C2U/U2C transfers ti.transaction_total = transferdata.quantity.get_amount(); ti.transfer_amount = transferdata.quantity.get_amount() ; } + if (t.act.name == N(xferdomain)) { + const auto transferdata = t.act.data_as(); + ti.action = "xferdomain"; + ti.tpid = transferdata.tpid; + ti.memo = std::string("Transferred domain " ) + transferdata.fio_domain; + ti.sender = transferdata.actor.to_string(); + ti.receiver = fioio::key_to_account(transferdata.new_owner_fio_public_key); + ti.payee_public_key = transferdata.new_owner_fio_public_key; + ti.fee_amount = transferdata.max_fee; + //ti.fee_amount = t.receipt->response; // this needs parsed for fee paid value + ti.transaction_total = ti.fee_amount; + ti.transfer_amount = 0; + } + if (t.act.name == N(xferaddress)) { + const auto transferdata = t.act.data_as(); + ti.action = "xferaddress"; + ti.tpid = transferdata.tpid; + ti.memo = std::string("Transferred address " ) + transferdata.fio_address; + ti.sender = transferdata.actor.to_string(); + ti.receiver = fioio::key_to_account(transferdata.new_owner_fio_public_key); + ti.payee_public_key = transferdata.new_owner_fio_public_key; + ti.fee_amount = transferdata.max_fee; + //ti.fee_amount = t.receipt->response; // this needs parsed for fee paid value + ti.transaction_total = ti.fee_amount; + ti.transfer_amount = 0; + } if (params.pos < 0) { result.transfers.emplace(result.transfers.begin(), ti ); From 1887a6d0fddc9273d531b95fa32dda4e9e4bf632 Mon Sep 17 00:00:00 2001 From: adsorptionenthalpy Date: Thu, 28 May 2020 10:38:04 -0600 Subject: [PATCH 06/22] Skip over emplacing unprocessed transcation information --- plugins/history_plugin/history_plugin.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index 729659b20a..d3b98d6652 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -647,8 +647,7 @@ namespace eosio { //ti.fee_amount = t.receipt->response; // this needs parsed for fee paid value ti.transaction_total = transferdata.max_fee + transferdata.amount; //max_fee temporary ti.transfer_amount = transferdata.amount ; - } - if (t.act.name == N(transfer)) { + } else if (t.act.name == N(transfer)) { const auto transferdata = t.act.data_as(); ti.action = "transfer"; ti.tpid = ""; @@ -659,8 +658,7 @@ namespace eosio { ti.fee_amount = 0; // there is no fee for C2U/U2C transfers ti.transaction_total = transferdata.quantity.get_amount(); ti.transfer_amount = transferdata.quantity.get_amount() ; - } - if (t.act.name == N(xferdomain)) { + } else if (t.act.name == N(xferdomain)) { const auto transferdata = t.act.data_as(); ti.action = "xferdomain"; ti.tpid = transferdata.tpid; @@ -672,8 +670,7 @@ namespace eosio { //ti.fee_amount = t.receipt->response; // this needs parsed for fee paid value ti.transaction_total = ti.fee_amount; ti.transfer_amount = 0; - } - if (t.act.name == N(xferaddress)) { + } else if (t.act.name == N(xferaddress)) { const auto transferdata = t.act.data_as(); ti.action = "xferaddress"; ti.tpid = transferdata.tpid; @@ -685,7 +682,9 @@ namespace eosio { //ti.fee_amount = t.receipt->response; // this needs parsed for fee paid value ti.transaction_total = ti.fee_amount; ti.transfer_amount = 0; - } + } else { + continue; // Do not process any other transaction types + } if (params.pos < 0) { result.transfers.emplace(result.transfers.begin(), ti ); From 50b41a217e78d0e2d452a90d4a2e3833d56c15fe Mon Sep 17 00:00:00 2001 From: adsorptionenthalpy Date: Thu, 28 May 2020 16:31:09 -0600 Subject: [PATCH 07/22] parse json response for fee_amount --- plugins/history_plugin/history_plugin.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index d3b98d6652..a90f9ff5e5 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -643,9 +643,8 @@ namespace eosio { ti.sender = transferdata.actor.to_string(); ti.receiver = fioio::key_to_account(transferdata.payee_public_key); ti.payee_public_key = transferdata.payee_public_key; - ti.fee_amount = transferdata.max_fee; - //ti.fee_amount = t.receipt->response; // this needs parsed for fee paid value - ti.transaction_total = transferdata.max_fee + transferdata.amount; //max_fee temporary + ti.fee_amount = boost::lexical_cast(t.receipt->response.substr(t.receipt->response.find("d\\\""), t.receipt->response.find("\"}"))); + ti.transaction_total = ti.fee_amount + transferdata.amount; ti.transfer_amount = transferdata.amount ; } else if (t.act.name == N(transfer)) { const auto transferdata = t.act.data_as(); @@ -666,7 +665,7 @@ namespace eosio { ti.sender = transferdata.actor.to_string(); ti.receiver = fioio::key_to_account(transferdata.new_owner_fio_public_key); ti.payee_public_key = transferdata.new_owner_fio_public_key; - ti.fee_amount = transferdata.max_fee; + ti.fee_amount = boost::lexical_cast(t.receipt->response.substr(t.receipt->response.find("d\\\""), t.receipt->response.find("\"}"))); //ti.fee_amount = t.receipt->response; // this needs parsed for fee paid value ti.transaction_total = ti.fee_amount; ti.transfer_amount = 0; @@ -678,7 +677,7 @@ namespace eosio { ti.sender = transferdata.actor.to_string(); ti.receiver = fioio::key_to_account(transferdata.new_owner_fio_public_key); ti.payee_public_key = transferdata.new_owner_fio_public_key; - ti.fee_amount = transferdata.max_fee; + ti.fee_amount = boost::lexical_cast(t.receipt->response.substr(t.receipt->response.find("d\\\""), t.receipt->response.find("\"}"))); //ti.fee_amount = t.receipt->response; // this needs parsed for fee paid value ti.transaction_total = ti.fee_amount; ti.transfer_amount = 0; From 196d6071a1e275e8abf023da955a82d8486325c2 Mon Sep 17 00:00:00 2001 From: Myname Date: Fri, 29 May 2020 02:51:57 +0000 Subject: [PATCH 08/22] work on fee extraction --- plugins/history_plugin/history_plugin.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index a90f9ff5e5..8df5bd6cdc 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -122,6 +122,14 @@ namespace eosio { } } + //Used to retrieve the fee paid from action_trace.receipt->response + static const uint64_t extract_fee (const action_trace &t) { + const string &extract = t.receipt->response.substr(t.receipt->response.find("d\":") + 3, + std::numeric_limits::max()); + const string &fee = extract.substr(0, extract.find("}")); + return boost::lexical_cast(fee); + } + struct filter_entry { name receiver; name action; @@ -643,7 +651,7 @@ namespace eosio { ti.sender = transferdata.actor.to_string(); ti.receiver = fioio::key_to_account(transferdata.payee_public_key); ti.payee_public_key = transferdata.payee_public_key; - ti.fee_amount = boost::lexical_cast(t.receipt->response.substr(t.receipt->response.find("d\\\""), t.receipt->response.find("\"}"))); + ti.fee_amount = extract_fee(t); ti.transaction_total = ti.fee_amount + transferdata.amount; ti.transfer_amount = transferdata.amount ; } else if (t.act.name == N(transfer)) { @@ -665,8 +673,7 @@ namespace eosio { ti.sender = transferdata.actor.to_string(); ti.receiver = fioio::key_to_account(transferdata.new_owner_fio_public_key); ti.payee_public_key = transferdata.new_owner_fio_public_key; - ti.fee_amount = boost::lexical_cast(t.receipt->response.substr(t.receipt->response.find("d\\\""), t.receipt->response.find("\"}"))); - //ti.fee_amount = t.receipt->response; // this needs parsed for fee paid value + ti.fee_amount = extract_fee(t); ti.transaction_total = ti.fee_amount; ti.transfer_amount = 0; } else if (t.act.name == N(xferaddress)) { @@ -677,8 +684,7 @@ namespace eosio { ti.sender = transferdata.actor.to_string(); ti.receiver = fioio::key_to_account(transferdata.new_owner_fio_public_key); ti.payee_public_key = transferdata.new_owner_fio_public_key; - ti.fee_amount = boost::lexical_cast(t.receipt->response.substr(t.receipt->response.find("d\\\""), t.receipt->response.find("\"}"))); - //ti.fee_amount = t.receipt->response; // this needs parsed for fee paid value + ti.fee_amount = extract_fee(t); ti.transaction_total = ti.fee_amount; ti.transfer_amount = 0; } else { @@ -720,7 +726,10 @@ namespace eosio { } return result; - } //get actions + + } + + //get actions read_only::get_transaction_result read_only::get_transaction(const read_only::get_transaction_params &p) const { auto &chain = history->chain_plug->chain(); const auto abi_serializer_max_time = history->chain_plug->get_abi_serializer_max_time(); From 54d0566bc197ebb99ff5dd26bb6b095019627f59 Mon Sep 17 00:00:00 2001 From: Myname Date: Fri, 29 May 2020 21:35:23 +0000 Subject: [PATCH 09/22] alter transaction record names to use payee/payer, use public key for lookup param --- plugins/history_plugin/history_plugin.cpp | 40 +++++-------------- .../eosio/history_plugin/history_plugin.hpp | 14 +++---- 2 files changed, 16 insertions(+), 38 deletions(-) diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index 8df5bd6cdc..846f48a99d 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -567,12 +567,12 @@ namespace eosio { const auto abi_serializer_max_time = history->chain_plug->get_abi_serializer_max_time(); const auto& idx = hidb.get_index(); - + account_name account_name = fioio::key_to_account(params.fio_public_key); int64_t start = 0; int64_t pos = params.pos ? *params.pos : -1; int64_t end = 0; int64_t offset = params.offset ? *params.offset : -20; - auto n = params.account_name; + auto n = account_name; // idump((pos)); if (pos == -1) { auto itr = idx.lower_bound(boost::make_tuple(name(n.value + 1), 0)); @@ -636,7 +636,7 @@ namespace eosio { fc::datastream ds(a.packed_action_trace.data(), a.packed_action_trace.size()); action_trace t; fc::raw::unpack(ds, t); - if (t.receipt->receiver == params.account_name) { // skip emplacing results where receiver field does not match account_name parameter + if (t.receipt->receiver == account_name) { // skip emplacing results where receiver field does not match account_name parameter transfer_information ti; ti.transaction_id = t.trx_id; @@ -647,9 +647,9 @@ namespace eosio { const auto transferdata = t.act.data_as(); ti.action = "trnsfiopubky"; ti.tpid = transferdata.tpid; - ti.memo = ""; - ti.sender = transferdata.actor.to_string(); - ti.receiver = fioio::key_to_account(transferdata.payee_public_key); + ti.note = "FIO Transfer"; + ti.payer = transferdata.actor.to_string(); + ti.payee = fioio::key_to_account(transferdata.payee_public_key); ti.payee_public_key = transferdata.payee_public_key; ti.fee_amount = extract_fee(t); ti.transaction_total = ti.fee_amount + transferdata.amount; @@ -658,35 +658,13 @@ namespace eosio { const auto transferdata = t.act.data_as(); ti.action = "transfer"; ti.tpid = ""; - ti.memo = transferdata.memo; - ti.sender = transferdata.from.to_string(); - ti.receiver = transferdata.to.to_string(); + ti.note = transferdata.memo; + ti.payer = transferdata.from.to_string(); + ti.payee = transferdata.to.to_string(); ti.payee_public_key = ""; ti.fee_amount = 0; // there is no fee for C2U/U2C transfers ti.transaction_total = transferdata.quantity.get_amount(); ti.transfer_amount = transferdata.quantity.get_amount() ; - } else if (t.act.name == N(xferdomain)) { - const auto transferdata = t.act.data_as(); - ti.action = "xferdomain"; - ti.tpid = transferdata.tpid; - ti.memo = std::string("Transferred domain " ) + transferdata.fio_domain; - ti.sender = transferdata.actor.to_string(); - ti.receiver = fioio::key_to_account(transferdata.new_owner_fio_public_key); - ti.payee_public_key = transferdata.new_owner_fio_public_key; - ti.fee_amount = extract_fee(t); - ti.transaction_total = ti.fee_amount; - ti.transfer_amount = 0; - } else if (t.act.name == N(xferaddress)) { - const auto transferdata = t.act.data_as(); - ti.action = "xferaddress"; - ti.tpid = transferdata.tpid; - ti.memo = std::string("Transferred address " ) + transferdata.fio_address; - ti.sender = transferdata.actor.to_string(); - ti.receiver = fioio::key_to_account(transferdata.new_owner_fio_public_key); - ti.payee_public_key = transferdata.new_owner_fio_public_key; - ti.fee_amount = extract_fee(t); - ti.transaction_total = ti.fee_amount; - ti.transfer_amount = 0; } else { continue; // Do not process any other transaction types } diff --git a/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp b/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp index 70b3849115..d487cafb2f 100644 --- a/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp +++ b/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp @@ -53,7 +53,7 @@ namespace eosio { get_actions_result get_actions(const get_actions_params &) const; struct get_transfers_params { - chain::account_name account_name; + string fio_public_key; optional pos; /// a absolute sequence positon -1 is the end/last action optional offset; ///< the number of actions relative to pos, negative numbers return [pos-offset,pos), positive numbers return [pos,pos+offset) }; @@ -61,13 +61,13 @@ namespace eosio { struct transfer_information { uint32_t block_height; chain::block_timestamp_type block_time; - string receiver; - string sender; + string payer; + string payee; string payee_public_key; uint64_t transfer_amount; uint64_t fee_amount; uint64_t transaction_total; - string memo; + string note; string action; string tpid; string transaction_id; @@ -179,12 +179,12 @@ namespace eosio { FC_REFLECT(eosio::history_apis::read_only::get_actions_params, (account_name)(pos)(offset)) FC_REFLECT(eosio::history_apis::read_only::get_actions_result, (actions)(last_irreversible_block)(time_limit_exceeded_error)) -FC_REFLECT(eosio::history_apis::read_only::get_transfers_params, (account_name)(pos)(offset)) +FC_REFLECT(eosio::history_apis::read_only::get_transfers_params, (fio_public_key)(pos)(offset)) FC_REFLECT(eosio::history_apis::read_only::get_transfers_result, (transfers)(last_irreversible_block)(time_limit_exceeded_error)) FC_REFLECT(eosio::history_apis::read_only::transfer_information, (block_height) - (block_time)(receiver)(sender)(payee_public_key)(transfer_amount)(fee_amount) - (transaction_total)(memo)(action)(tpid)(transaction_id) ) + (block_time)(payer)(payee)(payee_public_key)(transfer_amount)(fee_amount) + (transaction_total)(note)(action)(tpid)(transaction_id) ) FC_REFLECT(eosio::history_apis::read_only::ordered_action_result, (global_action_seq)(account_action_seq)(block_num)(block_time)(action_trace)) From 87af0e623a0b239c099c15a19af9db9f39a7a773 Mon Sep 17 00:00:00 2001 From: Adam Androulidakis Date: Tue, 9 Jun 2020 13:53:14 -0600 Subject: [PATCH 10/22] Except subtransfers after trnsfiopbky (dup trx id handling) --- plugins/history_plugin/history_plugin.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index 846f48a99d..bbedd1bbb4 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -619,6 +619,8 @@ namespace eosio { get_transfers_result result; result.last_irreversible_block = chain.last_irreversible_block_num(); action_result.last_irreversible_block = chain.last_irreversible_block_num(); + fc::sha256 previoustrxid; + bool subtransfer = false; while (start_itr != end_itr) { uint64_t action_sequence_num; int64_t account_sequence_num; @@ -644,6 +646,7 @@ namespace eosio { ti.block_time = t.block_time; if (t.act.name == N(trnsfiopubky)) { + previoustrxid = t.trx_id; const auto transferdata = t.act.data_as(); ti.action = "trnsfiopubky"; ti.tpid = transferdata.tpid; @@ -653,8 +656,9 @@ namespace eosio { ti.payee_public_key = transferdata.payee_public_key; ti.fee_amount = extract_fee(t); ti.transaction_total = ti.fee_amount + transferdata.amount; - ti.transfer_amount = transferdata.amount ; - } else if (t.act.name == N(transfer)) { + ti.transfer_amount = transferdata.amount; + subtransfer = true; + } else if (t.act.name == N(transfer) && previoustrxid != t.trx_id && !subtransfer) { const auto transferdata = t.act.data_as(); ti.action = "transfer"; ti.tpid = ""; @@ -666,6 +670,7 @@ namespace eosio { ti.transaction_total = transferdata.quantity.get_amount(); ti.transfer_amount = transferdata.quantity.get_amount() ; } else { + subtransfer = false; continue; // Do not process any other transaction types } if (params.pos < 0) { From a588b99006a63650aafe09df12e56f656c8e7041 Mon Sep 17 00:00:00 2001 From: Adam Androulidakis Date: Tue, 9 Jun 2020 16:24:58 -0600 Subject: [PATCH 11/22] Rewrite logic, bugfix --- plugins/history_plugin/history_plugin.cpp | 93 +++++++++-------------- 1 file changed, 38 insertions(+), 55 deletions(-) diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index bbedd1bbb4..435c583c30 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -620,7 +620,6 @@ namespace eosio { result.last_irreversible_block = chain.last_irreversible_block_num(); action_result.last_irreversible_block = chain.last_irreversible_block_num(); fc::sha256 previoustrxid; - bool subtransfer = false; while (start_itr != end_itr) { uint64_t action_sequence_num; int64_t account_sequence_num; @@ -644,58 +643,44 @@ namespace eosio { ti.transaction_id = t.trx_id; ti.block_height = t.block_num; ti.block_time = t.block_time; - - if (t.act.name == N(trnsfiopubky)) { - previoustrxid = t.trx_id; - const auto transferdata = t.act.data_as(); - ti.action = "trnsfiopubky"; - ti.tpid = transferdata.tpid; - ti.note = "FIO Transfer"; - ti.payer = transferdata.actor.to_string(); - ti.payee = fioio::key_to_account(transferdata.payee_public_key); - ti.payee_public_key = transferdata.payee_public_key; - ti.fee_amount = extract_fee(t); - ti.transaction_total = ti.fee_amount + transferdata.amount; - ti.transfer_amount = transferdata.amount; - subtransfer = true; - } else if (t.act.name == N(transfer) && previoustrxid != t.trx_id && !subtransfer) { - const auto transferdata = t.act.data_as(); - ti.action = "transfer"; - ti.tpid = ""; - ti.note = transferdata.memo; - ti.payer = transferdata.from.to_string(); - ti.payee = transferdata.to.to_string(); - ti.payee_public_key = ""; - ti.fee_amount = 0; // there is no fee for C2U/U2C transfers - ti.transaction_total = transferdata.quantity.get_amount(); - ti.transfer_amount = transferdata.quantity.get_amount() ; - } else { - subtransfer = false; - continue; // Do not process any other transaction types - } - if (params.pos < 0) { - - result.transfers.emplace(result.transfers.begin(), ti ); - - } else { - - result.transfers.emplace_back( ti ); - - /* - action_result.actions.emplace(action_result.actions.begin(), ordered_action_result{ - action_sequence_num, - account_sequence_num, - a.block_num, a.block_time, - chain.to_variant_with_abi(t, abi_serializer_max_time) - }); - } else { - action_result.actions.emplace_back( ordered_action_result{ - action_sequence_num, - account_sequence_num, - a.block_num, a.block_time, - chain.to_variant_with_abi(t, abi_serializer_max_time) - }); */ + if(previoustrxid != t.trx_id) { + if (t.act.name == N(trnsfiopubky)) { + const auto transferdata = t.act.data_as(); + ti.action = "trnsfiopubky"; + ti.tpid = transferdata.tpid; + ti.note = "FIO Transfer"; + ti.payer = transferdata.actor.to_string(); + ti.payee = fioio::key_to_account(transferdata.payee_public_key); + ti.payee_public_key = transferdata.payee_public_key; + ti.fee_amount = extract_fee(t); + ti.transaction_total = ti.fee_amount + transferdata.amount; + ti.transfer_amount = transferdata.amount; + if (params.pos < 0) { + result.transfers.emplace(result.transfers.begin(), ti ); + } else { + result.transfers.emplace_back( ti ); + } + } + else if (t.act.name == N(transfer)) { + const auto transferdata = t.act.data_as(); + ti.action = "transfer"; + ti.tpid = ""; + ti.note = transferdata.memo; + ti.payer = transferdata.from.to_string(); + ti.payee = transferdata.to.to_string(); + ti.payee_public_key = ""; + ti.fee_amount = 0; // there is no fee for C2U/U2C transfers + ti.transaction_total = transferdata.quantity.get_amount(); + ti.transfer_amount = transferdata.quantity.get_amount(); + if (params.pos < 0) { + result.transfers.emplace(result.transfers.begin(), ti ); + } else { + result.transfers.emplace_back( ti ); + } + } } + previoustrxid = t.trx_id; + } /* DISABLING THE LOOKUP TIME LIMIT end_time = fc::time_point::now(); @@ -705,11 +690,9 @@ namespace eosio { } */ - } - } + } // while return result; - } //get actions From c19259d3670634134688d2afb7a4aa7943499b04 Mon Sep 17 00:00:00 2001 From: Adam Androulidakis Date: Tue, 16 Jun 2020 13:54:18 -0600 Subject: [PATCH 12/22] Enable lookup time limit, limit by 100000 us * 3, increase max sequence numbers 1000 * 3 --- plugins/history_plugin/history_plugin.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index 435c583c30..795c845364 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -603,7 +603,7 @@ namespace eosio { const auto max_itr = idx.lower_bound( boost::make_tuple( n, 0 ) ); const auto min_seq_number = max_itr->account_sequence_num; if (min_seq_number > 0) { // Reject outside of retention policy boundary. - const auto max_seq_number = min_seq_number + history->history_per_account; + const auto max_seq_number = min_seq_number + history->history_per_account * 3; EOS_ASSERT( start >= min_seq_number, chain::plugin_range_not_satisfiable, "start position is earlier than account retention policy (${p}). Latest available: ${l}. Requested start: ${r}", ("p",history->history_per_account)("l",min_seq_number)("r",start) ); // Below should actually never occur..? EOS_ASSERT( end >= min_seq_number, chain::plugin_range_not_satisfiable, "end position is earlier than account retention policy (${p}). Latest available: ${l}. Requested end: ${r}", ("p",history->history_per_account)("l",min_seq_number)("r",end) ); @@ -682,13 +682,12 @@ namespace eosio { previoustrxid = t.trx_id; } - /* DISABLING THE LOOKUP TIME LIMIT end_time = fc::time_point::now(); - if (end_time - start_time > fc::microseconds(100000)) { + if (end_time - start_time > (fc::microseconds(100000) * 3)) { action_result.time_limit_exceeded_error = true; break; } - */ + } // while From b81803893fc73a7a2bd2b8a595969fdcbf93ca3a Mon Sep 17 00:00:00 2001 From: Adam Androulidakis Date: Tue, 16 Jun 2020 13:59:32 -0600 Subject: [PATCH 13/22] move the 3 --- plugins/history_plugin/history_plugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index 795c845364..7570bb7a83 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -683,7 +683,7 @@ namespace eosio { } end_time = fc::time_point::now(); - if (end_time - start_time > (fc::microseconds(100000) * 3)) { + if (end_time - start_time > (fc::microseconds(100000 * 3))) { action_result.time_limit_exceeded_error = true; break; } From b2b95b1fd3e7467afb84adc1f553823f5eeab16d Mon Sep 17 00:00:00 2001 From: Adam Androulidakis Date: Wed, 17 Jun 2020 11:13:03 -0600 Subject: [PATCH 14/22] rename ti.block_height to block_num, add account_action_seq and global_action_seq --- plugins/history_plugin/history_plugin.cpp | 4 +++- .../include/eosio/history_plugin/history_plugin.hpp | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index 7570bb7a83..8b3bf98f14 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -641,8 +641,10 @@ namespace eosio { transfer_information ti; ti.transaction_id = t.trx_id; - ti.block_height = t.block_num; + ti.block_num = t.block_num; ti.block_time = t.block_time; + ti.global_action_seq = action_sequence_num; + ti.account_action_seq = account_sequence_num; if(previoustrxid != t.trx_id) { if (t.act.name == N(trnsfiopubky)) { const auto transferdata = t.act.data_as(); diff --git a/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp b/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp index d487cafb2f..f47a95ca3f 100644 --- a/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp +++ b/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp @@ -59,7 +59,9 @@ namespace eosio { }; struct transfer_information { - uint32_t block_height; + uint64_t global_action_seq; + uint64_t account_action_seq; + uint32_t block_num; chain::block_timestamp_type block_time; string payer; string payee; @@ -182,7 +184,7 @@ FC_REFLECT(eosio::history_apis::read_only::get_actions_result, FC_REFLECT(eosio::history_apis::read_only::get_transfers_params, (fio_public_key)(pos)(offset)) FC_REFLECT(eosio::history_apis::read_only::get_transfers_result, (transfers)(last_irreversible_block)(time_limit_exceeded_error)) -FC_REFLECT(eosio::history_apis::read_only::transfer_information, (block_height) +FC_REFLECT(eosio::history_apis::read_only::transfer_information, (global_action_seq)(account_action_seq)(block_num) (block_time)(payer)(payee)(payee_public_key)(transfer_amount)(fee_amount) (transaction_total)(note)(action)(tpid)(transaction_id) ) FC_REFLECT(eosio::history_apis::read_only::ordered_action_result, From 2219c7fc0390e254dc34a72259e48cd585412d7e Mon Sep 17 00:00:00 2001 From: Adam Androulidakis Date: Thu, 18 Jun 2020 16:03:15 -0600 Subject: [PATCH 15/22] Allow result for trnfiopbky hashed down payee pub key in get_transfers --- plugins/history_plugin/history_plugin.cpp | 34 ++++++++++++----------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index 8b3bf98f14..49d66af327 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -637,7 +637,6 @@ namespace eosio { fc::datastream ds(a.packed_action_trace.data(), a.packed_action_trace.size()); action_trace t; fc::raw::unpack(ds, t); - if (t.receipt->receiver == account_name) { // skip emplacing results where receiver field does not match account_name parameter transfer_information ti; ti.transaction_id = t.trx_id; @@ -648,22 +647,26 @@ namespace eosio { if(previoustrxid != t.trx_id) { if (t.act.name == N(trnsfiopubky)) { const auto transferdata = t.act.data_as(); - ti.action = "trnsfiopubky"; - ti.tpid = transferdata.tpid; - ti.note = "FIO Transfer"; - ti.payer = transferdata.actor.to_string(); - ti.payee = fioio::key_to_account(transferdata.payee_public_key); - ti.payee_public_key = transferdata.payee_public_key; - ti.fee_amount = extract_fee(t); - ti.transaction_total = ti.fee_amount + transferdata.amount; - ti.transfer_amount = transferdata.amount; - if (params.pos < 0) { - result.transfers.emplace(result.transfers.begin(), ti ); - } else { - result.transfers.emplace_back( ti ); + const auto paccount = fioio::key_to_account(transferdata.payee_public_key); + if (t.receipt->receiver == account_name || t.receipt->receiver == paccount) { + ti.action = "trnsfiopubky"; + ti.tpid = transferdata.tpid; + ti.note = "FIO Transfer"; + ti.payer = transferdata.actor.to_string(); + ti.payee = paccount; + ti.payee_public_key = transferdata.payee_public_key; + ti.fee_amount = extract_fee(t); + ti.transaction_total = ti.fee_amount + transferdata.amount; + ti.transfer_amount = transferdata.amount; + if (params.pos < 0) { + result.transfers.emplace(result.transfers.begin(), ti ); + } else { + result.transfers.emplace_back( ti ); + } } + } - else if (t.act.name == N(transfer)) { + else if (t.act.name == N(transfer) && t.receipt->receiver == account_name) { const auto transferdata = t.act.data_as(); ti.action = "transfer"; ti.tpid = ""; @@ -682,7 +685,6 @@ namespace eosio { } } previoustrxid = t.trx_id; - } end_time = fc::time_point::now(); if (end_time - start_time > (fc::microseconds(100000 * 3))) { From f7b64b77bb1294382ae9d4bb61351bd532a06cd6 Mon Sep 17 00:00:00 2001 From: Adam Androulidakis Date: Fri, 19 Jun 2020 12:14:32 -0600 Subject: [PATCH 16/22] additional filter in logic (get_transfers --- plugins/history_plugin/history_plugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index 49d66af327..90b729bb33 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -648,7 +648,7 @@ namespace eosio { if (t.act.name == N(trnsfiopubky)) { const auto transferdata = t.act.data_as(); const auto paccount = fioio::key_to_account(transferdata.payee_public_key); - if (t.receipt->receiver == account_name || t.receipt->receiver == paccount) { + if (t.receipt->receiver == account_name || account_name == paccount || t.receipt->receiver == paccount) { ti.action = "trnsfiopubky"; ti.tpid = transferdata.tpid; ti.note = "FIO Transfer"; From c6e62f4f6ce1ab72e9f6f21fcbda88e3e7d837b5 Mon Sep 17 00:00:00 2001 From: Adam Androulidakis Date: Mon, 22 Jun 2020 14:14:35 -0600 Subject: [PATCH 17/22] handle subtransfer --- plugins/history_plugin/history_plugin.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index 90b729bb33..47b0490aa1 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -619,6 +619,7 @@ namespace eosio { get_transfers_result result; result.last_irreversible_block = chain.last_irreversible_block_num(); action_result.last_irreversible_block = chain.last_irreversible_block_num(); + bool subtransfer = false; fc::sha256 previoustrxid; while (start_itr != end_itr) { uint64_t action_sequence_num; @@ -644,7 +645,7 @@ namespace eosio { ti.block_time = t.block_time; ti.global_action_seq = action_sequence_num; ti.account_action_seq = account_sequence_num; - if(previoustrxid != t.trx_id) { + if(previoustrxid != t.trx_id && !subtransfer) { if (t.act.name == N(trnsfiopubky)) { const auto transferdata = t.act.data_as(); const auto paccount = fioio::key_to_account(transferdata.payee_public_key); @@ -658,15 +659,17 @@ namespace eosio { ti.fee_amount = extract_fee(t); ti.transaction_total = ti.fee_amount + transferdata.amount; ti.transfer_amount = transferdata.amount; + subtransfer = true; if (params.pos < 0) { result.transfers.emplace(result.transfers.begin(), ti ); } else { result.transfers.emplace_back( ti ); } + } } - else if (t.act.name == N(transfer) && t.receipt->receiver == account_name) { + else if (t.act.name == N(transfer) && t.receipt->receiver == account_name && subtransfer) { const auto transferdata = t.act.data_as(); ti.action = "transfer"; ti.tpid = ""; @@ -677,8 +680,9 @@ namespace eosio { ti.fee_amount = 0; // there is no fee for C2U/U2C transfers ti.transaction_total = transferdata.quantity.get_amount(); ti.transfer_amount = transferdata.quantity.get_amount(); + subtransfer = false; if (params.pos < 0) { - result.transfers.emplace(result.transfers.begin(), ti ); + result.transfers.emplace(result.transfers.begin(), ti ); } else { result.transfers.emplace_back( ti ); } From 36aafafe87de94d1b7b16d7704cba7848058c7b1 Mon Sep 17 00:00:00 2001 From: Adam Androulidakis Date: Wed, 24 Jun 2020 11:14:38 -0600 Subject: [PATCH 18/22] revert previous work, move previoustrx condition to trnsfiopbky filter --- plugins/history_plugin/history_plugin.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index 47b0490aa1..1695d8b264 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -619,7 +619,6 @@ namespace eosio { get_transfers_result result; result.last_irreversible_block = chain.last_irreversible_block_num(); action_result.last_irreversible_block = chain.last_irreversible_block_num(); - bool subtransfer = false; fc::sha256 previoustrxid; while (start_itr != end_itr) { uint64_t action_sequence_num; @@ -645,11 +644,11 @@ namespace eosio { ti.block_time = t.block_time; ti.global_action_seq = action_sequence_num; ti.account_action_seq = account_sequence_num; - if(previoustrxid != t.trx_id && !subtransfer) { if (t.act.name == N(trnsfiopubky)) { const auto transferdata = t.act.data_as(); const auto paccount = fioio::key_to_account(transferdata.payee_public_key); - if (t.receipt->receiver == account_name || account_name == paccount || t.receipt->receiver == paccount) { + if (previoustrxid != t.trx_id && (t.receipt->receiver == account_name || + account_name == paccount || t.receipt->receiver == paccount)) { ti.action = "trnsfiopubky"; ti.tpid = transferdata.tpid; ti.note = "FIO Transfer"; @@ -659,7 +658,6 @@ namespace eosio { ti.fee_amount = extract_fee(t); ti.transaction_total = ti.fee_amount + transferdata.amount; ti.transfer_amount = transferdata.amount; - subtransfer = true; if (params.pos < 0) { result.transfers.emplace(result.transfers.begin(), ti ); } else { @@ -669,7 +667,7 @@ namespace eosio { } } - else if (t.act.name == N(transfer) && t.receipt->receiver == account_name && subtransfer) { + else if (t.act.name == N(transfer) && t.receipt->receiver == account_name) { const auto transferdata = t.act.data_as(); ti.action = "transfer"; ti.tpid = ""; @@ -680,14 +678,12 @@ namespace eosio { ti.fee_amount = 0; // there is no fee for C2U/U2C transfers ti.transaction_total = transferdata.quantity.get_amount(); ti.transfer_amount = transferdata.quantity.get_amount(); - subtransfer = false; if (params.pos < 0) { result.transfers.emplace(result.transfers.begin(), ti ); } else { result.transfers.emplace_back( ti ); } } - } previoustrxid = t.trx_id; end_time = fc::time_point::now(); From 66a7e19830be8b78dd3489cb7a495d9a2607c289 Mon Sep 17 00:00:00 2001 From: Adam Androulidakis Date: Wed, 24 Jun 2020 23:10:41 -0600 Subject: [PATCH 19/22] Add transferdata to/from fields to transfer filtering --- plugins/history_plugin/history_plugin.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index 1695d8b264..3482c171a6 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -663,12 +663,13 @@ namespace eosio { } else { result.transfers.emplace_back( ti ); } - } - } - else if (t.act.name == N(transfer) && t.receipt->receiver == account_name) { + else if (t.act.name == N(transfer)) { const auto transferdata = t.act.data_as(); + if (t.receipt->receiver == account_name || + transferdata.to.to_string() == account_name || + transferdata.from.to_string() == account_name) { ti.action = "transfer"; ti.tpid = ""; ti.note = transferdata.memo; @@ -684,6 +685,7 @@ namespace eosio { result.transfers.emplace_back( ti ); } } + } previoustrxid = t.trx_id; end_time = fc::time_point::now(); From d9bfd6efb79fb299bb2fefb3bf653a8329e1f7ee Mon Sep 17 00:00:00 2001 From: Adam Androulidakis Date: Wed, 24 Jun 2020 23:12:24 -0600 Subject: [PATCH 20/22] Make transfer_amount field optional for fee transfers to fio.treasury --- plugins/history_plugin/history_plugin.cpp | 9 +++++++-- .../include/eosio/history_plugin/history_plugin.hpp | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index 3482c171a6..7d2b8e5fac 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -676,9 +676,14 @@ namespace eosio { ti.payer = transferdata.from.to_string(); ti.payee = transferdata.to.to_string(); ti.payee_public_key = ""; - ti.fee_amount = 0; // there is no fee for C2U/U2C transfers + if (ti.payee == "fio.treasury") { + ti.fee_amount = transferdata.quantity.get_amount(); + } else { + ti.transfer_amount = transferdata.quantity.get_amount(); //transfer amount is optional result and only set in cases where transfer is not fee to fio.treasury + ti.fee_amount = 0; // there is no fee for C2U/U2C transfers + } ti.transaction_total = transferdata.quantity.get_amount(); - ti.transfer_amount = transferdata.quantity.get_amount(); + if (params.pos < 0) { result.transfers.emplace(result.transfers.begin(), ti ); } else { diff --git a/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp b/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp index f47a95ca3f..a64fd8a44c 100644 --- a/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp +++ b/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp @@ -66,7 +66,7 @@ namespace eosio { string payer; string payee; string payee_public_key; - uint64_t transfer_amount; + optional transfer_amount; uint64_t fee_amount; uint64_t transaction_total; string note; From 3e4b33c7ffbac462299a892c2d82d313d04ee2d4 Mon Sep 17 00:00:00 2001 From: Adam Androulidakis Date: Thu, 25 Jun 2020 10:19:34 -0600 Subject: [PATCH 21/22] fix parenthesis placement --- plugins/history_plugin/history_plugin.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index 7d2b8e5fac..7f7a778d8e 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -647,8 +647,9 @@ namespace eosio { if (t.act.name == N(trnsfiopubky)) { const auto transferdata = t.act.data_as(); const auto paccount = fioio::key_to_account(transferdata.payee_public_key); - if (previoustrxid != t.trx_id && (t.receipt->receiver == account_name || - account_name == paccount || t.receipt->receiver == paccount)) { + if ( previoustrxid != t.trx_id && (t.receipt->receiver == account_name || + account_name == paccount || t.receipt->receiver == paccount || + transferdata.actor.to_string() == account_name)) { ti.action = "trnsfiopubky"; ti.tpid = transferdata.tpid; ti.note = "FIO Transfer"; @@ -680,7 +681,6 @@ namespace eosio { ti.fee_amount = transferdata.quantity.get_amount(); } else { ti.transfer_amount = transferdata.quantity.get_amount(); //transfer amount is optional result and only set in cases where transfer is not fee to fio.treasury - ti.fee_amount = 0; // there is no fee for C2U/U2C transfers } ti.transaction_total = transferdata.quantity.get_amount(); From c17927f49a900005a84740090c5567107533f482 Mon Sep 17 00:00:00 2001 From: Adam Androulidakis Date: Sun, 28 Jun 2020 19:14:38 -0600 Subject: [PATCH 22/22] set amounts to 0 instead of omitting the fields --- plugins/history_plugin/history_plugin.cpp | 11 +++++++++-- .../include/eosio/history_plugin/history_plugin.hpp | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/plugins/history_plugin/history_plugin.cpp b/plugins/history_plugin/history_plugin.cpp index 7f7a778d8e..57ebd084a1 100644 --- a/plugins/history_plugin/history_plugin.cpp +++ b/plugins/history_plugin/history_plugin.cpp @@ -647,8 +647,12 @@ namespace eosio { if (t.act.name == N(trnsfiopubky)) { const auto transferdata = t.act.data_as(); const auto paccount = fioio::key_to_account(transferdata.payee_public_key); - if ( previoustrxid != t.trx_id && (t.receipt->receiver == account_name || - account_name == paccount || t.receipt->receiver == paccount || + if ( previoustrxid != t.trx_id && (account_name == paccount || + t.receipt->receiver == N(account_name) || + t.receipt->receiver == transferdata.actor || + t.receipt->receiver == N(paccount) || + paccount == "fio.treasury" || + transferdata.actor.to_string() == paccount || transferdata.actor.to_string() == account_name)) { ti.action = "trnsfiopubky"; ti.tpid = transferdata.tpid; @@ -657,6 +661,7 @@ namespace eosio { ti.payee = paccount; ti.payee_public_key = transferdata.payee_public_key; ti.fee_amount = extract_fee(t); + std::cout<<"*****TRANSFERPUB*******"; ti.transaction_total = ti.fee_amount + transferdata.amount; ti.transfer_amount = transferdata.amount; if (params.pos < 0) { @@ -679,7 +684,9 @@ namespace eosio { ti.payee_public_key = ""; if (ti.payee == "fio.treasury") { ti.fee_amount = transferdata.quantity.get_amount(); + ti.transfer_amount = 0; } else { + ti.fee_amount = 0; ti.transfer_amount = transferdata.quantity.get_amount(); //transfer amount is optional result and only set in cases where transfer is not fee to fio.treasury } ti.transaction_total = transferdata.quantity.get_amount(); diff --git a/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp b/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp index a64fd8a44c..f47a95ca3f 100644 --- a/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp +++ b/plugins/history_plugin/include/eosio/history_plugin/history_plugin.hpp @@ -66,7 +66,7 @@ namespace eosio { string payer; string payee; string payee_public_key; - optional transfer_amount; + uint64_t transfer_amount; uint64_t fee_amount; uint64_t transaction_total; string note;