Update for beem: improved account history handling

in HiveDevs3 years ago

Repository

https://github.com/holgern/beem


beem-logo

beem is a python library and command line tool for HIVE. The current version is 0.24.18.

There is also a discord channel for beem: https://discord.gg/4HM592V

The newest beem version can be installed by:

pip install -U beem

Check that you are using hive nodes. The following command

beempy updatenodes --hive

updates the nodelist and uses only hive nodes. After setting hive as default_chain, beempy updatenodes can be used.

The list of nodes can be checked with

beempy config

and

beempy currentnode

shows the currently connected node.

Changelog for 0.24.18

  • Adapt account history on api changes and fixes issue #267
  • Speed up history call, when limit is below 1000
  • Improve unit tests for account history
  • Fix estimate_virtual_op_num, when get_account_history returns an empty entry for an index
  • Implement _get_operation_filter and use filter operations in history and history_reverse on the https://api.hive.blog api node

Changelog for 0.24.17

  • Fixed a bug when using skip_account_check=True
  • Refactor code in Account
  • Add more unit tests

Changelog for 0.24.16

  • Fix bug in bytes representation of an Amount which prevents sending certain amounts (e.g. 8.19 HIVE)
  • Added unit tests to check if 8.190 is correctly working

Fixing rounding errors in transfers

In version 0.24.16, a rounding bug was fixed which prevents sending 8.19 HIVE. This bug leads to a wrong signature, which then prevents broadcasting the transfer op. This is now fixed.

Improved error handling in account history

The account history and history_reverse functions have now a better error handling.
The returned index is now checked, which prevents that account history elements were added twice to the output.

New filtered account history

Currently the new filter parameter are only implemented at "https://api.hive.blog" API node.

On this node, the get_account_history call has two more parameters: operation_filter_low and operation_filter_high.
These parameters are a bitmask of all possible operation names.
They can be obtained with the _get_operation_filter function:

operation_filter_low, operation_filter_high = account._get_operation_filter(only_ops=["transfer", "vote"])

which results in operation_filter_low=5 and operation_filter_high=0.

The history and history_reverse function from beem will now use the operation_filter when
"https://api.hive.blog" is set as node. This speeds up receiving account history data up to 100 %.

History reverse with operation_filter

from beem.account import Account
from beem import Hive
import time
hive = Hive("https://api.hive.blog")
acc = Account("holger80", blockchain_instance=hive)
start_time = time.time()
n_op = acc.virtual_op_count()
transfer_ops = list(acc.history_reverse(only_ops=["transfer"]))
print("Time needed to search all transfers in %d history elements: %.2f s" % (n_op, (time.time() - start_time)))
print("%d transfer op have been found" % (len(transfer_ops)))

returns

Time needed to search all transfers in 283514 history elements: 145.66 s
4666 transfer op have been found

History with operation_filter

from beem.account import Account
from beem import Hive
import time
hive = Hive("https://api.hive.blog")
acc = Account("holger80", blockchain_instance=hive)
start_time = time.time()
n_op = acc.virtual_op_count()
transfer_ops = list(acc.history(only_ops=["transfer"]))
print("Time needed to search all transfers in %d history elements: %.2f s" % (n_op, (time.time() - start_time)))
print("%d transfer op have been found" % (len(transfer_ops)))

returns

Time needed to search all transfers in 283517 history elements: 144.55 s
4666 transfer op have been found

History without operation filter

Now we do the same without filtering:

from beem.account import Account
from beem import Hive
import time
hive = Hive("https://api.hive.blog")
acc = Account("holger80", blockchain_instance=hive)
start_time = time.time()
n_op = acc.virtual_op_count()
transfer_ops = []
for op in acc.history():
    if op["type"] == "transfer":
        transfer_ops.append(op)
print("Time needed to search all transfers in %d history elements: %.2f s" % (n_op, (time.time() - start_time)))
print("%d transfer op have been found" % (len(transfer_ops)))

returns

Time needed to search all transfers in 283518 history elements: 261.63 s
4666 transfer op have been found

If you like what I do, consider casting a vote for me as witness on Hivesigner or on PeakD

Sort:  

Upvoted to thank you @holger80 for supporting the CO2Fund by, e.g., supporting posts, banner presentation, SP/HP delegation, dustsweeper gifts, helpful tools, etc.

Your current Rank (124) in the battle Arena of Holybread has granted you an Upvote of 30%

@holger80,
Very useful, thank you for your effort!
$tangent

Cheers~


Congratulations, @theguruasia You Successfully Trended The Post Shared By @holger80.
You Utilized 3/3 Daily Summon Bot Calls.

TAN Current Market Price : 0.203 HIVE


Congratulations @holger80, You Earned 2.051 TAN & Curators Made 2.051 TAN.

tangent.token


Join CORE / VAULT Token Discord Channel or Trade TANGENT Token
TAN Current Market Price : 0.250 HIVE

Congratulations @holger80! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :

You distributed more than 22000 upvotes. Your next target is to reach 23000 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP