Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fee payer to account history in ElasticSearch database #2624

Merged
merged 2 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 17 additions & 3 deletions libraries/plugins/elasticsearch/elasticsearch_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,29 @@ void elasticsearch_plugin_impl::checkState(const fc::time_point_sec& block_time)
bulk_lines.reserve(limit_documents);
}

struct get_fee_payer_visitor
{
using result_type = account_id_type;

template<typename OpType>
account_id_type operator()(const OpType& op) const
{
return op.fee_payer();
}
};

void elasticsearch_plugin_impl::doOperationHistory( const optional <operation_history_object>& oho,
operation_history_struct& os ) const
{ try {
os.trx_in_block = oho->trx_in_block;
os.op_in_trx = oho->op_in_trx;
os.operation_result = fc::json::to_string(oho->result);
os.virtual_op = oho->virtual_op;
os.fee_payer = oho->op.visit( get_fee_payer_visitor() );

if(_options.operation_string)
os.op = fc::json::to_string(oho->op);

os.operation_result = fc::json::to_string(oho->result);

if(_options.operation_object) {
constexpr uint16_t current_depth = 2;
Expand All @@ -269,8 +285,6 @@ void elasticsearch_plugin_impl::doOperationHistory( const optional <operation_hi
os.operation_result_object = graphene::utilities::es_data_adaptor::adapt_static_variant( v.get_array(),
_options.max_mapping_depth - current_depth );
}
if(_options.operation_string)
os.op = fc::json::to_string(oho->op);
} FC_CAPTURE_LOG_AND_RETHROW( (oho) ) }

void elasticsearch_plugin_impl::doBlock(uint32_t trx_in_block, const signed_block& b, block_struct& bs) const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ class elasticsearch_plugin : public graphene::app::plugin
struct operation_history_struct {
uint16_t trx_in_block;
uint16_t op_in_trx;
std::string operation_result;
uint32_t virtual_op;
account_id_type fee_payer;
std::string op;
std::string operation_result;
variant op_object;
variant operation_result_object;
};
Expand Down Expand Up @@ -146,7 +147,8 @@ struct bulk_struct {

FC_REFLECT_ENUM( graphene::elasticsearch::mode, (only_save)(only_query)(all) )
FC_REFLECT( graphene::elasticsearch::operation_history_struct,
(trx_in_block)(op_in_trx)(operation_result)(virtual_op)(op)(op_object)(operation_result_object) )
(trx_in_block)(op_in_trx)(virtual_op)(fee_payer)
(op)(operation_result)(op_object)(operation_result_object) )
FC_REFLECT( graphene::elasticsearch::block_struct, (block_num)(block_time)(trx_id) )
FC_REFLECT( graphene::elasticsearch::fee_struct, (asset)(asset_name)(amount)(amount_units) )
FC_REFLECT( graphene::elasticsearch::transfer_struct, (asset)(asset_name)(amount)(amount_units)(from)(to) )
Expand Down
2 changes: 2 additions & 0 deletions tests/elasticsearch/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ BOOST_AUTO_TEST_CASE(elasticsearch_account_history) {
j = fc::json::from_string(res);
auto last_transfer_amount = j["_source"]["operation_history"]["op_object"]["amount_"]["amount"].as_string();
BOOST_CHECK_EQUAL(last_transfer_amount, "300");
auto last_transfer_payer = j["_source"]["operation_history"]["fee_payer"].as_string();
BOOST_CHECK_EQUAL(last_transfer_payer, "1.2.0");

// To test credit offers
generate_blocks( HARDFORK_CORE_2362_TIME );
Expand Down