mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-01 17:47:30 +01:00
bitcoin: add wally_tx_output helper to create standalone output.
In preparation for when we don't have a tx. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
600d0a4a1d
commit
6966cf99e1
2 changed files with 33 additions and 12 deletions
38
bitcoin/tx.c
38
bitcoin/tx.c
|
@ -26,19 +26,12 @@ struct bitcoin_tx_output *new_tx_output(const tal_t *ctx,
|
|||
return output;
|
||||
}
|
||||
|
||||
int bitcoin_tx_add_output(struct bitcoin_tx *tx, const u8 *script,
|
||||
u8 *wscript, struct amount_sat amount)
|
||||
struct wally_tx_output *wally_tx_output(const u8 *script,
|
||||
struct amount_sat amount)
|
||||
{
|
||||
size_t i = tx->wtx->num_outputs;
|
||||
u64 satoshis = amount.satoshis; /* Raw: wally API */
|
||||
struct wally_tx_output *output;
|
||||
struct wally_psbt_output *psbt_out;
|
||||
int ret;
|
||||
u64 satoshis = amount.satoshis; /* Raw: low-level helper */
|
||||
const struct chainparams *chainparams = tx->chainparams;
|
||||
assert(i < tx->wtx->outputs_allocation_len);
|
||||
|
||||
assert(tx->wtx != NULL);
|
||||
assert(chainparams);
|
||||
|
||||
if (chainparams->is_elements) {
|
||||
u8 value[9];
|
||||
|
@ -48,15 +41,36 @@ int bitcoin_tx_add_output(struct bitcoin_tx *tx, const u8 *script,
|
|||
ret = wally_tx_elements_output_init_alloc(
|
||||
script, tal_bytelen(script), chainparams->fee_asset_tag, 33,
|
||||
value, sizeof(value), NULL, 0, NULL, 0, NULL, 0, &output);
|
||||
assert(ret == WALLY_OK);
|
||||
if (ret != WALLY_OK)
|
||||
return NULL;
|
||||
|
||||
/* Cheat a bit by also setting the numeric satoshi value,
|
||||
* otherwise we end up converting a number of times */
|
||||
output->satoshi = satoshis;
|
||||
} else {
|
||||
ret = wally_tx_output_init_alloc(satoshis, script,
|
||||
tal_bytelen(script), &output);
|
||||
assert(ret == WALLY_OK);
|
||||
if (ret != WALLY_OK)
|
||||
return NULL;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
int bitcoin_tx_add_output(struct bitcoin_tx *tx, const u8 *script,
|
||||
u8 *wscript, struct amount_sat amount)
|
||||
{
|
||||
size_t i = tx->wtx->num_outputs;
|
||||
struct wally_tx_output *output;
|
||||
struct wally_psbt_output *psbt_out;
|
||||
int ret;
|
||||
const struct chainparams *chainparams = tx->chainparams;
|
||||
assert(i < tx->wtx->outputs_allocation_len);
|
||||
|
||||
assert(tx->wtx != NULL);
|
||||
assert(chainparams);
|
||||
|
||||
output = wally_tx_output(script, amount);
|
||||
assert(output);
|
||||
ret = wally_tx_add_output(tx->wtx, output);
|
||||
assert(ret == WALLY_OK);
|
||||
|
||||
|
|
|
@ -79,6 +79,13 @@ struct bitcoin_tx *bitcoin_tx_with_psbt(const tal_t *ctx, struct wally_psbt *psb
|
|||
/* Internal de-linearization functions. */
|
||||
struct bitcoin_tx *pull_bitcoin_tx(const tal_t *ctx,
|
||||
const u8 **cursor, size_t *max);
|
||||
|
||||
/* Helper to create a wally_tx_output: make sure to wally_tx_output_free!
|
||||
* Returns NULL if amount is extreme (wally doesn't like).
|
||||
*/
|
||||
struct wally_tx_output *wally_tx_output(const u8 *script,
|
||||
struct amount_sat amount);
|
||||
|
||||
/* Add one output to tx. */
|
||||
int bitcoin_tx_add_output(struct bitcoin_tx *tx, const u8 *script,
|
||||
u8 *wscript,
|
||||
|
|
Loading…
Add table
Reference in a new issue