-
Notifications
You must be signed in to change notification settings - Fork 648
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
Changes from 4 commits
c9db5dd
ae09a86
0df639e
1b3b297
c2e17b3
e686567
57aee32
0db7c14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ class elasticsearch_plugin_impl | |
virtual ~elasticsearch_plugin_impl(); | ||
|
||
bool update_account_histories( const signed_block& b ); | ||
void populatePowTable(); | ||
|
||
graphene::chain::database& database() | ||
{ | ||
|
@@ -72,6 +73,7 @@ class elasticsearch_plugin_impl | |
std::string bulk_line; | ||
std::string index_name; | ||
bool is_sync = false; | ||
map <uint8_t , uint64_t > lookup_pow_table; | ||
private: | ||
bool add_elasticsearch( const account_id_type account_id, const optional<operation_history_object>& oho ); | ||
const account_transaction_history_object& addNewEntry(const account_statistics_object& stats_obj, | ||
|
@@ -227,23 +229,37 @@ 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); | ||
|
||
vs.fee_data.asset = o_v.fee_asset; | ||
vs.fee_data.asset_name = o_v.fee_asset(db).symbol; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're doing two lookups on fee_asset - better to look up only once. |
||
vs.fee_data.amount = o_v.fee_amount; | ||
vs.fee_data.amount_units = (double)(o_v.fee_amount.value)/lookup_pow_table[o_v.fee_asset(db).precision]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can remove all (double) casts here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. had to keep (double) cast in the |
||
|
||
vs.transfer_data.asset = o_v.transfer_asset_id; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for transfer_asset. |
||
vs.transfer_data.asset_name = o_v.transfer_asset_id(db).symbol; | ||
vs.transfer_data.amount = o_v.transfer_amount; | ||
vs.transfer_data.amount_units = (double)(o_v.transfer_amount.value)/lookup_pow_table[o_v.transfer_asset_id(db).precision]; | ||
vs.transfer_data.from = o_v.transfer_from; | ||
vs.transfer_data.to = o_v.transfer_to; | ||
|
||
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 = o_v.fill_pays_asset_id(db).symbol; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Three lookups for fill_pays_asset and fill_receives_asset each. |
||
vs.fill_data.pays_amount = o_v.fill_pays_amount; | ||
vs.fill_data.pays_amount_units = (double)(o_v.fill_pays_amount.value)/lookup_pow_table[o_v.fill_pays_asset_id(db).precision]; | ||
vs.fill_data.receives_asset_id = o_v.fill_receives_asset_id; | ||
vs.fill_data.receives_asset_name = o_v.fill_receives_asset_id(db).symbol; | ||
vs.fill_data.receives_amount = o_v.fill_receives_amount; | ||
vs.fill_data.receives_amount_units = (double)(o_v.fill_receives_amount.value)/lookup_pow_table[o_v.fill_receives_asset_id(db).precision]; | ||
|
||
auto fill_price = (double)(o_v.fill_receives_amount.value/lookup_pow_table[o_v.fill_receives_asset_id(db).precision]) / | ||
(double)(o_v.fill_pays_amount.value / lookup_pow_table[o_v.fill_pays_asset_id(db).precision]); | ||
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; | ||
} | ||
|
@@ -368,6 +384,23 @@ void elasticsearch_plugin_impl::populateESstruct() | |
es.query = ""; | ||
} | ||
|
||
void elasticsearch_plugin_impl::populatePowTable() | ||
{ | ||
lookup_pow_table[0] = 1; | ||
lookup_pow_table[1] = 10; | ||
lookup_pow_table[2] = 100; | ||
lookup_pow_table[3] = 1000; | ||
lookup_pow_table[4] = 10000; | ||
lookup_pow_table[5] = 100000; | ||
lookup_pow_table[6] = 1000000; | ||
lookup_pow_table[7] = 10000000; | ||
lookup_pow_table[8] = 100000000; | ||
lookup_pow_table[9] = 1000000000; | ||
lookup_pow_table[10] = 10000000000; | ||
lookup_pow_table[11] = 100000000000; | ||
lookup_pow_table[12] = 1000000000000; | ||
} | ||
|
||
} // end namespace detail | ||
|
||
elasticsearch_plugin::elasticsearch_plugin() : | ||
|
@@ -445,6 +478,8 @@ void elasticsearch_plugin::plugin_startup() | |
if(!graphene::utilities::checkES(es)) | ||
FC_THROW_EXCEPTION(fc::exception, "ES database is not up in url ${url}", ("url", my->_elasticsearch_node_url)); | ||
ilog("elasticsearch ACCOUNT HISTORY: plugin_startup() begin"); | ||
|
||
my->populatePowTable(); | ||
} | ||
|
||
} } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use a simple static const array with static initialization instead of a map? Would be much simpler IMO.
Also, use double values instead of uint64_t - they're always converted to double anyway, and it even saves you some casting when using the values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, i agree and changed. cant make it
static
as a member ofelasticsearch_plugin_impl
. maybe somewhere else, however not sure where.