mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
txprepare: return psbt serialized version of tx as well
Changelog-Added: JSON-API: `txprepare` returns a psbt version of the created transaction
This commit is contained in:
parent
bf4cac7fb8
commit
1fb9a078b6
13
bitcoin/tx.c
13
bitcoin/tx.c
@ -492,6 +492,19 @@ void bitcoin_tx_finalize(struct bitcoin_tx *tx)
|
||||
assert(bitcoin_tx_check(tx));
|
||||
}
|
||||
|
||||
char *bitcoin_tx_to_psbt_base64(const tal_t *ctx, struct bitcoin_tx *tx)
|
||||
{
|
||||
char *serialized_psbt, *ret_val;
|
||||
int ret;
|
||||
|
||||
ret = wally_psbt_to_base64(tx->psbt, &serialized_psbt);
|
||||
assert(ret == WALLY_OK);
|
||||
|
||||
ret_val = tal_strdup(ctx, serialized_psbt);
|
||||
wally_free_string(serialized_psbt);
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
struct bitcoin_tx *pull_bitcoin_tx(const tal_t *ctx, const u8 **cursor,
|
||||
size_t *max)
|
||||
{
|
||||
|
@ -195,4 +195,8 @@ void towire_bitcoin_txid(u8 **pptr, const struct bitcoin_txid *txid);
|
||||
void towire_bitcoin_tx(u8 **pptr, const struct bitcoin_tx *tx);
|
||||
void towire_bitcoin_tx_output(u8 **pptr, const struct bitcoin_tx_output *output);
|
||||
|
||||
/*
|
||||
* Get the base64 string encoded PSBT of a bitcoin transaction.
|
||||
*/
|
||||
char *bitcoin_tx_to_psbt_base64(const tal_t *ctx, struct bitcoin_tx *tx);
|
||||
#endif /* LIGHTNING_BITCOIN_TX_H */
|
||||
|
@ -240,6 +240,15 @@ void json_add_tx(struct json_stream *result,
|
||||
json_add_hex_talarr(result, fieldname, linearize_tx(tmpctx, tx));
|
||||
}
|
||||
|
||||
void json_add_psbt(struct json_stream *stream,
|
||||
const char *fieldname,
|
||||
struct bitcoin_tx *tx)
|
||||
{
|
||||
const char *psbt_b64;
|
||||
psbt_b64 = bitcoin_tx_to_psbt_base64(tx, tx);
|
||||
json_add_string(stream, fieldname, take(psbt_b64));
|
||||
}
|
||||
|
||||
void json_add_amount_msat_compat(struct json_stream *result,
|
||||
struct amount_msat msat,
|
||||
const char *rawfieldname,
|
||||
|
@ -137,4 +137,10 @@ void json_add_preimage(struct json_stream *result, const char *fieldname,
|
||||
void json_add_tx(struct json_stream *result,
|
||||
const char *fieldname,
|
||||
const struct bitcoin_tx *tx);
|
||||
|
||||
/* '"fieldname" : "cHNidP8BAJoCAAAAAljo..." or "cHNidP8BAJoCAAAAAljo..." if fieldname is NULL */
|
||||
void json_add_psbt(struct json_stream *stream,
|
||||
const char *fieldname,
|
||||
struct bitcoin_tx *tx);
|
||||
|
||||
#endif /* LIGHTNING_COMMON_JSON_HELPERS_H */
|
||||
|
@ -302,6 +302,7 @@ def test_txprepare(node_factory, bitcoind, chainparams):
|
||||
wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 10)
|
||||
|
||||
prep = l1.rpc.txprepare(outputs=[{addr: Millisatoshi(amount * 3 * 1000)}])
|
||||
assert prep['psbt']
|
||||
decode = bitcoind.rpc.decoderawtransaction(prep['unsigned_tx'])
|
||||
assert decode['txid'] == prep['txid']
|
||||
# 4 inputs, 2 outputs (3 if we have a fee output).
|
||||
|
@ -443,6 +443,7 @@ static struct command_result *json_txprepare(struct command *cmd,
|
||||
response = json_stream_success(cmd);
|
||||
json_add_tx(response, "unsigned_tx", utx->tx);
|
||||
json_add_txid(response, "txid", &utx->txid);
|
||||
json_add_psbt(response, "psbt", utx->tx);
|
||||
return command_success(cmd, response);
|
||||
}
|
||||
static const struct json_command txprepare_command = {
|
||||
|
Loading…
Reference in New Issue
Block a user