mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-10 17:44:22 +01:00
have towire_wally_psbt and fromwire_wally_psbt set safe psbt version
This commit is contained in:
committed by
Rusty Russell
parent
650443e4d5
commit
e30f2cb4a4
@@ -737,12 +737,24 @@ struct wally_psbt *psbt_from_bytes(const tal_t *ctx, const u8 *bytes,
|
||||
|
||||
void towire_wally_psbt(u8 **pptr, const struct wally_psbt *psbt)
|
||||
{
|
||||
struct wally_psbt *psbt_copy;
|
||||
|
||||
/* Let's include the PSBT bytes */
|
||||
size_t bytes_written;
|
||||
const u8 *pbt_bytes = psbt_get_bytes(NULL, psbt, &bytes_written);
|
||||
const u8 *psbt_bytes = psbt_get_bytes(NULL, psbt, &bytes_written);
|
||||
|
||||
/* When sending to other processes, set to v0 for compat */
|
||||
psbt_copy = psbt_from_bytes(NULL, psbt_bytes, bytes_written);
|
||||
tal_free(psbt_bytes);
|
||||
if (!is_elements(chainparams))
|
||||
psbt_set_version(psbt_copy, 0);
|
||||
|
||||
const u8 *psbt_bytes_copy = psbt_get_bytes(NULL, psbt_copy, &bytes_written);
|
||||
|
||||
towire_u32(pptr, bytes_written);
|
||||
towire_u8_array(pptr, pbt_bytes, bytes_written);
|
||||
tal_free(pbt_bytes);
|
||||
towire_u8_array(pptr, psbt_bytes_copy, bytes_written);
|
||||
tal_free(psbt_bytes_copy);
|
||||
tal_free(psbt_copy);
|
||||
}
|
||||
|
||||
struct wally_psbt *fromwire_wally_psbt(const tal_t *ctx,
|
||||
@@ -773,6 +785,9 @@ struct wally_psbt *fromwire_wally_psbt(const tal_t *ctx,
|
||||
tal_free(tmpbuf);
|
||||
#endif
|
||||
|
||||
/* Internally we always operate on v2 */
|
||||
psbt_set_version(psbt, 2);
|
||||
|
||||
return psbt;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user