@@ -140,36 +140,38 @@ void marshal_single_input_tx(struct bitcoin_tx const *tx,
140140 if (output_witscript) {
141141 /* Called with a single witscript. */
142142 assert (tx->wtx ->num_outputs == 1 );
143- o_tp->add_output_witscripts ((const char *) output_witscript,
144- tal_count (output_witscript));
145143 } else if (output_witscripts) {
146144 /* Called with an array of witscripts. */
147- size_t nwitscripts = tal_count (output_witscripts);
148- assert (nwitscripts == tx->wtx ->num_outputs );
149- for (size_t ii = 0 ; ii < tx->wtx ->num_outputs ; ii++)
150- if (output_witscripts[ii])
151- o_tp->add_output_witscripts (
152- (const char *)
153- output_witscripts[ii]->ptr ,
154- tal_count (output_witscripts[ii]->ptr ));
155- else
156- o_tp->add_output_witscripts (" " );
157- } else {
158- /* Called with no witscrtipts. */
159- for (size_t ii = 0 ; ii < tx->wtx ->num_outputs ; ii++)
160- o_tp->add_output_witscripts (" " );
145+ assert (tal_count (output_witscripts) == tx->wtx ->num_outputs );
161146 }
162147
163148 o_tp->set_raw_tx_bytes (serialized_tx (tx, true ));
164149
165150 assert (tx->wtx ->num_inputs == 1 );
166- SignDescriptor *desc = o_tp->add_input_descs ();
167- desc-> mutable_output ()->set_value (tx->input_amounts [0 ]->satoshis );
151+ InputDescriptor *idesc = o_tp->add_input_descs ();
152+ idesc-> mutable_prev_output ()->set_value (tx->input_amounts [0 ]->satoshis );
168153 /* FIXME - What else needs to be set? */
169154
170155 for (size_t ii = 0 ; ii < tx->wtx ->num_outputs ; ii++) {
171- SignDescriptor *desc = o_tp->add_output_descs ();
172- /* FIXME - We don't need to set *anything* here? */
156+ OutputDescriptor *odesc = o_tp->add_output_descs ();
157+ if (output_witscript) {
158+ /* We have a single witscript. */
159+ odesc->set_witscript ((const char *) output_witscript,
160+ tal_count (output_witscript));
161+ } else if (output_witscripts) {
162+ /* We have an array of witscripts. */
163+ if (output_witscripts[ii])
164+ odesc->set_witscript (
165+ (const char *)
166+ output_witscripts[ii]->ptr ,
167+ tal_count (output_witscripts[ii]->ptr ));
168+ else
169+ odesc->set_witscript (" " );
170+ } else {
171+ /* Called w/ no witscripts. */
172+ odesc->set_witscript (" " );
173+ }
174+
173175 }
174176}
175177
@@ -227,23 +229,17 @@ void unmarshal_ecdsa_recoverable_signature(ECDSARecoverableSignature const &es,
227229 assert (ok);
228230}
229231
230- void unmarshal_witnesses (RepeatedPtrField<WitnessStack > const &wits ,
231- u8 * ***o_sigs)
232+ void unmarshal_signatures (RepeatedPtrField<BitcoinSignature > const &sigs ,
233+ u8 ***o_sigs)
232234{
233- u8 *** osigs = NULL ;
234- int nsigs = wits .size ();
235+ u8 **osigs = NULL ;
236+ int nsigs = sigs .size ();
235237 if (nsigs > 0 ) {
236- osigs = tal_arrz (tmpctx, u8 ** , nsigs);
238+ osigs = tal_arrz (tmpctx, u8 *, nsigs);
237239 for (size_t ii = 0 ; ii < nsigs; ++ii) {
238- WitnessStack const &sig = wits[ii];
239- int nelem = sig.item_size ();
240- osigs[ii] = tal_arrz (osigs, u8 *, nelem);
241- for (size_t jj = 0 ; jj < nelem; ++jj) {
242- string const &elem = sig.item (jj);
243- size_t elen = elem.size ();
244- osigs[ii][jj] = tal_arr (osigs[ii], u8 , elen);
245- memcpy (osigs[ii][jj], &elem[0 ], elen);
246- }
240+ BitcoinSignature const &bs = sigs[ii];
241+ osigs[ii] = tal_arr (osigs, u8 , bs.data ().size ());
242+ memcpy (osigs[ii], bs.data ().data (), bs.data ().size ());
247243 }
248244 }
249245 *o_sigs = osigs;
@@ -397,8 +393,25 @@ proxy_stat proxy_handle_sign_withdrawal_tx(
397393 struct bitcoin_tx_output **outputs,
398394 struct utxo **utxos,
399395 struct bitcoin_tx *tx,
400- u8 **** o_sigs)
396+ u8 ***o_sigs)
401397{
398+ fprintf (stderr,
399+ " %s:%d %s self_id=%s peer_id=%s dbid=%" PRIu64 " "
400+ " satoshi_out=%" PRIu64 " change_out=%" PRIu64 " "
401+ " change_keyindex=%u utxos=%s outputs=%s tx=%s\n " ,
402+ __FILE__, __LINE__, __FUNCTION__,
403+ dump_node_id (&self_id).c_str (),
404+ dump_node_id (peer_id).c_str (),
405+ dbid,
406+ satoshi_out->satoshis ,
407+ change_out->satoshis ,
408+ change_keyindex,
409+ dump_utxos ((const struct utxo **)utxos).c_str (),
410+ dump_bitcoin_tx_outputs (
411+ (const struct bitcoin_tx_output **)outputs).c_str (),
412+ dump_tx (tx).c_str ()
413+ );
414+
402415 status_debug (
403416 " %s:%d %s self_id=%s peer_id=%s dbid=%" PRIu64 " "
404417 " satoshi_out=%" PRIu64 " change_out=%" PRIu64 " "
@@ -427,9 +440,12 @@ proxy_stat proxy_handle_sign_withdrawal_tx(
427440 const struct utxo *in = utxos[ii];
428441 /* Fails in tests/test_closing.py::test_onchain_first_commit */
429442 /* assert(!in->is_p2sh); */
430- SignDescriptor *desc = req.mutable_tx ()->add_input_descs ();
431- desc->mutable_key_loc ()->set_key_index (in->keyindex );
432- desc->mutable_output ()->set_value (in->amount .satoshis );
443+ InputDescriptor *idesc = req.mutable_tx ()->add_input_descs ();
444+ idesc->mutable_key_loc ()->set_key_index (in->keyindex );
445+ idesc->mutable_prev_output ()->set_value (in->amount .satoshis );
446+ idesc->set_spend_type (in->is_p2sh
447+ ? SpendType::P2SH_P2WPKH
448+ : SpendType::P2WPKH);
433449 }
434450
435451 /* We expect exactly two total ouputs, with one non-change. */
@@ -440,7 +456,7 @@ proxy_stat proxy_handle_sign_withdrawal_tx(
440456 assert (tal_count (outputs) == 1 );
441457 for (size_t ii = 0 ; ii < tx->wtx ->num_outputs ; ii++) {
442458 const struct wally_tx_output *out = &tx->wtx ->outputs [ii];
443- SignDescriptor *desc = req.mutable_tx ()->add_output_descs ();
459+ OutputDescriptor *odesc = req.mutable_tx ()->add_output_descs ();
444460 /* Does this output match the funding output? */
445461 if (memeq (out->script , out->script_len ,
446462 outputs[0 ]->script , tal_count (outputs[0 ]->script ))) {
@@ -449,22 +465,31 @@ proxy_stat proxy_handle_sign_withdrawal_tx(
449465 } else {
450466 /* Nope, this must be the change output. */
451467 assert (out->satoshi == change_out->satoshis );
452- desc->mutable_key_loc ()->set_key_index (change_keyindex);
468+ odesc->mutable_key_loc ()->
469+ set_key_index (change_keyindex);
453470 }
454471 }
455472
456473 ClientContext context;
457474 SignFundingTxReply rsp;
458475 Status status = stub->SignFundingTx (&context, req, &rsp);
459476 if (status.ok ()) {
460- unmarshal_witnesses (rsp.witnesses (), o_sigs);
477+ unmarshal_signatures (rsp.signatures (), o_sigs);
478+ fprintf (stderr, " %s:%d %s self_id=%s witnesses=%s\n " ,
479+ __FILE__, __LINE__, __FUNCTION__,
480+ dump_node_id (&self_id).c_str (),
481+ dump_signatures ((u8 const **) *o_sigs).c_str ());
461482 status_debug (" %s:%d %s self_id=%s witnesses=%s" ,
462483 __FILE__, __LINE__, __FUNCTION__,
463484 dump_node_id (&self_id).c_str (),
464- dump_witnesses ((u8 const * **) *o_sigs).c_str ());
485+ dump_signatures ((u8 const **) *o_sigs).c_str ());
465486 last_message = " success" ;
466487 return PROXY_OK;
467488 } else {
489+ fprintf (stderr, " %s:%d %s: self_id=%s %s\n " ,
490+ __FILE__, __LINE__, __FUNCTION__,
491+ dump_node_id (&self_id).c_str (),
492+ status.error_message ().c_str ());
468493 status_unusual (" %s:%d %s: self_id=%s %s" ,
469494 __FILE__, __LINE__, __FUNCTION__,
470495 dump_node_id (&self_id).c_str (),
@@ -1236,4 +1261,11 @@ proxy_stat proxy_handle_sign_node_announcement(
12361261 }
12371262}
12381263
1264+ // FIXME - This routine allows us to pretty print the tx to stderr
1265+ // from C code. Probably should remove it in production ...
1266+ void print_tx (char const *tag, struct bitcoin_tx const *tx)
1267+ {
1268+ fprintf (stderr, " %s: tx=%s\n " , tag, dump_tx (tx).c_str ());
1269+ }
1270+
12391271} /* extern "C" */
0 commit comments