Skip to content

Commit 081c2e4

Browse files
committed
Replaced tx->input_amounts and tx->output_witscripts with tx->psbt.
1 parent 3bb640b commit 081c2e4

File tree

6 files changed

+102
-132
lines changed

6 files changed

+102
-132
lines changed

bitcoin/tx.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,12 +555,6 @@ struct bitcoin_tx *pull_bitcoin_tx(const tal_t *ctx, const u8 **cursor,
555555
wally_tx_get_length(tx->wtx, flags & ~WALLY_TX_FLAG_USE_ELEMENTS,
556556
&wsize);
557557

558-
/* We don't know the input amounts yet, so set them all to NULL */
559-
tx->input_amounts =
560-
tal_arrz(tx, struct amount_sat *, tx->wtx->inputs_allocation_len);
561-
/* Same for the output_witscripts. */
562-
tx->output_witscripts =
563-
tal_arrz(tx, struct witscript*, tx->wtx->outputs_allocation_len);
564558
tx->chainparams = chainparams;
565559

566560
tx->psbt = new_psbt(tx, tx->wtx);

contrib/remote_hsmd/dump.cc

Lines changed: 73 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -184,23 +184,10 @@ string dump_bitcoin_tx_outputs(const struct bitcoin_tx_output **outputs)
184184
return ostrm.str();
185185
}
186186

187-
string dump_input_amounts(const struct amount_sat **ias)
188-
{
189-
ostringstream ostrm;
190-
ostrm << "[";
191-
if (*ias) {
192-
for (size_t ii = 0; ii < tal_count(ias); ii++) {
193-
if (ii != 0)
194-
ostrm << ",";
195-
ostrm << ias[ii]->satoshis;
196-
}
197-
}
198-
ostrm << "]";
199-
return ostrm.str();
200-
}
201-
202187
string dump_wally_tx_witness_stack(const struct wally_tx_witness_stack *sp)
203188
{
189+
if (sp == NULL)
190+
return "[]";
204191
ostringstream ostrm;
205192
ostrm << "[";
206193
for (size_t ii = 0; ii < sp->num_items; ii++) {
@@ -247,6 +234,8 @@ string dump_wally_tx_inputs(const struct wally_tx_input *inputs,
247234

248235
string dump_wally_tx_output(const struct wally_tx_output *out)
249236
{
237+
if (out == NULL)
238+
return "{}";
250239
ostringstream ostrm;
251240
ostrm << "{ ";
252241
ostrm << "satoshi=" << out->satoshi;
@@ -274,6 +263,8 @@ string dump_wally_tx_outputs(const struct wally_tx_output *outputs,
274263

275264
string dump_wally_tx(const struct wally_tx *wtx)
276265
{
266+
if (wtx == NULL)
267+
return "{}";
277268
ostringstream ostrm;
278269
ostrm << "{ ";
279270
ostrm << "version=" << wtx->version;
@@ -288,32 +279,87 @@ string dump_wally_tx(const struct wally_tx *wtx)
288279
return ostrm.str();
289280
}
290281

291-
string dump_output_witscripts(const struct witscript **wp)
282+
string dump_wally_psbt_input(const struct wally_psbt_input *in)
283+
{
284+
ostringstream ostrm;
285+
ostrm << "{ ";
286+
ostrm << "non_witness_utxo=" << dump_wally_tx(in->non_witness_utxo);
287+
ostrm << ", witness_utxo=" << dump_wally_tx_output(in->witness_utxo);
288+
ostrm << ", redeem_script=" << dump_hex(in->redeem_script,
289+
in->redeem_script_len);
290+
ostrm << ", witness_script=" << dump_hex(in->witness_script,
291+
in->witness_script_len);
292+
ostrm << ", final_script_sig=" << dump_hex(in->final_script_sig,
293+
in->final_script_sig_len);
294+
ostrm << ", final_witness="
295+
<< dump_wally_tx_witness_stack(in->final_witness);
296+
ostrm << ", keypaths=??, partial_sigs==??, unknown=??";
297+
ostrm << ", sighash_type=" << in->sighash_type;
298+
ostrm << " }";
299+
return ostrm.str();
300+
}
301+
302+
string dump_wally_psbt_inputs(const struct wally_psbt_input *inputs,
303+
size_t num_inputs)
304+
{
305+
ostringstream ostrm;
306+
ostrm << "[";
307+
for (size_t ii = 0; ii < num_inputs; ii++) {
308+
if (ii != 0)
309+
ostrm << ",";
310+
ostrm << dump_wally_psbt_input(&inputs[ii]);
311+
}
312+
ostrm << "]";
313+
return ostrm.str();
314+
}
315+
316+
string dump_wally_psbt_output(const struct wally_psbt_output *out)
317+
{
318+
ostringstream ostrm;
319+
ostrm << "{ ";
320+
ostrm << "redeem_script=" << dump_hex(out->redeem_script,
321+
out->redeem_script_len);
322+
ostrm << ", witness_script=" << dump_hex(out->witness_script,
323+
out->witness_script_len);
324+
ostrm << ", keypaths=??, unknown=??";
325+
ostrm << " }";
326+
return ostrm.str();
327+
328+
}
329+
330+
string dump_wally_psbt_outputs(const struct wally_psbt_output *outputs,
331+
size_t num_outputs)
292332
{
293333
ostringstream ostrm;
294334
ostrm << "[";
295-
for (size_t ii = 0; ii < tal_count(wp); ii++) {
335+
for (size_t ii = 0; ii < num_outputs; ii++) {
296336
if (ii != 0)
297337
ostrm << ",";
298-
ostrm << (wp[ii] ?
299-
dump_hex(wp[ii]->ptr, tal_count(wp[ii]->ptr)) :
300-
"<none>");
338+
ostrm << dump_wally_psbt_output(&outputs[ii]);
301339
}
302340
ostrm << "]";
303341
return ostrm.str();
304342
}
305343

344+
string dump_wally_psbt(const struct wally_psbt *psbt)
345+
{
346+
ostringstream ostrm;
347+
ostrm << "{ ";
348+
ostrm << "tx=" << dump_wally_tx(psbt->tx);
349+
ostrm << ", inputs="
350+
<< dump_wally_psbt_inputs(psbt->inputs, psbt->num_inputs);
351+
ostrm << ", outputs="
352+
<< dump_wally_psbt_outputs(psbt->outputs, psbt->num_outputs);
353+
ostrm << " }";
354+
return ostrm.str();
355+
}
356+
306357
string dump_tx(const struct bitcoin_tx *tx)
307358
{
308359
ostringstream ostrm;
309360
ostrm << "{ ";
310-
ostrm << "input_amounts=" <<
311-
dump_input_amounts(
312-
(const struct amount_sat **)tx->input_amounts);
313-
ostrm << ", wally_tx=" << dump_wally_tx(tx->wtx);
314-
ostrm << ", output_witscripts=" <<
315-
dump_output_witscripts(
316-
(const struct witscript **)tx->output_witscripts);
361+
ostrm << ", wtx=" << dump_wally_tx(tx->wtx);
362+
ostrm << ", psbt=" << dump_wally_psbt(tx->psbt);
317363
ostrm << " }";
318364
return ostrm.str();
319365
}

contrib/remote_hsmd/dump.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ std::string dump_utxo(const struct utxo *in);
1616
std::string dump_utxos(const struct utxo **utxos);
1717
std::string dump_bitcoin_tx_output(const struct bitcoin_tx_output *op);
1818
std::string dump_bitcoin_tx_outputs(const struct bitcoin_tx_output **outputs);
19-
std::string dump_input_amounts(const struct amount_sat **ias);
2019
std::string dump_wally_tx_witness_stack(const struct wally_tx_witness_stack *sp);
2120
std::string dump_wally_tx_input(const struct wally_tx_input *in);
2221
std::string dump_wally_tx_inputs(const struct wally_tx_input *inputs,
@@ -25,5 +24,5 @@ std::string dump_wally_tx_output(const struct wally_tx_output *out);
2524
std::string dump_wally_tx_outputs(const struct wally_tx_output *outputs,
2625
size_t num_outputs);
2726
std::string dump_wally_tx(const struct wally_tx *wtx);
28-
std::string dump_output_witscripts(const struct witscript **wp);
27+
std::string dump_wally_psbt(const struct wally_psbt *psbt);
2928
std::string dump_tx(const struct bitcoin_tx *tx);

0 commit comments

Comments
 (0)