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

* Fix bug for get_estimated_block_num when a block is missing

parent 5af48705
No related branches found
No related tags found
No related merge requests found
Changelog Changelog
========= =========
0.20.22
-------
* Fix #195 - comment.downvote(100) will now downvote with 100%, negative numbers are not allowed anymore
* comment.upvote(), negative numbers are not allowed anymore
* Fix #193 - steem.vote() was added, so that voting is possible without tags_api
* PR #181 - improve permlink derivation by crokkon
* PR #192 - fixes compatibility issues with WhaleShares HF2 / v2.5 by alexpmorris
* Fix bug for get_estimated_block_num when a block is skipped
0.20.21 0.20.21
------- -------
* Fix float entered in Amount will be reduced by 0.001 due to rounding issues * Fix float entered in Amount will be reduced by 0.001 due to rounding issues
......
...@@ -310,6 +310,16 @@ class Blockchain(object): ...@@ -310,6 +310,16 @@ class Blockchain(object):
.. note:: The block number returned depends on the ``mode`` used .. note:: The block number returned depends on the ``mode`` used
when instantiating from this class. when instantiating from this class.
.. code-block:: python
>>> from beem.blockchain import Blockchain
>>> from datetime import datetime
>>> blockchain = Blockchain()
>>> block_num = blockchain.get_estimated_block_num(datetime(2019, 6, 18, 5 ,8, 27))
>>> block_num == 33898184
True
""" """
last_block = self.get_current_block() last_block = self.get_current_block()
date = addTzInfo(date) date = addTzInfo(date)
...@@ -328,9 +338,17 @@ class Blockchain(object): ...@@ -328,9 +338,17 @@ class Blockchain(object):
if block_number > last_block.identifier: if block_number > last_block.identifier:
block_number = last_block.identifier block_number = last_block.identifier
block_time_diff = timedelta(seconds=10) block_time_diff = timedelta(seconds=10)
last_block_time_diff_seconds = 10
second_last_block_time_diff_seconds = 10
while block_time_diff.total_seconds() > self.block_interval or block_time_diff.total_seconds() < -self.block_interval: while block_time_diff.total_seconds() > self.block_interval or block_time_diff.total_seconds() < -self.block_interval:
block = Block(block_number, steem_instance=self.steem) block = Block(block_number, steem_instance=self.steem)
second_last_block_time_diff_seconds = last_block_time_diff_seconds
last_block_time_diff_seconds = block_time_diff.total_seconds()
block_time_diff = date - block.time() block_time_diff = date - block.time()
if second_last_block_time_diff_seconds == block_time_diff.total_seconds() and second_last_block_time_diff_seconds < 10:
return int(block_number)
delta = block_time_diff.total_seconds() // self.block_interval delta = block_time_diff.total_seconds() // self.block_interval
if delta == 0 and block_time_diff.total_seconds() < 0: if delta == 0 and block_time_diff.total_seconds() < 0:
delta = -1 delta = -1
......
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