mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 18:11:28 +01:00
273029f244
This sets the nLockTime to the tip (and accordingly each input's nSequence to 0xfffffffe) for withdrawal transactions. Even if the anti fee-sniping argument might not be valid until some time yet, this makes our regular wallet transactions far less distinguishable from bitcoind's ones since it now defaults to using native Segwit transactions (like us). Moreover other wallets are likely to implement this (if they haven't already). Changelog-Added: wallet: withdrawal transactions now sets nlocktime to the current tip.
57 lines
1.5 KiB
C
57 lines
1.5 KiB
C
#include "funding_tx.h"
|
|
#include <assert.h>
|
|
#include <bitcoin/pubkey.h>
|
|
#include <bitcoin/script.h>
|
|
#include <bitcoin/tx.h>
|
|
#include <ccan/ptrint/ptrint.h>
|
|
#include <common/permute_tx.h>
|
|
#include <common/utxo.h>
|
|
|
|
#ifndef SUPERVERBOSE
|
|
#define SUPERVERBOSE(...)
|
|
#endif
|
|
|
|
struct bitcoin_tx *funding_tx(const tal_t *ctx,
|
|
const struct chainparams *chainparams,
|
|
u16 *outnum,
|
|
const struct utxo **utxomap,
|
|
struct amount_sat funding,
|
|
const struct pubkey *local_fundingkey,
|
|
const struct pubkey *remote_fundingkey,
|
|
struct amount_sat change,
|
|
const struct pubkey *changekey,
|
|
const struct ext_key *bip32_base)
|
|
{
|
|
u8 *wscript;
|
|
struct bitcoin_tx *tx;
|
|
bool has_change = !amount_sat_eq(change, AMOUNT_SAT(0));
|
|
|
|
tx = tx_spending_utxos(ctx, chainparams, utxomap, bip32_base,
|
|
has_change, 1, 0, BITCOIN_TX_DEFAULT_SEQUENCE);
|
|
|
|
|
|
wscript = bitcoin_redeem_2of2(tx, local_fundingkey, remote_fundingkey);
|
|
SUPERVERBOSE("# funding witness script = %s\n",
|
|
tal_hex(wscript, wscript));
|
|
bitcoin_tx_add_output(tx, scriptpubkey_p2wsh(tx, wscript), funding);
|
|
tal_free(wscript);
|
|
|
|
if (has_change) {
|
|
const void *map[2];
|
|
map[0] = int2ptr(0);
|
|
map[1] = int2ptr(1);
|
|
bitcoin_tx_add_output(tx, scriptpubkey_p2wpkh(tx, changekey),
|
|
change);
|
|
permute_outputs(tx, NULL, map);
|
|
*outnum = (map[0] == int2ptr(0) ? 0 : 1);
|
|
} else {
|
|
*outnum = 0;
|
|
}
|
|
|
|
permute_inputs(tx, (const void **)utxomap);
|
|
|
|
elements_tx_add_fee_output(tx);
|
|
assert(bitcoin_tx_check(tx));
|
|
return tx;
|
|
}
|