tx: make bitcoin_tx_output_get_amount_sat() return amount_sat.
What changed, and why it matters
This commit is a small internal code cleanup: it changes a helper function so it returns a value directly instead of writing it through a pointer. There is no security-relevant change visible in the diff.
No security action required; this is a routine refactoring change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors bitcoin_tx_output_get_amount_sat() from an out-parameter style (void, writing to struct amount_sat *amount) to a return-value style (struct amount_sat). Call sites in chaintopology.c and dualopend.c are updated to assign the return value. The function body is otherwise unchanged: it still calls bitcoin_tx_output_get_amount(), asserts the asset is main, and converts to amount_sat. No logic, validation, or behavior changes are introduced.
Changed components
bitcoin/tx.cbitcoin/tx.hlightningd/chaintopology.copeningd/dualopend.cInspect captured patch +6 / −8
diff --git a/bitcoin/tx.c b/bitcoin/tx.c
index 4c1a63de..0d5d6e56 100644
--- a/bitcoin/tx.c
+++ b/bitcoin/tx.c
@@ -326,13 +326,12 @@ struct amount_asset bitcoin_tx_output_get_amount(const struct bitcoin_tx *tx,
return wally_tx_output_get_amount(&tx->wtx->outputs[outnum]);
}
-void bitcoin_tx_output_get_amount_sat(const struct bitcoin_tx *tx, int outnum,
- struct amount_sat *amount)
+struct amount_sat bitcoin_tx_output_get_amount_sat(const struct bitcoin_tx *tx, int outnum)
{
struct amount_asset asset_amt;
asset_amt = bitcoin_tx_output_get_amount(tx, outnum);
assert(amount_asset_is_main(&asset_amt));
- *amount = amount_asset_to_sat(&asset_amt);
+ return amount_asset_to_sat(&asset_amt);
}
void bitcoin_tx_input_set_witness(struct bitcoin_tx *tx, int innum,
diff --git a/bitcoin/tx.h b/bitcoin/tx.h
index 4b7134e0..1e28130d 100644
--- a/bitcoin/tx.h
+++ b/bitcoin/tx.h
@@ -176,8 +176,8 @@ u8 *bitcoin_tx_output_get_witscript(const tal_t *ctx, const struct bitcoin_tx *t
* Internally we use a `wally_tx` to represent the transaction. The
* satoshi amount isn't a struct amount_sat, so we need a conversion
*/
-void bitcoin_tx_output_get_amount_sat(const struct bitcoin_tx *tx, int outnum,
- struct amount_sat *amount);
+struct amount_sat bitcoin_tx_output_get_amount_sat(const struct bitcoin_tx *tx, int outnum);
+
/**
* Helper to just get an amount_sat for the output amount.
*/
diff --git a/lightningd/chaintopology.c b/lightningd/chaintopology.c
index 25544f90..0b2caec7 100644
--- a/lightningd/chaintopology.c
+++ b/lightningd/chaintopology.c
@@ -83,7 +83,7 @@ static void filter_block_txs(struct chain_topology *topo, struct block *b)
struct bitcoin_outpoint outpoint;
outpoint.txid = txid;
outpoint.n = k;
- bitcoin_tx_output_get_amount_sat(tx, k, &amount);
+ amount = bitcoin_tx_output_get_amount_sat(tx, k);
invoice_check_onchain_payment(topo->ld, txout->script, amount, &outpoint);
}
}
diff --git a/openingd/dualopend.c b/openingd/dualopend.c
index 8c4cdbb4..733b0c28 100644
--- a/openingd/dualopend.c
+++ b/openingd/dualopend.c
@@ -1871,8 +1871,7 @@ static bool run_tx_interactive(struct state *state,
if (is_elements(chainparams)) {
struct amount_asset asset;
- bitcoin_tx_output_get_amount_sat(tx, outpoint.n,
- &amt);
+ amt = bitcoin_tx_output_get_amount_sat(tx, outpoint.n);
/* FIXME: persist asset tags */
asset = amount_sat_to_asset(&amt,
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.