From 9799884ade01042e59944724d162fb6eef247762 Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Sun, 5 Jan 2025 13:07:57 +1300 Subject: [PATCH] wally: use common process cleanup wrappers for wally structs Add a wally_map cleanup wrapper since it will be needed for taproot. --- main/process/sign_liquid_tx.c | 5 ++--- main/process/sign_tx.c | 5 ++--- main/utils/wally_ext.c | 6 ++++++ main/utils/wally_ext.h | 3 +++ 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/main/process/sign_liquid_tx.c b/main/process/sign_liquid_tx.c index 24fa465b..fd2520c7 100644 --- a/main/process/sign_liquid_tx.c +++ b/main/process/sign_liquid_tx.c @@ -12,6 +12,7 @@ #include "../utils/network.h" #include "../utils/temporary_stack.h" #include "../utils/util.h" +#include "../utils/wally_ext.h" #include "../wallet.h" #include @@ -35,8 +36,6 @@ bool validate_wallet_outputs(jade_process_t* process, const char* network, const void send_ae_signature_replies(jade_process_t* process, signing_data_t* all_signing_data, uint32_t num_inputs); void send_ec_signature_replies(jade_msg_source_t source, signing_data_t* all_signing_data, uint32_t num_inputs); -static void wally_free_tx_wrapper(void* tx) { JADE_WALLY_VERIFY(wally_tx_free((struct wally_tx*)tx)); } - static const char TX_TYPE_STR_SWAP[] = "swap"; static const char TX_TYPE_STR_SEND_PAYMENT[] = "send_payment"; typedef enum { TXTYPE_UNKNOWN, TXTYPE_SEND_PAYMENT, TXTYPE_SWAP } TxType_t; @@ -559,7 +558,7 @@ void sign_liquid_tx_process(void* process_ptr) jade_process_reject_message(process, CBOR_RPC_BAD_PARAMETERS, "Failed to extract tx from passed bytes", NULL); goto cleanup; } - jade_process_call_on_exit(process, wally_free_tx_wrapper, tx); + jade_process_call_on_exit(process, jade_wally_free_tx_wrapper, tx); // copy the amount size_t num_inputs = 0; diff --git a/main/process/sign_tx.c b/main/process/sign_tx.c index 1abae736..25be81d1 100644 --- a/main/process/sign_tx.c +++ b/main/process/sign_tx.c @@ -11,6 +11,7 @@ #include "../utils/event.h" #include "../utils/malloc_ext.h" #include "../utils/network.h" +#include "../utils/wally_ext.h" #include "../wallet.h" #include @@ -25,8 +26,6 @@ bool show_btc_transaction_outputs_activity( const char* network, const struct wally_tx* tx, const output_info_t* output_info); bool show_btc_final_confirmation_activity(uint64_t fee, const char* warning_msg); -static void wally_free_tx_wrapper(void* tx) { JADE_WALLY_VERIFY(wally_tx_free((struct wally_tx*)tx)); } - // Can optionally be passed paths for change outputs, which we verify internally bool validate_wallet_outputs(jade_process_t* process, const char* network, const struct wally_tx* tx, CborValue* wallet_outputs, output_info_t* output_info, const char** errmsg) @@ -413,7 +412,7 @@ void sign_tx_process(void* process_ptr) jade_process_reject_message(process, CBOR_RPC_BAD_PARAMETERS, "Failed to extract tx from passed bytes", NULL); goto cleanup; } - jade_process_call_on_exit(process, wally_free_tx_wrapper, tx); + jade_process_call_on_exit(process, jade_wally_free_tx_wrapper, tx); // copy the amount size_t num_inputs = 0; diff --git a/main/utils/wally_ext.c b/main/utils/wally_ext.c index 711a62fa..cceb93b8 100644 --- a/main/utils/wally_ext.c +++ b/main/utils/wally_ext.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include /* index == 0 is reserved for idf internal use, * see https://docs.espressif.com/projects/esp-idf/en/v4.3.2/esp32/api-guides/thread-local-storage.html @@ -138,3 +140,7 @@ void jade_wally_init(void) set_jade_wally_ctx(&ctx, wally_get_secp_context()); JADE_WALLY_VERIFY(wally_set_operations(&ops)); } + +void jade_wally_free_tx_wrapper(void* tx) { JADE_WALLY_VERIFY(wally_tx_free((struct wally_tx*)tx)); } + +void jade_wally_free_map_wrapper(void* map) { JADE_WALLY_VERIFY(wally_map_free((struct wally_map*)map)); } diff --git a/main/utils/wally_ext.h b/main/utils/wally_ext.h index db906546..208419e9 100644 --- a/main/utils/wally_ext.h +++ b/main/utils/wally_ext.h @@ -4,4 +4,7 @@ void jade_wally_init(void); void jade_wally_randomize_secp_ctx(void); +void jade_wally_free_tx_wrapper(void* tx); +void jade_wally_free_map_wrapper(void* map); + #endif /* UTILS_WALLY_EXT_H_ */