Skip to content

Commit

Permalink
wally: use common process cleanup wrappers for wally structs
Browse files Browse the repository at this point in the history
Add a wally_map cleanup wrapper since it will be needed for taproot.
  • Loading branch information
jgriffiths committed Jan 6, 2025
1 parent e49eb81 commit c96d7bd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
5 changes: 2 additions & 3 deletions main/process/sign_liquid_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sodium/utils.h>
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions main/process/sign_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <inttypes.h>
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions main/utils/wally_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <stdint.h>
#include <wally_map.h>
#include <wally_transaction.h>

/* 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
Expand Down Expand Up @@ -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)); }
3 changes: 3 additions & 0 deletions main/utils/wally_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */

0 comments on commit c96d7bd

Please sign in to comment.