Hive programming in Python,
by Stable Diffusion AI
I have tried beem earlier, and currently using the LightHive library created by @emrebeyler, but I seem to have similar problems with both libraries.
I took the example from the lighthive documentation, and only slightly altered it, only changing the account name, and taking away all references to 'binance'.
Modified example code below:
import datetime
from lighthive.client import Client
from lighthive.helpers.amount import Amount
client = Client()
account = client.account('gamer00')
one_week_ago = datetime.datetime.utcnow() - datetime.timedelta(days=7)
total_hive = 0
for op in account.history(
stop_at=one_week_ago,
filter=["transfer"]):
if op["to"] == "gamer00":
continue
total_hive += Amount(op["amount"]).amount
print("Total HIVE transfers received", total_hive)
However, when I try to run the script, I keep constantly getting this error message:
Traceback (most recent call last):
File "/home/ambience/Projects/Code/Python/Hive/transactions/minimal/lighthive-fetch.py", line 11, in <module>
for op in account.history(
File "/home/ambience/.local/lib/python3.10/site-packages/lighthive/helpers/account.py", line 77, in history
max_index = self.client.get_account_history(account, -1, 0)[0][0]
File "/home/ambience/.local/lib/python3.10/site-packages/lighthive/client.py", line 61, in callable
return self.request(attr, *args, **kwargs)
File "/home/ambience/.local/lib/python3.10/site-packages/lighthive/client.py", line 178, in request
self.validate_response(response)
File "/home/ambience/.local/lib/python3.10/site-packages/lighthive/client.py", line 190, in validate_response
raise RPCNodeException(
lighthive.exceptions.RPCNodeException: Assert Exception:args.start >= args.limit-1: start must be greater than or equal to limit-1 (start is 0-based index)
I now know that the searches are basically done in reverse, since it's a blockchain, and starting the reading from the beginning would be too resource intensive for anything more recent. However there being a parameter 'order', I guess this can be changed. The default seems to be a reverse search.
But since I didn't have any 'start_at' definitions in my code, I don't get why the error message.
Nice post!
Thanks!