Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14864867
D10688.id31448.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
D10688.id31448.diff
View Options
diff --git a/test/functional/test_framework/blocktools.py b/test/functional/test_framework/blocktools.py
--- a/test/functional/test_framework/blocktools.py
+++ b/test/functional/test_framework/blocktools.py
@@ -4,7 +4,10 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Utilities for manipulating blocks and transactions."""
+import struct
+import time
import unittest
+from binascii import a2b_hex
from .messages import (
COIN,
@@ -36,18 +39,22 @@
TIME_GENESIS_BLOCK = 1296688602
-def create_block(hashprev, coinbase, ntime=None, *, version=1):
+def create_block(hashprev=None, coinbase=None, ntime=None,
+ *, version=None, tmpl=None):
"""Create a block (with regtest difficulty)."""
block = CBlock()
- block.nVersion = version
- if ntime is None:
- import time
- block.nTime = int(time.time() + 600)
+ if tmpl is None:
+ tmpl = {}
+ block.nVersion = version or tmpl.get('version', 1)
+ block.nTime = ntime or tmpl.get('curtime', int(time.time() + 600))
+ block.hashPrevBlock = hashprev or int(tmpl['previousblockhash'], 0x10)
+ if "bits" in tmpl:
+ block.nBits = struct.unpack('>I', a2b_hex(tmpl['bits']))[0]
else:
- block.nTime = ntime
- block.hashPrevBlock = hashprev
- # difficulty retargeting is disabled in REGTEST chainparams
- block.nBits = 0x207fffff
+ # difficulty retargeting is disabled in REGTEST chainparams
+ block.nBits = 0x207fffff
+ if coinbase is None:
+ coinbase = create_coinbase(height=tmpl['height'])
block.vtx.append(coinbase)
block.hashMerkleRoot = block.calc_merkle_root()
block.calc_sha256()
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, May 20, 22:55 (4 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5866104
Default Alt Text
D10688.id31448.diff (1 KB)
Attached To
D10688: QA: blocktools: Accept block template to create_block
Event Timeline
Log In to Comment