|
5 | 5 | """Utilities for manipulating blocks and transactions.""" |
6 | 6 |
|
7 | 7 | from test_framework.mininode import * |
8 | | -from test_framework.script import CScript, OP_TRUE, OP_CHECKSIG |
| 8 | +from test_framework.script import CScript, CScriptNum, CScriptOp, OP_TRUE, OP_CHECKSIG, OP_1 |
9 | 9 |
|
10 | 10 |
|
11 | 11 | # Create a block (with regtest difficulty) |
@@ -42,19 +42,23 @@ def serialize_script_num(value): |
42 | 42 | r[-1] |= 0x80 |
43 | 43 | return r |
44 | 44 |
|
45 | | -def cbase_scriptsig(height): |
46 | | - return ser_string(serialize_script_num(height)) |
47 | | - |
48 | 45 | def cbase_value(height): |
49 | 46 | #return ((50 * COIN) >> int(height/150)) |
50 | 47 | return (250 * COIN) |
51 | 48 |
|
| 49 | +def script_BIP34_coinbase_height(height): |
| 50 | + if height <= 16: |
| 51 | + res = CScriptOp.encode_op_n(height) |
| 52 | + # Append dummy to increase scriptSig size above 2 (see bad-cb-length consensus rule) |
| 53 | + return CScript([res, OP_1]) |
| 54 | + return CScript([CScriptNum(height)]) |
| 55 | + |
52 | 56 | # Create a coinbase transaction, assuming no miner fees. |
53 | 57 | # If pubkey is passed in, the coinbase output will be a P2PK output; |
54 | 58 | # otherwise an anyone-can-spend output. |
55 | 59 | def create_coinbase(height, pubkey = None): |
56 | 60 | coinbase = CTransaction() |
57 | | - coinbase.vin = [CTxIn(NullOutPoint, cbase_scriptsig(height), 0xffffffff)] |
| 61 | + coinbase.vin = [CTxIn(NullOutPoint, script_BIP34_coinbase_height(height), 0xffffffff)] |
58 | 62 | coinbaseoutput = CTxOut() |
59 | 63 | coinbaseoutput.nValue = cbase_value(height) |
60 | 64 | if (pubkey != None): |
@@ -100,7 +104,7 @@ def get_legacy_sigopcount_tx(tx, fAccurate=True): |
100 | 104 | ### PIVX specific blocktools ### |
101 | 105 | def create_coinbase_pos(height): |
102 | 106 | coinbase = CTransaction() |
103 | | - coinbase.vin = [CTxIn(NullOutPoint, cbase_scriptsig(height), 0xffffffff)] |
| 107 | + coinbase.vin = [CTxIn(NullOutPoint, script_BIP34_coinbase_height(height), 0xffffffff)] |
104 | 108 | coinbase.vout = [CTxOut(0, b"")] |
105 | 109 | coinbase.calc_sha256() |
106 | 110 | return coinbase |
0 commit comments