Skip to content

Commit 4e61fef

Browse files
authored
Merge pull request #4736 from nymtech/jon/nym-vpn-api-env
Add NYM_VPN_API to network config
2 parents 32e2557 + b4514ec commit 4e61fef

File tree

8 files changed

+113
-25
lines changed

8 files changed

+113
-25
lines changed

common/network-defaults/src/lib.rs

+17
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub struct NymNetworkDetails {
4242
pub endpoints: Vec<ValidatorDetails>,
4343
pub contracts: NymContracts,
4444
pub explorer_api: Option<String>,
45+
pub nym_vpn_api_url: Option<String>,
4546
}
4647

4748
// by default we assume the same defaults as mainnet, i.e. same prefixes and denoms
@@ -71,6 +72,7 @@ impl NymNetworkDetails {
7172
endpoints: Default::default(),
7273
contracts: Default::default(),
7374
explorer_api: Default::default(),
75+
nym_vpn_api_url: Default::default(),
7476
}
7577
}
7678

@@ -126,6 +128,7 @@ impl NymNetworkDetails {
126128
.with_multisig_contract(get_optional_env(var_names::MULTISIG_CONTRACT_ADDRESS))
127129
.with_coconut_dkg_contract(get_optional_env(var_names::COCONUT_DKG_CONTRACT_ADDRESS))
128130
.with_explorer_api(get_optional_env(var_names::EXPLORER_API))
131+
.with_nym_vpn_api_url(get_optional_env(var_names::NYM_VPN_API))
129132
}
130133

131134
pub fn new_mainnet() -> Self {
@@ -155,6 +158,7 @@ impl NymNetworkDetails {
155158
),
156159
},
157160
explorer_api: parse_optional_str(mainnet::EXPLORER_API),
161+
nym_vpn_api_url: parse_optional_str(mainnet::NYM_VPN_API),
158162
}
159163
}
160164

@@ -263,6 +267,19 @@ impl NymNetworkDetails {
263267
self.explorer_api = endpoint.map(Into::into);
264268
self
265269
}
270+
271+
#[must_use]
272+
pub fn with_nym_vpn_api_url<S: Into<String>>(mut self, endpoint: Option<S>) -> Self {
273+
self.nym_vpn_api_url = endpoint.map(Into::into);
274+
self
275+
}
276+
277+
pub fn nym_vpn_api_url(&self) -> Option<Url> {
278+
self.nym_vpn_api_url.as_ref().map(|url| {
279+
url.parse()
280+
.expect("the provided nym-vpn api url is invalid!")
281+
})
282+
}
266283
}
267284

268285
#[derive(Debug, Copy, Serialize, Deserialize, Clone, PartialEq, Eq)]

common/network-defaults/src/mainnet.rs

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub const NYXD_URL: &str = "https://rpc.nymtech.net";
3131
pub const NYM_API: &str = "https://validator.nymtech.net/api/";
3232
pub const NYXD_WS: &str = "wss://rpc.nymtech.net/websocket";
3333
pub const EXPLORER_API: &str = "https://explorer.nymtech.net/api/";
34+
pub const NYM_VPN_API: &str = "https://nymvpn.net/api/";
3435

3536
// I'm making clippy mad on purpose, because that url HAS TO be updated and deployed before merging
3637
pub const EXIT_POLICY_URL: &str =
@@ -114,6 +115,7 @@ pub fn export_to_env() {
114115
set_var_to_default(var_names::NYXD_WEBSOCKET, NYXD_WS);
115116
set_var_to_default(var_names::EXPLORER_API, EXPLORER_API);
116117
set_var_to_default(var_names::EXIT_POLICY_URL, EXIT_POLICY_URL);
118+
set_var_to_default(var_names::NYM_VPN_API, NYM_VPN_API);
117119
}
118120

119121
pub fn export_to_env_if_not_set() {
@@ -155,4 +157,5 @@ pub fn export_to_env_if_not_set() {
155157
set_var_conditionally_to_default(var_names::NYXD_WEBSOCKET, NYXD_WS);
156158
set_var_conditionally_to_default(var_names::EXPLORER_API, EXPLORER_API);
157159
set_var_conditionally_to_default(var_names::EXIT_POLICY_URL, EXIT_POLICY_URL);
160+
set_var_conditionally_to_default(var_names::NYM_VPN_API, NYM_VPN_API);
158161
}

common/network-defaults/src/var_names.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub const NYM_API: &str = "NYM_API";
2424
pub const NYXD_WEBSOCKET: &str = "NYXD_WS";
2525
pub const EXPLORER_API: &str = "EXPLORER_API";
2626
pub const EXIT_POLICY_URL: &str = "EXIT_POLICY";
27+
pub const NYM_VPN_API: &str = "NYM_VPN_API";
2728

2829
pub const DKG_TIME_CONFIGURATION: &str = "DKG_TIME_CONFIGURATION";
2930

envs/canary.env

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ COCONUT_DKG_CONTRACT_ADDRESS=n1aakfpghcanxtc45gpqlx8j3rq0zcpyf49qmhm9mdjrfx036h4
2020
EXPLORER_API=https://canary-explorer.performance.nymte.ch/api
2121
NYXD="https://canary-validator.performance.nymte.ch"
2222
NYM_API="https://canary-api.performance.nymte.ch/api"
23+
NYM_VPN_API="https://foo/api"

envs/mainnet.env

+1
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ NYXD="https://rpc.nymtech.net"
2424
NYM_API="https://validator.nymtech.net/api/"
2525
NYXD_WS="wss://rpc.nymtech.net/websocket"
2626
EXPLORER_API="https://explorer.nymtech.net/api/"
27+
NYM_VPN_API="https://nymvpn.com/api"

nym-wallet/Cargo.lock

+88-25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nym-wallet/nym-wallet-types/src/network/qa.rs

+1
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@ pub(crate) fn network_details() -> nym_network_defaults::NymNetworkDetails {
5656
coconut_dkg_contract_address: parse_optional_str(COCONUT_DKG_CONTRACT_ADDRESS),
5757
},
5858
explorer_api: parse_optional_str(EXPLORER_API),
59+
nym_vpn_api_url: None,
5960
}
6061
}

nym-wallet/nym-wallet-types/src/network/sandbox.rs

+1
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@ pub(crate) fn network_details() -> nym_network_defaults::NymNetworkDetails {
5656
coconut_dkg_contract_address: parse_optional_str(COCONUT_DKG_CONTRACT_ADDRESS),
5757
},
5858
explorer_api: parse_optional_str(EXPLORER_API),
59+
nym_vpn_api_url: None,
5960
}
6061
}

0 commit comments

Comments
 (0)