This is inspired by a patch from @whitslack, which overlapped with this series. Most importantly, there was only one call to bitcoin_tx_simple_input_weight(), and it is better to be explicit with that one. This also changes our funder calculation to assume our own input is taproot, which it is likely to be given we've defaulted to taproot for outputs for change addresses since 23.08. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
53 lines
1.2 KiB
C
53 lines
1.2 KiB
C
#include "config.h"
|
|
#include <common/utxo.h>
|
|
#include <wire/wire.h>
|
|
|
|
size_t utxo_spend_weight(const struct utxo *utxo, size_t min_witness_weight)
|
|
{
|
|
size_t witness_weight;
|
|
bool p2sh = (utxo->utxotype == UTXO_P2SH_P2WPKH);
|
|
|
|
witness_weight = bitcoin_tx_input_witness_weight(utxo->utxotype);
|
|
|
|
/* If the min is less than what we'd use for a 'normal' tx,
|
|
* we return the value with the greater added/calculated */
|
|
if (witness_weight < min_witness_weight)
|
|
return bitcoin_tx_input_weight(p2sh,
|
|
min_witness_weight);
|
|
|
|
return bitcoin_tx_input_weight(p2sh, witness_weight);
|
|
}
|
|
|
|
u32 utxo_is_immature(const struct utxo *utxo, u32 blockheight)
|
|
{
|
|
if (utxo->is_in_coinbase) {
|
|
/* We got this from a block, it must have a known
|
|
* blockheight. */
|
|
assert(utxo->blockheight);
|
|
|
|
if (blockheight < *utxo->blockheight + 100)
|
|
return *utxo->blockheight + 99 - blockheight;
|
|
|
|
else
|
|
return 0;
|
|
} else {
|
|
/* Non-coinbase outputs are always mature. */
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
const char *utxotype_to_str(enum utxotype utxotype)
|
|
{
|
|
switch (utxotype) {
|
|
case UTXO_P2SH_P2WPKH:
|
|
return "p2sh_p2wpkh";
|
|
case UTXO_P2WPKH:
|
|
return "p2wpkh";
|
|
case UTXO_P2WSH_FROM_CLOSE:
|
|
return "p2wsh_from_close";
|
|
case UTXO_P2TR:
|
|
return "p2tr";
|
|
}
|
|
abort();
|
|
}
|