@@ -9,6 +9,7 @@ extern "C" {
99#include < bitcoin/chainparams.h>
1010#include < bitcoin/privkey.h>
1111#include < bitcoin/psbt.h>
12+ #include < bitcoin/script.h>
1213#include < bitcoin/short_channel_id.h>
1314#include < bitcoin/tx.h>
1415#include < common/derive_basepoints.h>
@@ -588,12 +589,12 @@ proxy_stat proxy_handle_ready_channel(
588589 req.set_push_value_msat (push_value->millisatoshis );
589590 marshal_outpoint (funding_txid,
590591 funding_txout, req.mutable_funding_outpoint ());
591- req.set_holder_to_self_delay (holder_to_self_delay);
592+ req.set_holder_selected_contest_delay (holder_to_self_delay);
592593 marshal_script (holder_shutdown_script,
593594 req.mutable_holder_shutdown_script ());
594595 marshal_basepoints (counterparty_basepoints, counterparty_funding_pubkey,
595596 req.mutable_counterparty_basepoints ());
596- req.set_counterparty_to_self_delay (counterparty_to_self_delay);
597+ req.set_counterparty_selected_contest_delay (counterparty_to_self_delay);
597598 marshal_script (counterparty_shutdown_script,
598599 req.mutable_counterparty_shutdown_script ());
599600 if (option_anchor_outputs)
@@ -623,33 +624,58 @@ proxy_stat proxy_handle_ready_channel(
623624}
624625
625626proxy_stat proxy_handle_sign_withdrawal_tx (
626- struct node_id *peer_id,
627- u64 dbid,
628627 struct bitcoin_tx_output **outputs,
629628 struct utxo **utxos,
630629 struct wally_psbt *psbt,
631630 u8 ****o_wits)
632631{
633632 STATUS_DEBUG (
634633 " %s:%d %s { "
635- " \" self_id\" :%s, \" peer_id \" :%s, \" dbid \" :% " PRIu64 " , "
634+ " \" self_id\" :%s, "
636635 " \" utxos\" :%s, \" outputs\" :%s, \" psbt\" :%s }" ,
637636 __FILE__, __LINE__, __FUNCTION__,
638637 dump_node_id (&self_id).c_str (),
639- dump_node_id (peer_id).c_str (),
640- dbid,
641638 dump_utxos ((const struct utxo **)utxos).c_str (),
642639 dump_bitcoin_tx_outputs (
643640 (const struct bitcoin_tx_output **)outputs).c_str (),
644641 dump_wally_psbt (psbt).c_str ()
645642 );
646643
647644 last_message = " " ;
645+
646+ // This code is mimicking psbt_txid at bitcoin/psbt.c:796:
647+ //
648+ /* You can *almost* take txid of global tx. But @niftynei thought
649+ * about this far more than me and pointed out that P2SH
650+ * inputs would not be represented, so here we go. */
651+ struct wally_tx *tx;
652+ tal_wally_start ();
653+ wally_tx_clone_alloc (psbt->tx , 0 , &tx);
654+ for (size_t i = 0 ; i < tx->num_inputs ; i++) {
655+ if (psbt->inputs [i].final_scriptsig ) {
656+ wally_tx_set_input_script (tx, i,
657+ psbt->inputs [i].final_scriptsig ,
658+ psbt->inputs [i].final_scriptsig_len );
659+ } else if (psbt->inputs [i].redeem_script ) {
660+ u8 *script;
661+
662+ /* P2SH requires push of the redeemscript, from libwally src */
663+ script = tal_arr (tmpctx, u8 , 0 );
664+ script_push_bytes (&script,
665+ psbt->inputs [i].redeem_script ,
666+ psbt->inputs [i].redeem_script_len );
667+ wally_tx_set_input_script (tx, i, script, tal_bytelen (script));
668+ }
669+ }
670+ tal_wally_end (tal_steal (psbt, tx));
671+
672+
648673 SignFundingTxRequest req;
649674 marshal_node_id (&self_id, req.mutable_node_id ());
650- marshal_channel_nonce (peer_id, dbid, req.mutable_channel_nonce ());
651675
652- req.mutable_tx ()->set_raw_tx_bytes (serialized_wtx (psbt->tx , true ));
676+ // Serialize the tx we modified above which includes witscripts.
677+ req.mutable_tx ()->set_raw_tx_bytes (serialized_wtx (tx, true ));
678+
653679 assert (psbt->tx ->num_inputs >= tal_count (utxos));
654680 size_t uu = 0 ;
655681 for (size_t ii = 0 ; ii < psbt->tx ->num_inputs ; ++ii) {
@@ -664,6 +690,20 @@ proxy_stat proxy_handle_sign_withdrawal_tx(
664690 }
665691 assert (uu == tal_count (utxos));
666692
693+ for (size_t ii = 0 ; ii < psbt->tx ->num_outputs ; ++ii) {
694+ OutputDescriptor *odesc = req.mutable_tx ()->add_output_descs ();
695+ struct wally_map *mp = &psbt->outputs [ii].keypaths ;
696+ if (mp->num_items == 1 ) {
697+ const struct wally_map_item *ip = &mp->items [0 ];
698+ size_t npath =
699+ (ip->value_len - BIP32_KEY_FINGERPRINT_LEN) / sizeof (uint32_t );
700+ uint32_t *path = (uint32_t *) (ip->value + BIP32_KEY_FINGERPRINT_LEN);
701+ for (size_t jj = 0 ; jj < npath; ++jj) {
702+ odesc->mutable_key_loc ()->add_key_path (le32_to_cpu (path[jj]));
703+ }
704+ }
705+ }
706+
667707 ClientContext context;
668708 SignFundingTxReply rsp;
669709 Status status = stub->SignFundingTx (&context, req, &rsp);
0 commit comments