Browse Source

bitcoin_tx: add helper for extracting output amount

nifty/pset-pre
lisa neigut 5 years ago
committed by Rusty Russell
parent
commit
c110f3662c
  1. 10
      bitcoin/tx.c
  2. 7
      bitcoin/tx.h

10
bitcoin/tx.c

@ -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)
{

7
bitcoin/tx.h

@ -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.
*/

Loading…
Cancel
Save