Skip to content

Commit cdfb70e

Browse files
committed
signet: split decode_psbt miner helper
1 parent 7710a31 commit cdfb70e

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

contrib/signet/miner

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,21 @@ def signet_txs(block, challenge):
6666

6767
return spend, to_spend
6868

69-
def decode_psbt(b64psbt):
69+
def decode_challenge_psbt(b64psbt):
7070
psbt = PSBT.from_base64(b64psbt)
7171

7272
assert len(psbt.tx.vin) == 1
7373
assert len(psbt.tx.vout) == 1
7474
assert PSBT_SIGNET_BLOCK in psbt.g.map
75+
return psbt
7576

77+
def get_block_from_psbt(psbt):
78+
return from_binary(CBlock, psbt.g.map[PSBT_SIGNET_BLOCK])
79+
80+
def get_solution_from_psbt(psbt):
7681
scriptSig = psbt.i[0].map.get(PSBT_IN_FINAL_SCRIPTSIG, b"")
7782
scriptWitness = psbt.i[0].map.get(PSBT_IN_FINAL_SCRIPTWITNESS, b"\x00")
78-
79-
return from_binary(CBlock, psbt.g.map[PSBT_SIGNET_BLOCK]), ser_string(scriptSig) + scriptWitness
83+
return ser_string(scriptSig) + scriptWitness
8084

8185
def finish_block(block, signet_solution, grind_cmd):
8286
block.vtx[0].vout[-1].scriptPubKey += CScriptOp.encode_op_pushdata(SIGNET_HEADER + signet_solution)
@@ -180,7 +184,9 @@ def do_genpsbt(args):
180184
print(psbt)
181185

182186
def do_solvepsbt(args):
183-
block, signet_solution = decode_psbt(sys.stdin.read())
187+
psbt = decode_challenge_psbt(sys.stdin.read())
188+
block = get_block_from_psbt(psbt)
189+
signet_solution = get_solution_from_psbt(psbt)
184190
block = finish_block(block, signet_solution, args.grind_cmd)
185191
print(block.serialize().hex())
186192

@@ -330,7 +336,9 @@ class Generate:
330336
logging.debug("Generated PSBT: %s" % (psbt,))
331337
sys.stderr.write("PSBT signing failed\n")
332338
return None
333-
block, signet_solution = decode_psbt(psbt_signed["psbt"])
339+
psbt = decode_challenge_psbt(psbt_signed["psbt"])
340+
block = get_block_from_psbt(psbt)
341+
signet_solution = get_solution_from_psbt(psbt)
334342
return finish_block(block, signet_solution, grind_cmd)
335343

336344
def do_generate(args):

0 commit comments

Comments
 (0)