@@ -1638,7 +1638,6 @@ static struct io_plan *handle_sign_withdrawal_tx(struct io_conn *conn,
16381638 u32 change_keyindex ;
16391639 struct utxo * * utxos ;
16401640 struct bitcoin_tx * tx ;
1641- struct bitcoin_tx * tx2 ; // REF
16421641 struct pubkey changekey ;
16431642 struct bitcoin_tx_output * * outputs ;
16441643 u32 nlocktime ;
@@ -1652,77 +1651,60 @@ static struct io_plan *handle_sign_withdrawal_tx(struct io_conn *conn,
16521651 return bad_req_fmt (conn , c , msg_in ,
16531652 "Failed to get key %u" , change_keyindex );
16541653
1654+ // FIXME - The next few lines are for debug, remove them.
1655+ struct bitcoin_tx * tx2 =
1656+ withdraw_tx (tmpctx , c -> chainparams ,
1657+ cast_const2 (const struct utxo * * , utxos ), outputs ,
1658+ & changekey , change_out , NULL , NULL , nlocktime );
1659+ sign_all_inputs (tx2 , utxos );
1660+ print_tx ("REF" , tx2 );
1661+
16551662 tx = withdraw_tx (tmpctx , c -> chainparams ,
16561663 cast_const2 (const struct utxo * * , utxos ), outputs ,
16571664 & changekey , change_out , NULL , NULL , nlocktime );
16581665
1659- /* FIXME - There are things we can't do remotely yet:
1660- * 2. Handle inputs w/ close_info.
1661- */
1662- bool demure = false;
1663- for (size_t ii = 0 ; ii < tx -> wtx -> num_inputs ; ii ++ )
1664- if (utxos [ii ]-> close_info )
1665- demure = true;
1666-
1667- if (!demure ) {
1668- u8 * * sigs ;
1669- proxy_stat rv = proxy_handle_sign_withdrawal_tx (
1670- & c -> id , c -> dbid , & satoshi_out ,
1671- & change_out , change_keyindex ,
1672- outputs , utxos , tx , & sigs );
1673- if (PROXY_PERMANENT (rv ))
1674- status_failed (STATUS_FAIL_INTERNAL_ERROR ,
1675- "proxy_%s failed: %s" , __FUNCTION__ ,
1676- proxy_last_message ());
1677- else if (!PROXY_SUCCESS (rv ))
1678- return bad_req_fmt (conn , c , msg_in ,
1679- "proxy_%s error: %s" , __FUNCTION__ ,
1680- proxy_last_message ());
1681-
1682- /* Sign w/ the remote lightning-signer. */
1683- g_proxy_impl = PROXY_IMPL_COMPLETE ;
1684- assert (tal_count (sigs ) == tal_count (utxos ));
1685- for (size_t ii = 0 ; ii < tal_count (sigs ); ++ ii ) {
1686- /* Figure out keys to spend this. */
1687- struct pubkey inkey ;
1688- u8 der_pubkey [PUBKEY_CMPR_LEN ];
1689- const struct utxo * in = utxos [ii ];
1690- hsm_key_for_utxo (NULL , & inkey , in );
1691- pubkey_to_der (der_pubkey , & inkey );
1692-
1693- if (in -> is_p2sh ) {
1694- u8 * script = bitcoin_scriptsig_p2sh_p2wpkh (
1695- tx , & inkey );
1696- bitcoin_tx_input_set_script (tx , ii , script );
1697-
1698- } else {
1699- bitcoin_tx_input_set_script (tx , ii , NULL );
1700- }
1701-
1702- u8 * * witness = tal_arr (tx , u8 * , 2 );
1703- witness [0 ] = tal_dup_arr (witness , u8 ,
1704- sigs [ii ],
1705- tal_count (sigs [ii ]), 0 );
1706- witness [1 ] = tal_dup_arr (witness , u8 ,
1707- der_pubkey ,
1708- sizeof (der_pubkey ), 0 );
1709- bitcoin_tx_input_set_witness (tx , ii , take (witness ));
1710- }
1666+ u8 * * * wits ;
1667+ proxy_stat rv = proxy_handle_sign_withdrawal_tx (
1668+ & c -> id , c -> dbid , & satoshi_out ,
1669+ & change_out , change_keyindex ,
1670+ outputs , utxos , tx , & wits );
1671+ if (PROXY_PERMANENT (rv ))
1672+ status_failed (STATUS_FAIL_INTERNAL_ERROR ,
1673+ "proxy_%s failed: %s" , __FUNCTION__ ,
1674+ proxy_last_message ());
1675+ else if (!PROXY_SUCCESS (rv ))
1676+ return bad_req_fmt (conn , c , msg_in ,
1677+ "proxy_%s error: %s" , __FUNCTION__ ,
1678+ proxy_last_message ());
17111679
1712- print_tx ("RLS" , tx );
1713- } else {
1714- /* It's P2SH, need to sign here */
1715- g_proxy_impl = PROXY_IMPL_MARSHALED ;
1716- sign_all_inputs (tx , utxos );
1717- }
1680+ /* Sign w/ the remote lightning-signer. */
1681+ g_proxy_impl = PROXY_IMPL_COMPLETE ;
1682+ assert (tal_count (wits ) == tal_count (utxos ));
1683+ for (size_t ii = 0 ; ii < tal_count (wits ); ++ ii ) {
1684+ struct pubkey inkey ;
1685+ bool ok = pubkey_from_der (
1686+ wits [ii ][1 ], tal_count (wits [ii ][1 ]), & inkey );
1687+ assert (ok );
17181688
1719- tx2 = withdraw_tx (tmpctx , c -> chainparams ,
1720- cast_const2 (const struct utxo * * , utxos ), outputs ,
1721- & changekey , change_out , NULL , NULL , nlocktime );
1689+ if (utxos [ii ]-> is_p2sh ) {
1690+ u8 * script = bitcoin_scriptsig_p2sh_p2wpkh (
1691+ tx , & inkey );
1692+ bitcoin_tx_input_set_script (tx , ii , script );
17221693
1723- sign_all_inputs (tx2 , utxos );
1694+ } else {
1695+ bitcoin_tx_input_set_script (tx , ii , NULL );
1696+ }
17241697
1725- print_tx ("REF" , tx2 );
1698+ u8 * * witness = tal_arr (tx , u8 * , 2 );
1699+ witness [0 ] = tal_dup_arr (witness , u8 ,
1700+ wits [ii ][0 ],
1701+ tal_count (wits [ii ][0 ]), 0 );
1702+ witness [1 ] = tal_dup_arr (witness , u8 ,
1703+ wits [ii ][1 ],
1704+ tal_count (wits [ii ][1 ]), 0 );
1705+ bitcoin_tx_input_set_witness (tx , ii , take (witness ));
1706+ }
1707+ print_tx ("RLS" , tx );
17261708
17271709 return req_reply (conn , c ,
17281710 take (towire_hsm_sign_withdrawal_reply (NULL , tx )));
0 commit comments