mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-08 16:44:22 +01:00
wallet: Add utxo_is_immature helper
This commit is contained in:
@@ -73,3 +73,21 @@ size_t utxo_spend_weight(const struct utxo *utxo, size_t min_witness_weight)
|
||||
|
||||
return bitcoin_tx_input_weight(utxo->is_p2sh, wit_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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,4 +83,11 @@ struct utxo *fromwire_utxo(const tal_t *ctx, const u8 **ptr, size_t *max);
|
||||
|
||||
/* Estimate of (signed) UTXO weight in transaction */
|
||||
size_t utxo_spend_weight(const struct utxo *utxo, size_t min_witness_weight);
|
||||
|
||||
/**
|
||||
* Determine how many blocks until a UTXO becomes mature.
|
||||
*
|
||||
* Returns 0 for non-coinbase outputs or the number of blocks to mature.
|
||||
*/
|
||||
u32 utxo_is_immature(const struct utxo *utxo, u32 blockheight);
|
||||
#endif /* LIGHTNING_COMMON_UTXO_H */
|
||||
|
||||
@@ -26,6 +26,7 @@ WALLET_TEST_COMMON_OBJS := \
|
||||
common/setup.o \
|
||||
common/timeout.o \
|
||||
common/utils.o \
|
||||
common/utxo.o \
|
||||
common/wireaddr.o \
|
||||
common/version.o \
|
||||
wallet/db_sqlite3_sqlgen.o \
|
||||
|
||||
@@ -511,15 +511,9 @@ static bool deep_enough(u32 maxheight, const struct utxo *utxo,
|
||||
return false;
|
||||
}
|
||||
|
||||
/* If the utxo is a coinbase, we over-write the maxheight
|
||||
* to the coinbase maxheight (current - 99) */
|
||||
if (utxo->is_in_coinbase) {
|
||||
/* Nothing is spendable the first 100 blocks */
|
||||
if (current_blockheight < 100)
|
||||
return false;
|
||||
if (maxheight > current_blockheight - 99)
|
||||
maxheight = current_blockheight - 99;
|
||||
}
|
||||
bool immature = utxo_is_immature(utxo, current_blockheight);
|
||||
if (immature)
|
||||
return false;
|
||||
|
||||
/* If we require confirmations check that we have a
|
||||
* confirmation height and that it is below the required
|
||||
|
||||
@@ -272,11 +272,11 @@ static void json_add_utxo(struct json_stream *response,
|
||||
if (utxo->spendheight)
|
||||
json_add_string(response, "status", "spent");
|
||||
else if (utxo->blockheight) {
|
||||
if (utxo->is_in_coinbase
|
||||
&& *utxo->blockheight + 99 > current_height) {
|
||||
json_add_string(response, "status", "immature");
|
||||
} else
|
||||
json_add_string(response, "status", "confirmed");
|
||||
json_add_string(response, "status",
|
||||
utxo_is_immature(utxo, current_height)
|
||||
? "immature"
|
||||
: "confirmed");
|
||||
|
||||
json_add_num(response, "blockheight", *utxo->blockheight);
|
||||
} else
|
||||
json_add_string(response, "status", "unconfirmed");
|
||||
|
||||
Reference in New Issue
Block a user