bitcoin_tx: add helper for extracting output amount

This commit is contained in:
lisa neigut 2019-11-14 10:38:17 -06:00 committed by Rusty Russell
parent d8c9e70c0c
commit c110f3662c
2 changed files with 17 additions and 0 deletions

View file

@ -263,6 +263,16 @@ struct amount_asset bitcoin_tx_output_get_amount(const struct bitcoin_tx *tx,
return amount;
}
void bitcoin_tx_output_get_amount_sat(struct bitcoin_tx *tx, int outnum,
struct amount_sat *amount)
{
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);
}
void bitcoin_tx_input_set_witness(struct bitcoin_tx *tx, int innum,
u8 **witness)
{

View file

@ -115,6 +115,13 @@ void bitcoin_tx_output_set_amount(struct bitcoin_tx *tx, int outnum,
*/
const u8 *bitcoin_tx_output_get_script(const tal_t *ctx, const struct bitcoin_tx *tx, int outnum);
/** bitcoin_tx_output_get_amount_sat - Helper to get transaction output's amount
*
* 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(struct bitcoin_tx *tx, int outnum,
struct amount_sat *amount);
/**
* Helper to just get an amount_sat for the output amount.
*/