mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-22 08:34:20 +01:00
wally: Add accessor methods for script and amount
These are handled internally in the `wally_tx` and do not conform to our usual tallocated strings that can by inspected using `tal_bytelen`, and we don't really want to litter our code with whitelisting comments for the `amount_sat.satoshis` access, so these just do read-only on the fly conversions. Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
committed by
Rusty Russell
parent
64273b5ec5
commit
8d0500228e
29
bitcoin/tx.h
29
bitcoin/tx.h
@@ -95,6 +95,22 @@ int bitcoin_tx_add_input(struct bitcoin_tx *tx, const struct bitcoin_txid *txid,
|
||||
void bitcoin_tx_output_set_amount(struct bitcoin_tx *tx, int outnum,
|
||||
struct amount_sat *amount);
|
||||
|
||||
/**
|
||||
* Helper to get the script of a script's output as a tal_arr
|
||||
*
|
||||
* Internally we use a `wally_tx` to represent the transaction. The script
|
||||
* attached to a `wally_tx_output` is not a `tal_arr`, so in order to keep the
|
||||
* comfort of being able to call `tal_bytelen` and similar on a script we just
|
||||
* return a `tal_arr` clone of the original script.
|
||||
*/
|
||||
const u8 *bitcoin_tx_output_get_script(const tal_t *ctx, const struct bitcoin_tx *tx, int outnum);
|
||||
|
||||
/**
|
||||
* Helper to just get an amount_sat for the output amount.
|
||||
*/
|
||||
struct amount_sat bitcoin_tx_output_get_amount(const struct bitcoin_tx *tx,
|
||||
int outnum);
|
||||
|
||||
/**
|
||||
* Set the input witness.
|
||||
*
|
||||
@@ -109,6 +125,19 @@ void bitcoin_tx_input_set_witness(struct bitcoin_tx *tx, int innum,
|
||||
*/
|
||||
void bitcoin_tx_input_set_script(struct bitcoin_tx *tx, int innum, u8 *script);
|
||||
|
||||
/**
|
||||
* Helper to get a witness as a tal_arr array.
|
||||
*/
|
||||
const u8 *bitcoin_tx_input_get_witness(const tal_t *ctx,
|
||||
const struct bitcoin_tx *tx, int innum,
|
||||
int witnum);
|
||||
|
||||
/**
|
||||
* Wrap the raw txhash in the wally_tx_input into a bitcoin_txid
|
||||
*/
|
||||
void bitcoin_tx_input_get_txid(const struct bitcoin_tx *tx, int innum,
|
||||
struct bitcoin_txid *out);
|
||||
|
||||
/**
|
||||
* Check a transaction for consistency.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user