bitshares-core
bitshares-core copied to clipboard
timestamps in get_relative_account_history() call
Is it possible to get the timestamp for every operation in the account history?
Hi there, you need to use the new elasticsearch plugin to make this, documentation is in progress but you can get some of it at: https://github.com/oxarbitrage/worker-proposals/blob/master/elasticsearch-plugin.md - https://github.com/bitshares/bitshares-core/issues/358
For example, getting the last op from the network will return:
root@NC-PH-1346-07:~# curl -X GET 'http://localhost:9200/graphene-*/data/_search?pretty=true' -d '
{
"query": {
"match_all": {}
},
"size": 1,
"sort": [
{
"block_data.block_time": {
"order": "desc"
}
}
]
}
'
{
"took" : 394,
"timed_out" : false,
"_shards" : {
"total" : 130,
"successful" : 130,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 90991474,
"max_score" : null,
"hits" : [
{
"_index" : "graphene-2017-11",
"_type" : "data",
"_id" : "2.9.90991445",
"_score" : null,
"_source" : {
"account_history" : {
"id" : "2.9.90991445",
"account" : "1.2.410471",
"operation_id" : "1.11.89931301",
"sequence" : 219332,
"next" : "2.9.90991444"
},
"operation_history" : {
"trx_in_block" : 2,
"op_in_trx" : 1,
"operation_result" : "[1,\"1.7.37153893\"]",
"virtual_op" : 40981,
"op" : "[1,{\"fee\":{\"amount\":1213,\"asset_id\":\"1.3.0\"},\"seller\":\"1.2.410471\",\"amount_to_sell\":{\"amount\":482315280,\"asset_id\":\"1.3.0\"},
\"min_to_receive\":{\"amount\":4701839,\"asset_id\":\"1.3.121\"},\"expiration\":\"1963-11-25T09:31:44\",\"fill_or_kill\":false,\"extensions\":[]}]"
},
"operation_type" : 1,
"block_data" : {
"block_num" : 21840919,
"block_time" : "2017-11-16T11:41:42",
"trx_id" : "a06be59f63345f32c7b6005761059010739376de"
},
"additional_data" : {
"fee_data" : {
"asset" : "1.3.0",
"amount" : 1213
},
"transfer_data" : {
"asset" : "1.3.0",
"amount" : 0,
"from" : "1.2.0",
"to" : "1.2.0"
}
}
},
"sort" : [
1510832502000
]
}
]
}
}
root@NC-PH-1346-07:~#
The block_time
is the timestamp you are looking for and in elasticsearch plugin this date is with every operation. For this and other similar issues get_relative_account_history
will not be modified in the short term and you need to start looking into this plugin.
If you need help, have questions, etc please post here or open new issues accordingly.
There is no infrastructure of ES yet. Can we not simply add the blocks timestamp to the APIs output?
i don't think so. first there are performance issues to fetch the block and later the timestamp with each op, no code to do it was accepted. second, the output of the api call is just ops, if we add the timestamp we will be changing the format of the output possible breaking ongoing applications. we can go over this by adding a new api call but (third), we developed the ES plugin just for that (between other reasons), to don't add more stuff the the current api outputs, now is timestamp, then is filter by op, then filter by transaction, and so on.
the ES is a global solution for this kind of situations of all kind of searches inside account history.
I agree there is no infrastructure but all you need is to setup your own node with ES
to make use of the new api.
we need to educate IMHO to start resolving this issues by the plugin where everything can be done instead of just adding more stuff to the account history api outputs and more api calls.
Done via https://github.com/bitshares/bitshares-core/pull/2642