Skip to content

Commit

Permalink
Use the last irreversible block for tapos ref params
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Oct 4, 2019
1 parent 1026f72 commit b3d6cda
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
4 changes: 4 additions & 0 deletions .changes/next-release/minor-20191004132521.json
@@ -0,0 +1,4 @@
{
"type": "minor",
"description": "Use the last irreversible block for tapos ref params"
}
12 changes: 5 additions & 7 deletions graphenebase/transactions.py
Expand Up @@ -16,17 +16,15 @@
timeformat = "%Y-%m-%dT%H:%M:%S%Z"


def getBlockParams(ws):
def getBlockParams(ws, use_head_block=False):
""" Auxiliary method to obtain ``ref_block_num`` and
``ref_block_prefix``. Requires a websocket connection to a
witness node!
"""
dynBCParams = ws.get_dynamic_global_properties()
ref_block_num = dynBCParams["head_block_number"] & 0xFFFF
ref_block_prefix = struct.unpack_from(
"<I", unhexlify(dynBCParams["head_block_id"]), 4
)[0]
return ref_block_num, ref_block_prefix
raise DeprecationWarning(
"This method shouldn't be called anymore. It is part of "
"transactionbuilder now"
)


def formatTimeFromNow(secs=0):
Expand Down
18 changes: 13 additions & 5 deletions graphenecommon/transactionbuilder.py
Expand Up @@ -405,17 +405,25 @@ def constructTx(self):
dict.update(self, self.tx.json())
self._unset_require_reconstruction()

def get_block_params(self):
def get_block_params(self, use_head_block=False):
""" Auxiliary method to obtain ``ref_block_num`` and
``ref_block_prefix``. Requires a websocket connection to a
witness node!
"""
ws = self.blockchain.rpc
dynBCParams = ws.get_dynamic_global_properties()
ref_block_num = dynBCParams["head_block_number"] & 0xFFFF
ref_block_prefix = struct.unpack_from(
"<I", unhexlify(dynBCParams["head_block_id"]), 4
)[0]
if use_head_block:
ref_block_num = dynBCParams["head_block_number"] & 0xFFFF
ref_block_prefix = struct.unpack_from(
"<I", unhexlify(dynBCParams["head_block_id"]), 4
)[0]
else:
# need to get subsequent block because block head doesn't return 'id' - stupid
block = ws.get_block_header(int(dynBCParams["last_irreversible_block_num"])+1)
ref_block_num = dynBCParams["last_irreversible_block_num"] & 0xFFFF
ref_block_prefix = struct.unpack_from(
"<I", unhexlify(block["previous"]), 4
)[0]
return ref_block_num, ref_block_prefix

def sign(self):
Expand Down

0 comments on commit b3d6cda

Please sign in to comment.