wally: Migrate the funding transaction to use the shims

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2019-03-14 16:21:45 +01:00 committed by Rusty Russell
parent 7e03db5062
commit 98983006d6
2 changed files with 14 additions and 13 deletions

View File

@ -26,19 +26,18 @@ struct bitcoin_tx *funding_tx(const tal_t *ctx,
tx = tx_spending_utxos(ctx, utxomap, bip32_base,
!amount_sat_eq(change, AMOUNT_SAT(0)));
tx->output[0].amount = funding;
wscript = bitcoin_redeem_2of2(tx, local_fundingkey, remote_fundingkey);
SUPERVERBOSE("# funding witness script = %s\n",
tal_hex(wscript, wscript));
tx->output[0].script = scriptpubkey_p2wsh(tx, wscript);
bitcoin_tx_add_output(tx, scriptpubkey_p2wsh(tx, wscript), &funding);
tal_free(wscript);
if (!amount_sat_eq(change, AMOUNT_SAT(0))) {
const void *map[2];
map[0] = int2ptr(0);
map[1] = int2ptr(1);
tx->output[1].script = scriptpubkey_p2wpkh(tx, changekey);
tx->output[1].amount = change;
bitcoin_tx_add_output(tx, scriptpubkey_p2wpkh(tx, changekey),
&change);
permute_outputs(tx, NULL, map);
*outnum = (map[0] == int2ptr(0) ? 0 : 1);
} else {

View File

@ -52,20 +52,22 @@ struct bitcoin_tx *tx_spending_utxos(const tal_t *ctx,
const struct ext_key *bip32_base,
bool add_change_output)
{
struct bitcoin_tx *tx =
bitcoin_tx(ctx, tal_count(utxos), add_change_output ? 2 : 1);
struct pubkey key;
u8 *script;
size_t outcount = add_change_output ? 2 : 1;
struct bitcoin_tx *tx = bitcoin_tx(ctx, tal_count(utxos), outcount);
for (size_t i = 0; i < tal_count(utxos); i++) {
tx->input[i].txid = utxos[i]->txid;
tx->input[i].index = utxos[i]->outnum;
tx->input[i].amount = tal_dup(tx, struct amount_sat,
&utxos[i]->amount);
if (utxos[i]->is_p2sh && bip32_base) {
struct pubkey key;
bip32_pubkey(bip32_base, &key, utxos[i]->keyindex);
tx->input[i].script =
bitcoin_scriptsig_p2sh_p2wpkh(tx, &key);
script = bitcoin_scriptsig_p2sh_p2wpkh(tx, &key);
} else {
script = NULL;
}
bitcoin_tx_add_input(tx, &utxos[i]->txid, utxos[i]->outnum,
BITCOIN_TX_DEFAULT_SEQUENCE,
&utxos[i]->amount, script);
}
return tx;