mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-01 17:47:30 +01:00
psbt: implement psbt_txid.
You can't just take the txid of the global tx, if some are p2sh-wrapped. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
09f065fc45
commit
a6a8a40594
4 changed files with 47 additions and 0 deletions
|
@ -463,3 +463,34 @@ struct wally_psbt *fromwire_wally_psbt(const tal_t *ctx,
|
|||
return psbt;
|
||||
}
|
||||
|
||||
/* This only works on a non-final psbt because we're ALL SEGWIT! */
|
||||
void psbt_txid(const struct wally_psbt *psbt, struct bitcoin_txid *txid,
|
||||
struct wally_tx **wtx)
|
||||
{
|
||||
struct wally_tx *tx;
|
||||
|
||||
/* You can *almost* take txid of global tx. But @niftynei thought
|
||||
* about this far more than me and pointed out that P2SH
|
||||
* inputs would not be represented, so here we go. */
|
||||
|
||||
wally_tx_clone_alloc(psbt->tx, 0, &tx);
|
||||
|
||||
for (size_t i = 0; i < tx->num_inputs; i++) {
|
||||
u8 *script;
|
||||
if (!psbt->inputs[i].redeem_script)
|
||||
continue;
|
||||
|
||||
/* P2SH requires push of the redeemscript, from libwally src */
|
||||
script = tal_arr(tmpctx, u8, 0);
|
||||
script_push_bytes(&script,
|
||||
psbt->inputs[i].redeem_script,
|
||||
psbt->inputs[i].redeem_script_len);
|
||||
wally_tx_set_input_script(tx, i, script, tal_bytelen(script));
|
||||
}
|
||||
|
||||
wally_txid(tx, txid);
|
||||
if (wtx)
|
||||
*wtx = tx;
|
||||
else
|
||||
wally_tx_free(tx);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ struct wally_tx;
|
|||
struct amount_asset;
|
||||
struct amount_sat;
|
||||
struct bitcoin_signature;
|
||||
struct bitcoin_txid;
|
||||
struct pubkey;
|
||||
|
||||
void psbt_destroy(struct wally_psbt *psbt);
|
||||
|
@ -31,6 +32,15 @@ struct wally_psbt *new_psbt(const tal_t *ctx,
|
|||
*/
|
||||
bool psbt_is_finalized(const struct wally_psbt *psbt);
|
||||
|
||||
/**
|
||||
* psbt_txid - get the txid of the psbt (what it would be after finalization)
|
||||
* @psbt: the psbt.
|
||||
* @txid: the transaction id (output)
|
||||
* @wtx: if non-NULL, returns a copy of the transaction (caller must wally_tx_free).
|
||||
*/
|
||||
void psbt_txid(const struct wally_psbt *psbt, struct bitcoin_txid *txid,
|
||||
struct wally_tx **wtx);
|
||||
|
||||
struct wally_tx *psbt_finalize(struct wally_psbt *psbt, bool finalize_in_place);
|
||||
|
||||
struct wally_psbt_input *psbt_add_input(struct wally_psbt *psbt,
|
||||
|
|
|
@ -78,6 +78,9 @@ void pubkey_to_der(u8 der[PUBKEY_CMPR_LEN] UNNEEDED, const struct pubkey *key UN
|
|||
/* Generated stub for pubkey_to_hash160 */
|
||||
void pubkey_to_hash160(const struct pubkey *pk UNNEEDED, struct ripemd160 *hash UNNEEDED)
|
||||
{ fprintf(stderr, "pubkey_to_hash160 called!\n"); abort(); }
|
||||
/* Generated stub for script_push_bytes */
|
||||
void script_push_bytes(u8 **scriptp UNNEEDED, const void *mem UNNEEDED, size_t len UNNEEDED)
|
||||
{ fprintf(stderr, "script_push_bytes called!\n"); abort(); }
|
||||
/* Generated stub for scriptpubkey_p2wsh */
|
||||
u8 *scriptpubkey_p2wsh(const tal_t *ctx UNNEEDED, const u8 *witnessscript UNNEEDED)
|
||||
{ fprintf(stderr, "scriptpubkey_p2wsh called!\n"); abort(); }
|
||||
|
|
|
@ -79,6 +79,9 @@ void pubkey_to_der(u8 der[PUBKEY_CMPR_LEN] UNNEEDED, const struct pubkey *key UN
|
|||
/* Generated stub for pubkey_to_hash160 */
|
||||
void pubkey_to_hash160(const struct pubkey *pk UNNEEDED, struct ripemd160 *hash UNNEEDED)
|
||||
{ fprintf(stderr, "pubkey_to_hash160 called!\n"); abort(); }
|
||||
/* Generated stub for script_push_bytes */
|
||||
void script_push_bytes(u8 **scriptp UNNEEDED, const void *mem UNNEEDED, size_t len UNNEEDED)
|
||||
{ fprintf(stderr, "script_push_bytes called!\n"); abort(); }
|
||||
/* Generated stub for scriptpubkey_p2wsh */
|
||||
u8 *scriptpubkey_p2wsh(const tal_t *ctx UNNEEDED, const u8 *witnessscript UNNEEDED)
|
||||
{ fprintf(stderr, "scriptpubkey_p2wsh called!\n"); abort(); }
|
||||
|
|
Loading…
Add table
Reference in a new issue