2021-02-01 13:28:50 +10:30
|
|
|
#include "config.h"
|
2017-08-29 01:35:01 +09:30
|
|
|
#include <common/utxo.h>
|
2017-02-21 15:15:29 +10:30
|
|
|
|
2020-11-17 19:45:23 -06:00
|
|
|
size_t utxo_spend_weight(const struct utxo *utxo, size_t min_witness_weight)
|
2020-07-06 14:56:14 +09:30
|
|
|
{
|
2025-05-06 05:24:46 +09:30
|
|
|
size_t witness_weight;
|
2025-05-06 05:28:39 +09:30
|
|
|
bool p2sh = (utxo->utxotype == UTXO_P2SH_P2WPKH);
|
2025-05-06 05:24:46 +09:30
|
|
|
|
2025-05-06 05:28:39 +09:30
|
|
|
witness_weight = bitcoin_tx_input_witness_weight(utxo->utxotype);
|
2025-05-06 05:24:46 +09:30
|
|
|
|
2020-11-17 19:45:23 -06:00
|
|
|
/* If the min is less than what we'd use for a 'normal' tx,
|
|
|
|
|
* we return the value with the greater added/calculated */
|
2025-05-06 05:24:46 +09:30
|
|
|
if (witness_weight < min_witness_weight)
|
|
|
|
|
return bitcoin_tx_input_weight(p2sh,
|
2020-11-17 19:45:23 -06:00
|
|
|
min_witness_weight);
|
|
|
|
|
|
2025-05-06 05:24:46 +09:30
|
|
|
return bitcoin_tx_input_weight(p2sh, witness_weight);
|
2020-07-06 14:56:14 +09:30
|
|
|
}
|
2022-11-08 16:06:55 +01:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-06 05:21:46 +09:30
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|