Browse Source

wally: Migrate the funding transaction to use the shims

Signed-off-by: Christian Decker <decker.christian@gmail.com>
pr-2587
Christian Decker 6 years ago
committed by Rusty Russell
parent
commit
98983006d6
  1. 7
      common/funding_tx.c
  2. 20
      common/utxo.c

7
common/funding_tx.c

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

20
common/utxo.c

@ -52,20 +52,22 @@ struct bitcoin_tx *tx_spending_utxos(const tal_t *ctx,
const struct ext_key *bip32_base, const struct ext_key *bip32_base,
bool add_change_output) bool add_change_output)
{ {
struct bitcoin_tx *tx = struct pubkey key;
bitcoin_tx(ctx, tal_count(utxos), add_change_output ? 2 : 1); 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++) { 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) { if (utxos[i]->is_p2sh && bip32_base) {
struct pubkey key;
bip32_pubkey(bip32_base, &key, utxos[i]->keyindex); bip32_pubkey(bip32_base, &key, utxos[i]->keyindex);
tx->input[i].script = script = bitcoin_scriptsig_p2sh_p2wpkh(tx, &key);
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; return tx;

Loading…
Cancel
Save