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:
Christian Decker
2019-03-22 22:45:41 +01:00
committed by Rusty Russell
parent 64273b5ec5
commit 8d0500228e
2 changed files with 73 additions and 0 deletions

View File

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