@@ -66,17 +66,21 @@ def signet_txs(block, challenge):
66
66
67
67
return spend , to_spend
68
68
69
- def decode_psbt (b64psbt ):
69
+ def decode_challenge_psbt (b64psbt ):
70
70
psbt = PSBT .from_base64 (b64psbt )
71
71
72
72
assert len (psbt .tx .vin ) == 1
73
73
assert len (psbt .tx .vout ) == 1
74
74
assert PSBT_SIGNET_BLOCK in psbt .g .map
75
+ return psbt
75
76
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 ):
76
81
scriptSig = psbt .i [0 ].map .get (PSBT_IN_FINAL_SCRIPTSIG , b"" )
77
82
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
80
84
81
85
def finish_block (block , signet_solution , grind_cmd ):
82
86
block .vtx [0 ].vout [- 1 ].scriptPubKey += CScriptOp .encode_op_pushdata (SIGNET_HEADER + signet_solution )
@@ -180,7 +184,9 @@ def do_genpsbt(args):
180
184
print (psbt )
181
185
182
186
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 )
184
190
block = finish_block (block , signet_solution , args .grind_cmd )
185
191
print (block .serialize ().hex ())
186
192
@@ -330,7 +336,9 @@ class Generate:
330
336
logging .debug ("Generated PSBT: %s" % (psbt ,))
331
337
sys .stderr .write ("PSBT signing failed\n " )
332
338
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 )
334
342
return finish_block (block , signet_solution , grind_cmd )
335
343
336
344
def do_generate (args ):
0 commit comments