Skip to content

Commit b6c4b32

Browse files
jgriffithsJamie C. Driver
authored andcommitted
network: remove final references to network names
As of this commit, each process gets a 'network_id' variable which is always set to a valid network id, and no network strings are used.
1 parent 6e7a2c7 commit b6c4b32

File tree

5 files changed

+39
-32
lines changed

5 files changed

+39
-32
lines changed

main/process/process_utils.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,13 @@ typedef struct {
7676
bool jade_process_check_network(jade_process_t* process, CborValue* params, uint32_t* network_id);
7777

7878
// Ensure the rpc "network" parameter is valid and consistent with prior use.
79-
// Declares 'network_id'/'network' variables and initializes them.
79+
// Declares 'network_id' variable and initializes it.
8080
// Assumes GET_MSG_PARAMS() was used previously in the same scope.
81-
// TODO: Remove 'network' and pass around 'network_id' instead.
8281
#define CHECK_NETWORK_CONSISTENT(process) \
8382
uint32_t network_id; \
8483
if (!jade_process_check_network(process, &params, &network_id)) { \
8584
goto cleanup; \
86-
} \
87-
const char* const network = networkIdToNetwork(network_id); \
88-
(void)network;
85+
}
8986

9087
// Do we have have a keychain, and does its userdata indicate the same 'source'
9188
// as the current message ?

main/qrmode.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "utils/network.h"
2323
#include "wallet.h"
2424

25+
#include <wally_address.h>
2526
#include <wally_script.h>
2627

2728
#include <string.h>
@@ -1591,8 +1592,13 @@ static bool post_auth_msg_request(const jade_msg_source_t source, const bool sup
15911592
cberr = cbor_encoder_create_map(&root_map_encoder, &params_encoder, 2);
15921593
JADE_ASSERT(cberr == CborNoError);
15931594
const network_type_t restriction = keychain_get_network_type_restriction();
1594-
const char* network = restriction == NETWORK_TYPE_TEST ? TAG_TESTNET : TAG_MAINNET;
1595-
add_string_to_map(&params_encoder, "network", network);
1595+
uint32_t network_id;
1596+
if (restriction == NETWORK_TYPE_TEST) {
1597+
network_id = WALLY_NETWORK_BITCOIN_TESTNET;
1598+
} else {
1599+
network_id = WALLY_NETWORK_BITCOIN_MAINNET;
1600+
}
1601+
add_string_to_map(&params_encoder, "network", networkIdToNetwork(network_id));
15961602
add_boolean_to_map(&params_encoder, "suppress_pin_change_confirmation", suppress_pin_change_confirmation);
15971603
cberr = cbor_encoder_close_container(&root_map_encoder, &params_encoder);
15981604
JADE_ASSERT(cberr == CborNoError);

main/utils/address.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <wally_script.h>
99

1010
#include <stdio.h>
11+
#include <string.h>
1112

1213
static const char BITCOIN_ADDRESS_URI_SCHEME[] = "bitcoin";
1314

main/utils/network.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,21 @@
22
#include "network.h"
33
#include "jade_assert.h"
44

5+
#include <string.h>
6+
57
#include <wally_address.h>
68
#include <wally_bip32.h>
79

10+
// Main networks
11+
#define TAG_MAINNET "mainnet"
12+
#define TAG_LIQUID "liquid"
13+
14+
// Test networks
15+
#define TAG_TESTNET "testnet"
16+
#define TAG_TESTNETLIQUID "testnet-liquid"
17+
#define TAG_LOCALTEST "localtest"
18+
#define TAG_LOCALTESTLIQUID "localtest-liquid"
19+
820
// Green CSV buckets allowed
921
static const size_t ALLOWED_CSV_MAINNET[] = { 25920, 51840, 65535 };
1022
static const size_t ALLOWED_CSV_TESTNET[] = { 144, 4320, 51840 };

main/utils/network.h

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,35 @@
22
#define UTILS_NETWORK_H_
33

44
#include <stdbool.h>
5+
#include <stddef.h>
56
#include <stdint.h>
6-
#include <string.h>
77

88
#include <network_type.h>
99

10+
// Maximum length of a network name
1011
#define MAX_NETWORK_NAME_LEN 20
1112

12-
// Main networks
13-
#define TAG_MAINNET "mainnet"
14-
#define TAG_LIQUID "liquid"
13+
bool isLiquidNetworkId(uint32_t network_id);
1514

16-
// Test networks
17-
#define TAG_TESTNET "testnet"
18-
#define TAG_TESTNETLIQUID "testnet-liquid"
19-
#define TAG_LOCALTEST "localtest"
20-
#define TAG_LOCALTESTLIQUID "localtest-liquid"
15+
bool csvBlocksExpectedForNetwork(uint32_t network_id, uint32_t csvBlocks);
16+
size_t networkToMinAllowedCsvBlocks(uint32_t network_id);
2117

22-
bool isLiquidNetworkId(const uint32_t network_id);
23-
24-
bool csvBlocksExpectedForNetwork(const uint32_t network_id, uint32_t csvBlocks);
25-
size_t networkToMinAllowedCsvBlocks(const uint32_t network_id);
26-
27-
// TAG_ string to WALLY_NETWORK_ constant, or WALLY_NETWORK_NONE if unknown
18+
// Network name to WALLY_NETWORK_ constant, or WALLY_NETWORK_NONE if unknown
2819
uint32_t networkToNetworkId(const char* network);
29-
// WALLY_NETWORK_ constant to TAG_ string. Asserts if unknown/WALLY_NETWORK_NONE
30-
const char* networkIdToNetwork(const uint32_t network_id);
20+
// WALLY_NETWORK_ constant to network name. Asserts if unknown/WALLY_NETWORK_NONE
21+
const char* networkIdToNetwork(uint32_t network_id);
3122

32-
network_type_t networkIdToType(const uint32_t network_id);
33-
uint32_t networkToBip32Version(const uint32_t network_id);
23+
network_type_t networkIdToType(uint32_t network_id);
24+
uint32_t networkToBip32Version(uint32_t network_id);
3425

35-
uint8_t networkToP2PKHPrefix(const uint32_t network_id);
36-
uint8_t networkToP2SHPrefix(const uint32_t network_id);
37-
const char* networkToBech32Hrp(const uint32_t network_id);
26+
uint8_t networkToP2PKHPrefix(uint32_t network_id);
27+
uint8_t networkToP2SHPrefix(uint32_t network_id);
28+
const char* networkToBech32Hrp(uint32_t network_id);
3829

3930
// Liquid-specific
40-
uint8_t networkToCAPrefix(const uint32_t network_id);
41-
const char* networkToBlech32Hrp(const uint32_t network_id);
31+
uint8_t networkToCAPrefix(uint32_t network_id);
32+
const char* networkToBlech32Hrp(uint32_t network_id);
4233

43-
const char* networkGetPolicyAsset(const uint32_t network_id);
34+
const char* networkGetPolicyAsset(uint32_t network_id);
4435

4536
#endif /* UTILS_NETWORK_H_ */

0 commit comments

Comments
 (0)