Skip to content

Commit 5885090

Browse files
jgriffithsJamie C. Driver
authored andcommitted
network: use network_t for network ids, remove network_type.h
Fix warnings about missed switch cases, remove now-uneeded wally includes.
1 parent 6630377 commit 5885090

27 files changed

+140
-133
lines changed

main/assets.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include <assets_snapshot.h>
1010
#include <cbor.h>
11-
#include <wally_address.h>
1211
#include <wally_elements.h>
1312
#include <wally_transaction.h>
1413

@@ -190,7 +189,7 @@ bool assets_get_allocate(const char* field, const CborValue* value, asset_info_t
190189
// Lookup asset-info for the passed asset-id.
191190
// 1. Looks in any explicitly passed asset-info
192191
// 2. Looks in any h/coded asset snapshot data (eg. policy assets)
193-
bool assets_get_info(const uint32_t network_id, const asset_info_t* assets, const size_t num_assets,
192+
bool assets_get_info(const network_t network_id, const asset_info_t* assets, const size_t num_assets,
194193
const char* asset_id, asset_info_t* asset_info_out)
195194
{
196195
JADE_ASSERT(network_is_liquid(network_id));

main/assets.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define JADE_ASSETS_H_
33

44
#include "utils/cbor_rpc.h"
5+
#include "utils/network.h"
56

67
// NOTE: strings here may not be nul-terminated as may directly reference message fields
78
typedef struct {
@@ -16,7 +17,7 @@ typedef struct {
1617

1718
bool assets_get_allocate(const char* field, const CborValue* value, asset_info_t** data, size_t* written);
1819

19-
bool assets_get_info(uint32_t network_id, const asset_info_t* assets, size_t num_assets, const char* asset_id,
20+
bool assets_get_info(network_t network_id, const asset_info_t* assets, size_t num_assets, const char* asset_id,
2021
asset_info_t* asset_info_out);
2122

2223
#endif /* JADE_ASSETS_H_ */

main/bcur.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#include "bcur.h"
33
#include "jade_assert.h"
44
#include "keychain.h"
5-
#include "network_type.h"
65
#include "qrcode.h"
76
#include "qrscan.h"
87
#include "ui.h"
98
#include "utils/malloc_ext.h"
9+
#include "utils/network.h"
1010
#include "utils/util.h"
1111

1212
#include <cbor.h>

main/descriptor.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "utils/temporary_stack.h"
99
#include "wallet.h"
1010

11-
#include <wally_address.h>
1211
#include <wally_descriptor.h>
1312
#include <wally_script.h>
1413

@@ -167,7 +166,7 @@ static void string_values_to_map(const string_value_t* datavalues, const size_t
167166
}
168167
}
169168

170-
static bool parse_descriptor(const char* name, const descriptor_data_t* descriptor, const uint32_t network_id,
169+
static bool parse_descriptor(const char* name, const descriptor_data_t* descriptor, const network_t network_id,
171170
descriptor_type_t* deduced_type, struct wally_descriptor** output, uint32_t* depth, const char** errmsg)
172171
{
173172
JADE_ASSERT(name);
@@ -276,7 +275,7 @@ static bool parse_descriptor(const char* name, const descriptor_data_t* descript
276275

277276
// NOTE: signers should either be sufficient to hold details for all signers, or NULL if
278277
// the only value of interest is the number of signers in the descriptor.
279-
bool descriptor_get_signers(const char* name, const descriptor_data_t* descriptor, const uint32_t network_id,
278+
bool descriptor_get_signers(const char* name, const descriptor_data_t* descriptor, const network_t network_id,
280279
descriptor_type_t* deduced_type, signer_t* signers, const size_t signers_len, size_t* written, const char** errmsg)
281280
{
282281
JADE_ASSERT(name);
@@ -389,7 +388,7 @@ bool descriptor_get_signers(const char* name, const descriptor_data_t* descripto
389388
}
390389

391390
// On success output must be freed with wally_free_string()
392-
bool descriptor_to_address(const char* name, const descriptor_data_t* descriptor, const uint32_t network_id,
391+
bool descriptor_to_address(const char* name, const descriptor_data_t* descriptor, const network_t network_id,
393392
const uint32_t multi_index, const uint32_t child_num, descriptor_type_t* deduced_type, char** output,
394393
const char** errmsg)
395394
{
@@ -430,7 +429,7 @@ bool descriptor_to_address(const char* name, const descriptor_data_t* descriptor
430429
// On success output must be freed
431430
// NOTE: For miniscript expressions, the script generated is untyped bitcoin script.
432431
// For descriptors, a scriptPubKey is generated.
433-
bool descriptor_to_script(const char* name, const descriptor_data_t* descriptor, const uint32_t network_id,
432+
bool descriptor_to_script(const char* name, const descriptor_data_t* descriptor, const network_t network_id,
434433
const uint32_t multi_index, const uint32_t child_num, descriptor_type_t* deduced_type, uint8_t** output,
435434
size_t* output_len, const char** errmsg)
436435
{
@@ -470,7 +469,7 @@ bool descriptor_to_script(const char* name, const descriptor_data_t* descriptor,
470469
return true;
471470
}
472471

473-
bool descriptor_search_for_script(const char* name, const descriptor_data_t* descriptor, const uint32_t network_id,
472+
bool descriptor_search_for_script(const char* name, const descriptor_data_t* descriptor, const network_t network_id,
474473
const uint32_t multi_index, uint32_t* child_num, const size_t search_depth, const uint8_t* script,
475474
const size_t script_len)
476475
{

main/descriptor.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define DESCRIPTOR_H_
33

44
#include "signer.h"
5+
#include "utils/network.h"
56

67
struct wally_map;
78

@@ -49,24 +50,24 @@ typedef struct _descriptor_data {
4950
size_t string_values_len(const string_value_t* datavalues, size_t num_values);
5051

5152
// Parse the descriptor and get signer information
52-
bool descriptor_get_signers(const char* name, const descriptor_data_t* descriptor, const uint32_t network_id,
53+
bool descriptor_get_signers(const char* name, const descriptor_data_t* descriptor, const network_t network_id,
5354
descriptor_type_t* type, signer_t* signers, size_t signers_len, size_t* written, const char** errmsg);
5455

5556
// Generate an address using a descriptor/miniscript expression
5657
// On success output must be freed with wally_free_string()
57-
bool descriptor_to_address(const char* name, const descriptor_data_t* descriptor, const uint32_t network_id,
58+
bool descriptor_to_address(const char* name, const descriptor_data_t* descriptor, const network_t network_id,
5859
uint32_t multi_index, uint32_t child_num, descriptor_type_t* type, char** output, const char** errmsg);
5960

6061
// Generate a script using a descriptor/miniscript expression
6162
// On success output must be freed
6263
// NOTE: For miniscript expressions, the script generated is untyped bitcoin script.
6364
// For descriptors, a scriptPubKey is generated.
64-
bool descriptor_to_script(const char* name, const descriptor_data_t* descriptor, const uint32_t network_id,
65+
bool descriptor_to_script(const char* name, const descriptor_data_t* descriptor, const network_t network_id,
6566
uint32_t multi_index, uint32_t child_num, descriptor_type_t* type, uint8_t** output, size_t* output_len,
6667
const char** errmsg);
6768

6869
// Iterate over a number of leaf child indexes testing the generated script for a match against the passed script
69-
bool descriptor_search_for_script(const char* name, const descriptor_data_t* descriptor, const uint32_t network_id,
70+
bool descriptor_search_for_script(const char* name, const descriptor_data_t* descriptor, const network_t network_id,
7071
uint32_t multi_index, uint32_t* child_num, size_t search_depth, const uint8_t* script, size_t script_len);
7172

7273
// Storage related functions

main/keychain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ bool keychain_is_network_type_consistent(const network_type_t network_type)
239239
return network_type_restriction == NETWORK_TYPE_NONE || network_type == network_type_restriction;
240240
}
241241

242-
bool keychain_is_network_id_consistent(const uint32_t network_id)
242+
bool keychain_is_network_id_consistent(const network_t network_id)
243243
{
244244
const network_type_t network_type = network_to_type(network_id);
245245
return keychain_is_network_type_consistent(network_type);

main/keychain.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef KEYCHAIN_H_
22
#define KEYCHAIN_H_
33

4-
#include <network_type.h>
4+
#include "utils/network.h"
55

66
#include <stdbool.h>
77
#include <wally_bip32.h>
@@ -53,7 +53,7 @@ void keychain_cache_mnemonic_entropy(const char* mnemonic);
5353
void keychain_clear_network_type_restriction(void);
5454
void keychain_set_network_type_restriction(const network_type_t network_type);
5555
network_type_t keychain_get_network_type_restriction(void);
56-
bool keychain_is_network_id_consistent(const uint32_t network_id);
56+
bool keychain_is_network_id_consistent(const network_t network_id);
5757
bool keychain_is_network_type_consistent(const network_type_t network_type);
5858

5959
// mnemonic returned should be freed by caller with wally_free_string

main/network_type.h

Lines changed: 0 additions & 6 deletions
This file was deleted.

main/process/dashboard.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ static inline bool awaiting_attestation_data(void) { return false; }
5151
#include <sodium/utils.h>
5252
#include <time.h>
5353

54-
#include <wally_address.h>
55-
5654
// Whether during initialisation we select USB, BLE QR etc.
5755
static jade_msg_source_t initialisation_source = SOURCE_NONE;
5856
static jade_msg_source_t internal_relogin_source = SOURCE_NONE;

main/process/process_utils.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212
#include "process_utils.h"
1313

1414
#include <sys/time.h>
15-
#include <wally_address.h>
1615
#include <wally_anti_exfil.h>
1716
#include <wally_script.h>
1817

1918
#include "process_utils.h"
2019

2120
static const char KEY_TYPE_RSA[] = { 'R', 'S', 'A' };
2221

23-
bool jade_process_check_network(jade_process_t* process, CborValue* params, uint32_t* network_id)
22+
bool jade_process_check_network(jade_process_t* process, CborValue* params, network_t* network_id)
2423
{
2524
JADE_ASSERT(process);
2625
JADE_ASSERT(params);

0 commit comments

Comments
 (0)