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 asset names and amount/price calculations to additional #1351

Merged
merged 8 commits into from
Oct 3, 2018
18 changes: 18 additions & 0 deletions libraries/plugins/elasticsearch/elasticsearch_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,23 +227,41 @@ void elasticsearch_plugin_impl::doBlock(uint32_t trx_in_block, const signed_bloc

void elasticsearch_plugin_impl::doVisitor(const optional <operation_history_object>& oho)
{
graphene::chain::database& db = database();

operation_visitor o_v;
oho->op.visit(o_v);

auto fee_asset = o_v.fee_asset(db);
vs.fee_data.asset = o_v.fee_asset;
vs.fee_data.asset_name = fee_asset.symbol;
vs.fee_data.amount = o_v.fee_amount;
vs.fee_data.amount_units = (o_v.fee_amount.value)/(double)asset::scaled_precision(fee_asset.precision).value;

auto transfer_asset = o_v.transfer_asset_id(db);
vs.transfer_data.asset = o_v.transfer_asset_id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for transfer_asset.

vs.transfer_data.asset_name = transfer_asset.symbol;
vs.transfer_data.amount = o_v.transfer_amount;
vs.transfer_data.amount_units = (o_v.transfer_amount.value)/(double)asset::scaled_precision(transfer_asset.precision).value;
vs.transfer_data.from = o_v.transfer_from;
vs.transfer_data.to = o_v.transfer_to;

auto fill_pays_asset = o_v.fill_pays_asset_id(db);
auto fill_receives_asset = o_v.fill_receives_asset_id(db);
vs.fill_data.order_id = o_v.fill_order_id;
vs.fill_data.account_id = o_v.fill_account_id;
vs.fill_data.pays_asset_id = o_v.fill_pays_asset_id;
vs.fill_data.pays_asset_name = fill_pays_asset.symbol;
vs.fill_data.pays_amount = o_v.fill_pays_amount;
vs.fill_data.pays_amount_units = (o_v.fill_pays_amount.value)/(double)asset::scaled_precision(fill_pays_asset.precision).value;
vs.fill_data.receives_asset_id = o_v.fill_receives_asset_id;
vs.fill_data.receives_asset_name = fill_receives_asset.symbol;
vs.fill_data.receives_amount = o_v.fill_receives_amount;
vs.fill_data.receives_amount_units = (o_v.fill_receives_amount.value)/(double)asset::scaled_precision(fill_receives_asset.precision).value;

auto fill_price = (o_v.fill_receives_amount.value/(double)asset::scaled_precision(fill_receives_asset.precision).value) /
(o_v.fill_pays_amount.value/(double)asset::scaled_precision(fill_pays_asset.precision).value);
vs.fill_data.fill_price_units = fill_price;
vs.fill_data.fill_price = o_v.fill_fill_price;
vs.fill_data.is_maker = o_v.fill_is_maker;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,16 @@ struct block_struct {

struct fee_struct {
asset_id_type asset;
std::string asset_name;
share_type amount;
double amount_units;
};

struct transfer_struct {
asset_id_type asset;
std::string asset_name;
share_type amount;
double amount_units;
account_id_type from;
account_id_type to;
};
Expand All @@ -152,10 +156,15 @@ struct fill_struct {
object_id_type order_id;
account_id_type account_id;
asset_id_type pays_asset_id;
std::string pays_asset_name;
share_type pays_amount;
double pays_amount_units;
asset_id_type receives_asset_id;
std::string receives_asset_name;
share_type receives_amount;
double receives_amount_units;
double fill_price;
double fill_price_units;
bool is_maker;
};

Expand All @@ -178,8 +187,10 @@ struct bulk_struct {

FC_REFLECT( graphene::elasticsearch::operation_history_struct, (trx_in_block)(op_in_trx)(operation_result)(virtual_op)(op) )
FC_REFLECT( graphene::elasticsearch::block_struct, (block_num)(block_time)(trx_id) )
FC_REFLECT( graphene::elasticsearch::fee_struct, (asset)(amount) )
FC_REFLECT( graphene::elasticsearch::transfer_struct, (asset)(amount)(from)(to) )
FC_REFLECT( graphene::elasticsearch::fill_struct, (order_id)(account_id)(pays_asset_id)(pays_amount)(receives_asset_id)(receives_amount)(fill_price)(is_maker))
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) )
FC_REFLECT( graphene::elasticsearch::fill_struct, (order_id)(account_id)(pays_asset_id)(pays_asset_name)(pays_amount)(pays_amount_units)
(receives_asset_id)(receives_asset_name)(receives_amount)(receives_amount_units)(fill_price)
(fill_price_units)(is_maker))
FC_REFLECT( graphene::elasticsearch::visitor_struct, (fee_data)(transfer_data)(fill_data) )
FC_REFLECT( graphene::elasticsearch::bulk_struct, (account_history)(operation_history)(operation_type)(operation_id_num)(block_data)(additional_data) )