Skip to content
Snippets Groups Projects
Commit 3dd7357e authored by Holger's avatar Holger
Browse files

Fix estimate_virtual_op_num, when get_account_history returns an empty entry for an index

parent a905e3fb
No related branches found
No related tags found
2 merge requests!5Taken current version of master branch in the https://github.com/holgern/beem,!4Original changes pushed to master at https://github.com/holgern/beem
...@@ -5,6 +5,7 @@ Changelog ...@@ -5,6 +5,7 @@ Changelog
* Adapt account history on api changes and fixes issue #267 * Adapt account history on api changes and fixes issue #267
* Speed up history call, when limit is below 1000 * Speed up history call, when limit is below 1000
* Improve unit tests for account history * Improve unit tests for account history
* Fix estimate_virtual_op_num, when get_account_history returns an empty entry for an index
0.24.17 0.24.17
------- -------
......
...@@ -653,10 +653,10 @@ class Account(BlockchainObject): ...@@ -653,10 +653,10 @@ class Account(BlockchainObject):
""" """
if self['mined']: if self['mined']:
return None return None
ops = list(self.get_account_history(0, 0)) ops = list(self.get_account_history(1, 1))
if not ops or 'creator' not in ops[0]: if not ops or 'creator' not in ops[-1]:
return None return None
return ops[0]['creator'] return ops[-1]['creator']
def get_recharge_time_str(self, voting_power_goal=100, starting_voting_power=None): def get_recharge_time_str(self, voting_power_goal=100, starting_voting_power=None):
""" Returns the account recharge time as string """ Returns the account recharge time as string
...@@ -1841,7 +1841,7 @@ class Account(BlockchainObject): ...@@ -1841,7 +1841,7 @@ class Account(BlockchainObject):
except IndexError: except IndexError:
return 0 return 0
def _get_account_history(self, account=None, start=-1, limit=1): def _get_account_history(self, account=None, start=-1, limit=1, operation_filter_low=None, operation_filter_high=None):
if account is None: if account is None:
account = self["name"] account = self["name"]
account = extract_account_name(account) account = extract_account_name(account)
...@@ -1850,15 +1850,33 @@ class Account(BlockchainObject): ...@@ -1850,15 +1850,33 @@ class Account(BlockchainObject):
if not self.blockchain.is_connected(): if not self.blockchain.is_connected():
raise OfflineHasNoRPCException("No RPC available in offline mode!") raise OfflineHasNoRPCException("No RPC available in offline mode!")
self.blockchain.rpc.set_next_node_on_empty_reply(False) self.blockchain.rpc.set_next_node_on_empty_reply(False)
if self.blockchain.rpc.get_use_appbase(): if operation_filter_low is None and operation_filter_high is None:
try: if self.blockchain.rpc.get_use_appbase():
ret = self.blockchain.rpc.get_account_history({'account': account, 'start': start, 'limit': limit}, api="account_history") try:
if ret is not None: ret = self.blockchain.rpc.get_account_history({'account': account, 'start': start, 'limit': limit}, api="account_history")
ret = ret["history"] if ret is not None:
except ApiNotSupported: ret = ret["history"]
ret = self.blockchain.rpc.get_account_history(account, start, limit, api="condenser") except ApiNotSupported:
ret = self.blockchain.rpc.get_account_history(account, start, limit, api="condenser")
else:
ret = self.blockchain.rpc.get_account_history(account, start, limit, api="database")
else: else:
ret = self.blockchain.rpc.get_account_history(account, start, limit, api="database") if self.blockchain.rpc.get_use_appbase():
try:
ret = self.blockchain.rpc.get_account_history({'account': account, 'start': start, 'limit': limit,
'operation_filter_low': operation_filter_low,
'operation_filter_high': operation_filter_low}, api="account_history")
if ret is not None:
ret = ret["history"]
except ApiNotSupported:
ret = self.blockchain.rpc.get_account_history(account, start, limit,
operation_filter_low,
operation_filter_high, api="condenser")
else:
ret = self.blockchain.rpc.get_account_history(account, start, limit,
operation_filter_low,
operation_filter_high,
api="database")
return ret return ret
def estimate_virtual_op_num(self, blocktime, stop_diff=0, max_count=100): def estimate_virtual_op_num(self, blocktime, stop_diff=0, max_count=100):
...@@ -1907,6 +1925,8 @@ class Account(BlockchainObject): ...@@ -1907,6 +1925,8 @@ class Account(BlockchainObject):
if index == 0: if index == 0:
index = 1 index = 1
op = self._get_account_history(start=(index)) op = self._get_account_history(start=(index))
if len(op) == 0:
return None
return op[0][1]['block'] return op[0][1]['block']
max_index = self.virtual_op_count() max_index = self.virtual_op_count()
...@@ -1966,6 +1986,9 @@ class Account(BlockchainObject): ...@@ -1966,6 +1986,9 @@ class Account(BlockchainObject):
# get block number for current op number estimation # get block number for current op number estimation
if op_num != last_op_num: if op_num != last_op_num:
block_num = get_blocknum(op_num) block_num = get_blocknum(op_num)
while block_num is None and op_num < max_index:
op_num += 1
block_num = get_blocknum(op_num)
last_op_num = op_num last_op_num = op_num
# check if the required accuracy was reached # check if the required accuracy was reached
......
...@@ -4,7 +4,7 @@ import unittest ...@@ -4,7 +4,7 @@ import unittest
import random import random
from parameterized import parameterized from parameterized import parameterized
from pprint import pprint from pprint import pprint
from beem import Steem from beem import Steem, Hive
from beem.amount import Amount from beem.amount import Amount
from beem.witness import Witness from beem.witness import Witness
from beem.account import Account from beem.account import Account
...@@ -32,20 +32,20 @@ core_unit = "STM" ...@@ -32,20 +32,20 @@ core_unit = "STM"
class Testcases(unittest.TestCase): class Testcases(unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
stm = Steem(node=get_hive_nodes()) stm = Hive(node=get_hive_nodes())
stm.config.refreshBackup() stm.config.refreshBackup()
stm.set_default_nodes(["xyz"]) stm.set_default_nodes(["xyz"])
del stm del stm
cls.urls = get_hive_nodes() cls.urls = get_hive_nodes()
cls.bts = Steem( cls.bts = Hive(
node=cls.urls, node=cls.urls,
nobroadcast=True, nobroadcast=True,
num_retries=10 num_retries=10
) )
set_shared_steem_instance(cls.bts) set_shared_steem_instance(cls.bts)
acc = Account("fullnodeupdate", steem_instance=cls.bts) acc = Account("fullnodeupdate", steem_instance=cls.bts)
comment = Comment(acc.get_blog_entries(limit=10)[1], steem_instance=cls.bts) comment = Comment(acc.get_blog_entries(limit=5)[1], steem_instance=cls.bts)
cls.authorperm = comment.authorperm cls.authorperm = comment.authorperm
votes = comment.get_votes(raw_data=True) votes = comment.get_votes(raw_data=True)
last_vote = votes[-1] last_vote = votes[-1]
...@@ -53,7 +53,7 @@ class Testcases(unittest.TestCase): ...@@ -53,7 +53,7 @@ class Testcases(unittest.TestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
stm = Steem(node=get_hive_nodes()) stm = Hive(node=get_hive_nodes())
stm.config.recover_with_latest_backup() stm.config.recover_with_latest_backup()
@parameterized.expand([ @parameterized.expand([
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment