Skip to content

Commit 9799884

Browse files
committed
wally: use common process cleanup wrappers for wally structs
Add a wally_map cleanup wrapper since it will be needed for taproot.
1 parent 1dbf9e9 commit 9799884

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

main/process/sign_liquid_tx.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "../utils/network.h"
1313
#include "../utils/temporary_stack.h"
1414
#include "../utils/util.h"
15+
#include "../utils/wally_ext.h"
1516
#include "../wallet.h"
1617

1718
#include <sodium/utils.h>
@@ -35,8 +36,6 @@ bool validate_wallet_outputs(jade_process_t* process, const char* network, const
3536
void send_ae_signature_replies(jade_process_t* process, signing_data_t* all_signing_data, uint32_t num_inputs);
3637
void send_ec_signature_replies(jade_msg_source_t source, signing_data_t* all_signing_data, uint32_t num_inputs);
3738

38-
static void wally_free_tx_wrapper(void* tx) { JADE_WALLY_VERIFY(wally_tx_free((struct wally_tx*)tx)); }
39-
4039
static const char TX_TYPE_STR_SWAP[] = "swap";
4140
static const char TX_TYPE_STR_SEND_PAYMENT[] = "send_payment";
4241
typedef enum { TXTYPE_UNKNOWN, TXTYPE_SEND_PAYMENT, TXTYPE_SWAP } TxType_t;
@@ -559,7 +558,7 @@ void sign_liquid_tx_process(void* process_ptr)
559558
jade_process_reject_message(process, CBOR_RPC_BAD_PARAMETERS, "Failed to extract tx from passed bytes", NULL);
560559
goto cleanup;
561560
}
562-
jade_process_call_on_exit(process, wally_free_tx_wrapper, tx);
561+
jade_process_call_on_exit(process, jade_wally_free_tx_wrapper, tx);
563562

564563
// copy the amount
565564
size_t num_inputs = 0;

main/process/sign_tx.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "../utils/event.h"
1212
#include "../utils/malloc_ext.h"
1313
#include "../utils/network.h"
14+
#include "../utils/wally_ext.h"
1415
#include "../wallet.h"
1516

1617
#include <inttypes.h>
@@ -25,8 +26,6 @@ bool show_btc_transaction_outputs_activity(
2526
const char* network, const struct wally_tx* tx, const output_info_t* output_info);
2627
bool show_btc_final_confirmation_activity(uint64_t fee, const char* warning_msg);
2728

28-
static void wally_free_tx_wrapper(void* tx) { JADE_WALLY_VERIFY(wally_tx_free((struct wally_tx*)tx)); }
29-
3029
// Can optionally be passed paths for change outputs, which we verify internally
3130
bool validate_wallet_outputs(jade_process_t* process, const char* network, const struct wally_tx* tx,
3231
CborValue* wallet_outputs, output_info_t* output_info, const char** errmsg)
@@ -413,7 +412,7 @@ void sign_tx_process(void* process_ptr)
413412
jade_process_reject_message(process, CBOR_RPC_BAD_PARAMETERS, "Failed to extract tx from passed bytes", NULL);
414413
goto cleanup;
415414
}
416-
jade_process_call_on_exit(process, wally_free_tx_wrapper, tx);
415+
jade_process_call_on_exit(process, jade_wally_free_tx_wrapper, tx);
417416

418417
// copy the amount
419418
size_t num_inputs = 0;

main/utils/wally_ext.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <freertos/FreeRTOS.h>
88
#include <freertos/task.h>
99
#include <stdint.h>
10+
#include <wally_map.h>
11+
#include <wally_transaction.h>
1012

1113
/* index == 0 is reserved for idf internal use,
1214
* 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)
138140
set_jade_wally_ctx(&ctx, wally_get_secp_context());
139141
JADE_WALLY_VERIFY(wally_set_operations(&ops));
140142
}
143+
144+
void jade_wally_free_tx_wrapper(void* tx) { JADE_WALLY_VERIFY(wally_tx_free((struct wally_tx*)tx)); }
145+
146+
void jade_wally_free_map_wrapper(void* map) { JADE_WALLY_VERIFY(wally_map_free((struct wally_map*)map)); }

main/utils/wally_ext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@
44
void jade_wally_init(void);
55
void jade_wally_randomize_secp_ctx(void);
66

7+
void jade_wally_free_tx_wrapper(void* tx);
8+
void jade_wally_free_map_wrapper(void* map);
9+
710
#endif /* UTILS_WALLY_EXT_H_ */

0 commit comments

Comments
 (0)