Compare commits

...

8 Commits

Author SHA1 Message Date
Bogdan-Ștefan Neacșu c2a6eb4d39 Use 1.. indices and fix the blind sign request multiple generation 2022-03-07 12:49:55 +02:00
Jon Häggblad 835a915f25 wallet: initial backend support for config file with validator urls 2022-03-07 10:53:31 +01:00
durch 9c16e5ebfa Remove core-graphics pin 2022-03-04 14:21:32 +01:00
durch 5dc57d2a3e Fix type generation, upgrade ts-rs 2022-03-03 22:17:35 +01:00
Raphaël Walther fd619cad51 Moved clean task at an earlier stage 2022-03-03 18:47:28 +01:00
durch 953c0915d1 Lock tauri-versions, break type generation 2022-03-03 18:10:58 +01:00
Jon Häggblad acb1aa8df0 network-defaults: make defaults a bit more dynamic
By attaching network defaults to the selector enum, we can get them
either from DEFAULT_NETWORK or a selector passed as a dependency.
Hopefully this opens up some venues for being able to toggle between
networks at runtime.
2022-03-03 13:26:53 +01:00
fmtabbara b9ef848523 fix clipboard and screen maximize 2022-03-03 12:18:08 +00:00
70 changed files with 1351 additions and 3694 deletions
+7 -6
View File
@@ -56,6 +56,12 @@ jobs:
command: fmt
args: --all -- --check
- name: Reclaim some disk space (because Windows is being annoying)
uses: actions-rs/cargo@v1
if: ${{ matrix.os == 'windows-latest' }}
with:
command: clean
- uses: actions-rs/clippy-check@v1
name: Clippy checks
with:
@@ -69,13 +75,8 @@ jobs:
command: clippy
args: -- -D warnings
# COCONUT stuff
- name: Reclaim some disk space (because Windows is being annoying)
uses: actions-rs/cargo@v1
if: ${{ matrix.os == 'windows-latest' }}
with:
command: clean
# COCONUT stuff
- name: Build all binaries with coconut enabled
uses: actions-rs/cargo@v1
with:
Generated
+527 -2634
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -17,7 +17,7 @@ members = [
"clients/native",
"clients/native/websocket-requests",
"clients/socks5",
"clients/tauri-client/src-tauri",
# "clients/tauri-client/src-tauri",
"common/client-libs/gateway-client",
"common/client-libs/mixnet-client",
"common/client-libs/validator-client",
+2 -2
View File
@@ -3,7 +3,7 @@ happy: fmt clippy-happy test
clippy-all: clippy-all-main clippy-all-contracts clippy-all-wallet
clippy-happy: clippy-happy-main clippy-happy-contracts clippy-happy-wallet
cargo-test: test-main test-contracts test-wallet
build: build-main build-contracts build-wallet
build: build-contracts build-wallet build-main
fmt: fmt-main fmt-contracts fmt-wallet
clippy-happy-main:
@@ -25,7 +25,7 @@ clippy-all-wallet:
cargo clippy --manifest-path nym-wallet/Cargo.toml --all-features -- -D warnings
test-main:
cargo test --all-features
cargo test --all-features --all
test-contracts:
cargo test --manifest-path contracts/Cargo.toml --all-features
+6 -2
View File
@@ -12,15 +12,19 @@ build = "src/build.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]
tauri-build = { version = "1.0.0-rc.3" }
tauri-build = { version = "=1.0.0-rc.2" }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.0.0-rc.3", features = [] }
tauri = { version = "=1.0.0-rc.2", features = [] }
tokio = "1.4"
url = "2.2"
tauri-codegen = "=1.0.0-rc.1"
tauri-macros = "=1.0.0-rc.1"
core-graphics = "=0.22.2"
coconut-interface = { path = "../../../common/coconut-interface" }
credentials = { path = "../../../common/credentials" }
validator-client = {path = "../../../common/client-libs/validator-client"}
@@ -39,8 +39,9 @@ flate2 = { version = "1.0.20", optional = true }
sha2 = { version = "0.9.5", optional = true }
itertools = { version = "0.10", optional = true }
cosmwasm-std = { version = "1.0.0-beta3", optional = true }
# Leaving it as * so that it inherits whatever the wallet is using
ts-rs = { version = "*", optional = true }
[dev-dependencies]
ts-rs = "6.1.2"
[features]
nymd-client = [
@@ -54,4 +55,3 @@ nymd-client = [
"itertools",
"cosmwasm-std",
]
typescript-types = ["ts-rs", "validator-api-requests/ts-rs"]
@@ -4,6 +4,7 @@
use crate::{validator_api, ValidatorClientError};
use coconut_interface::{BlindSignRequestBody, BlindedSignatureResponse, VerificationKeyResponse};
use mixnet_contract_common::{GatewayBond, IdentityKeyRef, MixNodeBond};
use network_defaults::DEFAULT_NETWORK;
use url::Url;
use validator_api_requests::models::{
CoreNodeStatusResponse, MixnodeStatusResponse, RewardEstimationResponse,
@@ -29,6 +30,7 @@ use std::str::FromStr;
#[cfg(feature = "nymd-client")]
#[must_use]
#[derive(Debug)]
pub struct Config {
network: network_defaults::all::Network,
api_url: Url,
@@ -159,12 +161,10 @@ impl Client<QueryNymdClient> {
let nymd_client = NymdClient::connect(
config.nymd_url.as_str(),
Some(config.mixnet_contract_address.clone().unwrap_or_else(|| {
cosmrs::AccountId::from_str(network_defaults::DEFAULT_MIXNET_CONTRACT_ADDRESS)
.unwrap()
cosmrs::AccountId::from_str(DEFAULT_NETWORK.mixnet_contract_address()).unwrap()
})),
Some(config.vesting_contract_address.clone().unwrap_or_else(|| {
cosmrs::AccountId::from_str(network_defaults::DEFAULT_VESTING_CONTRACT_ADDRESS)
.unwrap()
cosmrs::AccountId::from_str(DEFAULT_NETWORK.vesting_contract_address()).unwrap()
})),
Some(
config
@@ -172,7 +172,7 @@ impl Client<QueryNymdClient> {
.clone()
.unwrap_or_else(|| {
cosmrs::AccountId::from_str(
network_defaults::DEFAULT_BANDWIDTH_CLAIM_CONTRACT_ADDRESS,
DEFAULT_NETWORK.bandwidth_claim_contract_address(),
)
.unwrap()
}),
@@ -72,7 +72,7 @@ impl FromStr for GasPrice {
}
impl GasPrice {
pub fn new_with_default_price(denom: String) -> Result<Self, NymdError> {
pub fn new_with_default_price(denom: &str) -> Result<Self, NymdError> {
format!("{}{}", defaults::GAS_PRICE_AMOUNT, denom).parse()
}
}
@@ -83,8 +83,8 @@ mod tests {
#[test]
fn default_gas_price_is_valid() {
let denom = "unym".parse().unwrap();
let _ = GasPrice::new_with_default_price(denom);
let denom = "unym";
GasPrice::new_with_default_price(denom).unwrap();
}
#[test]
@@ -7,7 +7,11 @@ use cosmrs::Coin;
use serde::{Deserialize, Serialize};
use std::fmt;
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(
test,
ts(export, export_to = "../../../nym-wallet/src/types/rust/operation.ts")
)]
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub enum Operation {
Upload,
@@ -57,16 +57,16 @@ pub struct DirectSecp256k1HdWallet {
}
impl DirectSecp256k1HdWallet {
pub fn builder(prefix: String) -> DirectSecp256k1HdWalletBuilder {
pub fn builder(prefix: &str) -> DirectSecp256k1HdWalletBuilder {
DirectSecp256k1HdWalletBuilder::new(prefix)
}
/// Restores a wallet from the given BIP39 mnemonic using default options.
pub fn from_mnemonic(prefix: String, mnemonic: bip39::Mnemonic) -> Result<Self, NymdError> {
pub fn from_mnemonic(prefix: &str, mnemonic: bip39::Mnemonic) -> Result<Self, NymdError> {
DirectSecp256k1HdWalletBuilder::new(prefix).build(mnemonic)
}
pub fn generate(prefix: String, word_count: usize) -> Result<Self, NymdError> {
pub fn generate(prefix: &str, word_count: usize) -> Result<Self, NymdError> {
let mneomonic = bip39::Mnemonic::generate(word_count)?;
Self::from_mnemonic(prefix, mneomonic)
}
@@ -146,11 +146,11 @@ pub struct DirectSecp256k1HdWalletBuilder {
}
impl DirectSecp256k1HdWalletBuilder {
pub fn new(prefix: String) -> Self {
pub fn new(prefix: &str) -> Self {
DirectSecp256k1HdWalletBuilder {
bip39_password: String::new(),
hd_paths: vec![defaults::COSMOS_DERIVATION_PATH.parse().unwrap()],
prefix,
prefix: prefix.into(),
}
}
@@ -197,11 +197,11 @@ impl DirectSecp256k1HdWalletBuilder {
#[cfg(test)]
mod tests {
use super::*;
use network_defaults::{default_network, BECH32_PREFIX};
use network_defaults::DEFAULT_NETWORK;
#[test]
fn generating_account_addresses() {
let (addr1, addr2, addr3) = match BECH32_PREFIX {
let (addr1, addr2, addr3) = match DEFAULT_NETWORK.bech32_prefix() {
"punk" => (
"punk1jw6mp7d5xqc7w6xm79lha27glmd0vdt32a3fj2",
"punk1h5hgn94nsq4kh99rjj794hr5h5q6yfm22mcqqn",
@@ -222,7 +222,7 @@ mod tests {
];
for (mnemonic, address) in mnemonic_address.into_iter() {
let prefix = default_network().bech32_prefix();
let prefix = DEFAULT_NETWORK.bech32_prefix();
let wallet =
DirectSecp256k1HdWallet::from_mnemonic(prefix, mnemonic.parse().unwrap()).unwrap();
assert_eq!(
@@ -12,8 +12,6 @@ cosmwasm-std = "1.0.0-beta3"
serde = { version = "1.0", features = ["derive"] }
serde_repr = "0.1"
schemars = "0.8"
# Leaving it as * so that it inherits whatever the wallet is using
ts-rs = { version = "*", optional = true }
thiserror = "1.0"
network-defaults = { path = "../../network-defaults" }
fixed = { version = "1.1", features = ["serde"] }
@@ -25,7 +23,7 @@ contracts-common = { path = "../contracts-common" }
[dev-dependencies]
time = { version = "0.3.5", features = ["serde", "macros"] }
ts-rs = "6.1.2"
[features]
default = []
@@ -8,7 +8,11 @@ use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
use std::fmt::Display;
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(
test,
ts(export, export_to = "../../../nym-wallet/src/types/rust/gateway.ts")
)]
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize, JsonSchema)]
pub struct Gateway {
pub host: String,
@@ -18,7 +18,14 @@ fixed::const_fixed_from_int! {
const ONE: U128 = 1;
}
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(
test,
ts(
export,
export_to = "../../../nym-wallet/src/types/rust/rewardedsetnodestatus.ts"
)
)]
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize, JsonSchema)]
pub enum RewardedSetNodeStatus {
Active,
@@ -31,7 +38,11 @@ impl RewardedSetNodeStatus {
}
}
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(
test,
ts(export, export_to = "../../../nym-wallet/src/types/rust/mixnode.ts")
)]
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize, JsonSchema)]
pub struct MixNode {
pub host: String,
@@ -12,4 +12,6 @@ serde = { version = "1.0", features = ["derive"] }
schemars = "0.8"
cw-storage-plus = "0.11.1"
config = { path = "../../config" }
ts-rs = { version = "*", optional = true }
[dev-dependencies]
ts-rs = "6.1.2"
@@ -12,7 +12,11 @@ pub fn one_ucoin() -> Coin {
Coin::new(1, DENOM)
}
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(
test,
ts(export, export_to = "../../../nym-wallet/src/types/rust/period.ts")
)]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone, JsonSchema)]
pub enum Period {
Before,
+22 -16
View File
@@ -3,8 +3,8 @@
use coconut_interface::{
aggregate_signature_shares, aggregate_verification_keys, prepare_blind_sign,
prove_bandwidth_credential, Attribute, BlindSignRequestBody, Credential, Parameters, Signature,
SignatureShare, VerificationKey,
prove_bandwidth_credential, Attribute, BlindSignRequest, BlindSignRequestBody, Credential,
ElGamalKeyPair, Parameters, Signature, SignatureShare, VerificationKey,
};
use url::Url;
@@ -47,13 +47,13 @@ pub async fn obtain_aggregate_verification_key(
let mut client = validator_client::ApiClient::new(validators[0].clone());
let response = client.get_coconut_verification_key().await?;
indices.push(0);
indices.push(1);
shares.push(response.key);
for (id, validator_url) in validators.iter().enumerate().skip(1) {
client.change_validator_api(validator_url.clone());
let response = client.get_coconut_verification_key().await?;
indices.push(id as u64);
indices.push((id + 1) as u64);
shares.push(response.key);
}
@@ -66,17 +66,11 @@ async fn obtain_partial_credential(
private_attributes: &[Attribute],
client: &validator_client::ApiClient,
validator_vk: &VerificationKey,
blind_sign_request: &BlindSignRequest,
elgamal_keypair: &ElGamalKeyPair,
) -> Result<Signature, Error> {
let elgamal_keypair = coconut_interface::elgamal_keygen(params);
let blind_sign_request = prepare_blind_sign(
params,
&elgamal_keypair,
private_attributes,
public_attributes,
)?;
let blind_sign_request_body = BlindSignRequestBody::new(
&blind_sign_request,
blind_sign_request,
elgamal_keypair.public_key(),
public_attributes,
(public_attributes.len() + private_attributes.len()) as u32,
@@ -116,15 +110,25 @@ pub async fn obtain_aggregate_signature(
let validator_partial_vk = client.get_coconut_verification_key().await?;
validators_partial_vks.push(validator_partial_vk.key.clone());
let elgamal_keypair = coconut_interface::elgamal_keygen(params);
let blind_sign_request = prepare_blind_sign(
params,
&elgamal_keypair,
private_attributes,
public_attributes,
)?;
let first = obtain_partial_credential(
params,
public_attributes,
private_attributes,
&client,
&validator_partial_vk.key,
&blind_sign_request,
&elgamal_keypair,
)
.await?;
shares.push(SignatureShare::new(first, 0));
shares.push(SignatureShare::new(first, 1));
for (id, validator_url) in validators.iter().enumerate().skip(1) {
client.change_validator_api(validator_url.clone());
@@ -136,9 +140,11 @@ pub async fn obtain_aggregate_signature(
private_attributes,
&client,
&validator_partial_vk.key,
&blind_sign_request,
&elgamal_keypair,
)
.await?;
let share = SignatureShare::new(signature, id as u64);
let share = SignatureShare::new(signature, (id + 1) as u64);
shares.push(share)
}
@@ -148,7 +154,7 @@ pub async fn obtain_aggregate_signature(
let mut indices: Vec<u64> = Vec::with_capacity(validators_partial_vks.len());
for i in 0..validators_partial_vks.len() {
indices.push(i as u64);
indices.push((i + 1) as u64);
}
let verification_key =
aggregate_verification_keys(&validators_partial_vks, Some(indices.as_ref()))?;
@@ -1,4 +1,4 @@
use config::defaults;
use config::defaults::DEFAULT_NETWORK;
use subtle_encoding::bech32;
#[derive(Debug, Clone, PartialEq)]
@@ -18,12 +18,12 @@ pub fn try_bech32_decode(address: &str) -> Result<String, Bech32Error> {
pub fn validate_bech32_prefix(address: &str) -> Result<(), Bech32Error> {
let prefix = try_bech32_decode(address)?;
if prefix == defaults::BECH32_PREFIX {
if prefix == DEFAULT_NETWORK.bech32_prefix() {
Ok(())
} else {
Err(Bech32Error::WrongPrefix(format!(
"your bech32 address prefix should be {}, not {}",
defaults::BECH32_PREFIX,
DEFAULT_NETWORK.bech32_prefix(),
prefix
)))
}
+1
View File
@@ -9,6 +9,7 @@ edition = "2021"
[dependencies]
cfg-if = "1.0.0"
hex-literal = "0.3.3"
once_cell = "1.7.2"
serde = {version = "1.0", features = ["derive"]}
thiserror = "1.0"
url = "2.2"
+57 -61
View File
@@ -2,9 +2,11 @@
// SPDX-License-Identifier: Apache-2.0
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, fmt, str::FromStr};
use std::{collections::HashMap, fmt, ops::Deref, str::FromStr};
use crate::{mainnet, qa, sandbox, ValidatorDetails};
use crate::{
DefaultNetworkDetails, ValidatorDetails, MAINNET_DEFAULTS, QA_DEFAULTS, SANDBOX_DEFAULTS,
};
use thiserror::Error;
@@ -22,20 +24,40 @@ pub enum Network {
}
impl Network {
pub fn bech32_prefix(&self) -> String {
fn details(&self) -> &DefaultNetworkDetails<'_> {
match self {
Self::QA => String::from(qa::BECH32_PREFIX),
Self::SANDBOX => String::from(sandbox::BECH32_PREFIX),
Self::MAINNET => String::from(mainnet::BECH32_PREFIX),
Self::QA => &QA_DEFAULTS,
Self::SANDBOX => &SANDBOX_DEFAULTS,
Self::MAINNET => &MAINNET_DEFAULTS,
}
}
pub fn denom(&self) -> String {
match self {
Self::QA => String::from(qa::DENOM),
Self::SANDBOX => String::from(sandbox::DENOM),
Self::MAINNET => String::from(mainnet::DENOM),
}
pub fn bech32_prefix(&self) -> &str {
self.details().bech32_prefix
}
pub fn denom(&self) -> &str {
self.details().denom
}
pub fn mixnet_contract_address(&self) -> &str {
self.details().mixnet_contract_address
}
pub fn vesting_contract_address(&self) -> &str {
self.details().vesting_contract_address
}
pub fn bandwidth_claim_contract_address(&self) -> &str {
self.details().bandwidth_claim_contract_address
}
pub fn rewarding_validator_address(&self) -> &str {
self.details().rewarding_validator_address
}
pub fn validators(&self) -> impl Iterator<Item = &ValidatorDetails> {
self.details().validators.iter()
}
}
@@ -64,7 +86,7 @@ impl fmt::Display for Network {
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub struct NetworkDetails {
bech32_prefix: String,
denom: String,
@@ -75,7 +97,21 @@ pub struct NetworkDetails {
validators: Vec<ValidatorDetails>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
impl From<&DefaultNetworkDetails<'_>> for NetworkDetails {
fn from(details: &DefaultNetworkDetails) -> Self {
NetworkDetails {
bech32_prefix: details.bech32_prefix.into(),
denom: details.denom.into(),
mixnet_contract_address: details.mixnet_contract_address.into(),
vesting_contract_address: details.vesting_contract_address.into(),
bandwidth_claim_contract_address: details.bandwidth_claim_contract_address.into(),
rewarding_validator_address: details.rewarding_validator_address.into(),
validators: details.validators.clone(),
}
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
pub struct SupportedNetworks {
networks: HashMap<Network, NetworkDetails>,
}
@@ -86,53 +122,13 @@ impl SupportedNetworks {
for network in support {
match network {
Network::MAINNET => networks.insert(
Network::MAINNET,
NetworkDetails {
bech32_prefix: String::from(mainnet::BECH32_PREFIX),
denom: String::from(mainnet::DENOM),
mixnet_contract_address: String::from(mainnet::MIXNET_CONTRACT_ADDRESS),
vesting_contract_address: String::from(mainnet::VESTING_CONTRACT_ADDRESS),
bandwidth_claim_contract_address: String::from(
mainnet::BANDWIDTH_CLAIM_CONTRACT_ADDRESS,
),
rewarding_validator_address: String::from(
mainnet::REWARDING_VALIDATOR_ADDRESS,
),
validators: mainnet::validators(),
},
),
Network::SANDBOX => networks.insert(
Network::SANDBOX,
NetworkDetails {
bech32_prefix: String::from(sandbox::BECH32_PREFIX),
denom: String::from(sandbox::DENOM),
mixnet_contract_address: String::from(sandbox::MIXNET_CONTRACT_ADDRESS),
vesting_contract_address: String::from(sandbox::VESTING_CONTRACT_ADDRESS),
bandwidth_claim_contract_address: String::from(
sandbox::BANDWIDTH_CLAIM_CONTRACT_ADDRESS,
),
rewarding_validator_address: String::from(
sandbox::REWARDING_VALIDATOR_ADDRESS,
),
validators: sandbox::validators(),
},
),
Network::QA => networks.insert(
Network::QA,
NetworkDetails {
bech32_prefix: String::from(qa::BECH32_PREFIX),
denom: String::from(qa::DENOM),
mixnet_contract_address: String::from(qa::MIXNET_CONTRACT_ADDRESS),
vesting_contract_address: String::from(qa::VESTING_CONTRACT_ADDRESS),
bandwidth_claim_contract_address: String::from(
qa::BANDWIDTH_CLAIM_CONTRACT_ADDRESS,
),
rewarding_validator_address: String::from(qa::REWARDING_VALIDATOR_ADDRESS),
validators: qa::validators(),
},
),
Network::MAINNET => {
networks.insert(Network::MAINNET, MAINNET_DEFAULTS.deref().into())
}
Network::SANDBOX => {
networks.insert(Network::SANDBOX, SANDBOX_DEFAULTS.deref().into())
}
Network::QA => networks.insert(Network::QA, QA_DEFAULTS.deref().into()),
};
}
SupportedNetworks { networks }
+59 -42
View File
@@ -1,5 +1,7 @@
// Copyright 2020 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use url::Url;
@@ -9,65 +11,80 @@ pub mod mainnet;
pub mod qa;
pub mod sandbox;
// The set of defaults that are decided at compile time. Ideally we want to reduce these to a
// minimum.
// Keep DENOM around mostly for use in contracts. (TODO: consider moving it there, or renaming?)
cfg_if::cfg_if! {
if #[cfg(network = "mainnet")] {
pub const BECH32_PREFIX: &str = mainnet::BECH32_PREFIX;
pub const DEFAULT_NETWORK: all::Network = all::Network::MAINNET;
pub const DENOM: &str = mainnet::DENOM;
pub const DEFAULT_MIXNET_CONTRACT_ADDRESS: &str = mainnet::MIXNET_CONTRACT_ADDRESS;
pub const DEFAULT_VESTING_CONTRACT_ADDRESS: &str = mainnet::VESTING_CONTRACT_ADDRESS;
pub const DEFAULT_BANDWIDTH_CLAIM_CONTRACT_ADDRESS: &str = mainnet::BANDWIDTH_CLAIM_CONTRACT_ADDRESS;
pub const ETH_CONTRACT_ADDRESS: [u8; 20] = mainnet::_ETH_CONTRACT_ADDRESS;
pub const ETH_ERC20_CONTRACT_ADDRESS: [u8; 20] = mainnet::_ETH_ERC20_CONTRACT_ADDRESS;
pub const DEFAULT_REWARDING_VALIDATOR_ADDRESS: &str = mainnet::REWARDING_VALIDATOR_ADDRESS;
pub fn default_validators() -> Vec<ValidatorDetails> {
mainnet::validators()
}
pub fn default_network() -> all::Network {
all::Network::MAINNET
}
} else if #[cfg(network = "qa")] {
pub const BECH32_PREFIX: &str = qa::BECH32_PREFIX;
pub const DEFAULT_NETWORK: all::Network = all::Network::QA;
pub const DENOM: &str = qa::DENOM;
pub const DEFAULT_MIXNET_CONTRACT_ADDRESS: &str = qa::MIXNET_CONTRACT_ADDRESS;
pub const DEFAULT_VESTING_CONTRACT_ADDRESS: &str = qa::VESTING_CONTRACT_ADDRESS;
pub const DEFAULT_BANDWIDTH_CLAIM_CONTRACT_ADDRESS: &str = qa::BANDWIDTH_CLAIM_CONTRACT_ADDRESS;
pub const ETH_CONTRACT_ADDRESS: [u8; 20] = qa::_ETH_CONTRACT_ADDRESS;
pub const ETH_ERC20_CONTRACT_ADDRESS: [u8; 20] = qa::_ETH_ERC20_CONTRACT_ADDRESS;
pub const DEFAULT_REWARDING_VALIDATOR: &str = qa::REWARDING_VALIDATOR_ADDRESS;
pub fn default_validators() -> Vec<ValidatorDetails> {
qa::validators()
}
pub fn default_network() -> all::Network {
all::Network::QA
}
} else if #[cfg(network = "sandbox")] {
pub const BECH32_PREFIX: &str = sandbox::BECH32_PREFIX;
pub const DEFAULT_NETWORK: all::Network = all::Network::SANDBOX;
pub const DENOM: &str = sandbox::DENOM;
pub const DEFAULT_MIXNET_CONTRACT_ADDRESS: &str = sandbox::MIXNET_CONTRACT_ADDRESS;
pub const DEFAULT_VESTING_CONTRACT_ADDRESS: &str = sandbox::VESTING_CONTRACT_ADDRESS;
pub const DEFAULT_BANDWIDTH_CLAIM_CONTRACT_ADDRESS: &str = sandbox::BANDWIDTH_CLAIM_CONTRACT_ADDRESS;
pub const ETH_CONTRACT_ADDRESS: [u8; 20] = sandbox::_ETH_CONTRACT_ADDRESS;
pub const ETH_ERC20_CONTRACT_ADDRESS: [u8; 20] = sandbox::_ETH_ERC20_CONTRACT_ADDRESS;
pub const DEFAULT_REWARDING_VALIDATOR: &str = sandbox::REWARDING_VALIDATOR_ADDRESS;
pub fn default_validators() -> Vec<ValidatorDetails> {
sandbox::validators()
}
pub fn default_network() -> all::Network {
all::Network::SANDBOX
}
}
}
#[derive(Debug, Serialize, Deserialize, Clone)]
// Since these are lazily constructed, we can afford to switch some of them to stronger types in the
// future. If we do this, and also get rid of the references we could potentially unify with
// `NetworkDetails`.
#[derive(Debug)]
pub struct DefaultNetworkDetails<'a> {
bech32_prefix: &'a str,
denom: &'a str,
mixnet_contract_address: &'a str,
vesting_contract_address: &'a str,
bandwidth_claim_contract_address: &'a str,
rewarding_validator_address: &'a str,
validators: Vec<ValidatorDetails>,
}
static MAINNET_DEFAULTS: Lazy<DefaultNetworkDetails<'static>> =
Lazy::new(|| DefaultNetworkDetails {
bech32_prefix: mainnet::BECH32_PREFIX,
denom: mainnet::DENOM,
mixnet_contract_address: mainnet::MIXNET_CONTRACT_ADDRESS,
vesting_contract_address: mainnet::VESTING_CONTRACT_ADDRESS,
bandwidth_claim_contract_address: mainnet::BANDWIDTH_CLAIM_CONTRACT_ADDRESS,
rewarding_validator_address: mainnet::REWARDING_VALIDATOR_ADDRESS,
validators: mainnet::validators(),
});
static SANDBOX_DEFAULTS: Lazy<DefaultNetworkDetails<'static>> =
Lazy::new(|| DefaultNetworkDetails {
bech32_prefix: sandbox::BECH32_PREFIX,
denom: sandbox::DENOM,
mixnet_contract_address: sandbox::MIXNET_CONTRACT_ADDRESS,
vesting_contract_address: sandbox::VESTING_CONTRACT_ADDRESS,
bandwidth_claim_contract_address: sandbox::BANDWIDTH_CLAIM_CONTRACT_ADDRESS,
rewarding_validator_address: sandbox::REWARDING_VALIDATOR_ADDRESS,
validators: sandbox::validators(),
});
static QA_DEFAULTS: Lazy<DefaultNetworkDetails<'static>> = Lazy::new(|| DefaultNetworkDetails {
bech32_prefix: qa::BECH32_PREFIX,
denom: qa::DENOM,
mixnet_contract_address: qa::MIXNET_CONTRACT_ADDRESS,
vesting_contract_address: qa::VESTING_CONTRACT_ADDRESS,
bandwidth_claim_contract_address: qa::BANDWIDTH_CLAIM_CONTRACT_ADDRESS,
rewarding_validator_address: qa::REWARDING_VALIDATOR_ADDRESS,
validators: qa::validators(),
});
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct ValidatorDetails {
// it is assumed those values are always valid since they're being provided in our defaults file
pub nymd_url: String,
@@ -99,15 +116,15 @@ impl ValidatorDetails {
}
pub fn default_nymd_endpoints() -> Vec<Url> {
default_validators()
.iter()
DEFAULT_NETWORK
.validators()
.map(|validator| validator.nymd_url())
.collect()
}
pub fn default_api_endpoints() -> Vec<Url> {
default_validators()
.iter()
DEFAULT_NETWORK
.validators()
.filter_map(|validator| validator.api_url())
.collect()
}
+1
View File
@@ -846,6 +846,7 @@ version = "0.1.0"
dependencies = [
"cfg-if",
"hex-literal",
"once_cell",
"serde",
"thiserror",
"url",
+2 -2
View File
@@ -335,7 +335,7 @@ pub fn migrate(_deps: DepsMut<'_>, _env: Env, _msg: MigrateMsg) -> Result<Respon
pub mod tests {
use super::*;
use crate::support::tests;
use config::defaults::DENOM;
use config::defaults::{DEFAULT_NETWORK, DENOM};
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
use cosmwasm_std::{coins, from_binary};
use mixnet_contract_common::PagedMixnodeResponse;
@@ -345,7 +345,7 @@ pub mod tests {
let mut deps = mock_dependencies();
let env = mock_env();
let msg = InstantiateMsg {
rewarding_validator_address: config::defaults::DEFAULT_REWARDING_VALIDATOR.to_string(),
rewarding_validator_address: DEFAULT_NETWORK.rewarding_validator_address().to_string(),
};
let info = mock_info("creator", &[]);
+2 -2
View File
@@ -17,7 +17,7 @@ pub mod test_helpers {
use crate::mixnodes::storage as mixnodes_storage;
use crate::mixnodes::transactions::try_add_mixnode;
use crate::support::tests;
use config::defaults::DENOM;
use config::defaults::{DEFAULT_NETWORK, DENOM};
use cosmwasm_std::testing::mock_dependencies;
use cosmwasm_std::testing::mock_env;
use cosmwasm_std::testing::mock_info;
@@ -83,7 +83,7 @@ pub mod test_helpers {
pub fn init_contract() -> OwnedDeps<MemoryStorage, MockApi, MockQuerier<Empty>> {
let mut deps = mock_dependencies();
let msg = InstantiateMsg {
rewarding_validator_address: config::defaults::DEFAULT_REWARDING_VALIDATOR.to_string(),
rewarding_validator_address: DEFAULT_NETWORK.rewarding_validator_address().to_string(),
};
let env = mock_env();
let info = mock_info("creator", &[]);
+3 -5
View File
@@ -1,11 +1,9 @@
use network_defaults::{
default_api_endpoints, default_network, default_nymd_endpoints, DEFAULT_MIXNET_CONTRACT_ADDRESS,
};
use network_defaults::{default_api_endpoints, default_nymd_endpoints, DEFAULT_NETWORK};
use validator_client::nymd::QueryNymdClient;
pub(crate) fn new_nymd_client() -> validator_client::Client<QueryNymdClient> {
let network = default_network();
let mixnet_contract = DEFAULT_MIXNET_CONTRACT_ADDRESS.to_string();
let network = DEFAULT_NETWORK;
let mixnet_contract = network.mixnet_contract_address().to_string();
let nymd_url = default_nymd_endpoints()[0].clone();
let api_url = default_api_endpoints()[0].clone();
@@ -3,6 +3,7 @@
use bip39::core::str::FromStr;
use bip39::Mnemonic;
use config::defaults::DEFAULT_NETWORK;
use rand::seq::SliceRandom;
use rand::thread_rng;
use url::Url;
@@ -19,10 +20,7 @@ use bandwidth_claim_contract::payment::LinkPaymentData;
use credentials::token::bandwidth::TokenCredential;
use crypto::asymmetric::identity::{PublicKey, Signature, SIGNATURE_LENGTH};
use gateway_client::bandwidth::eth_contract;
use network_defaults::{
DEFAULT_BANDWIDTH_CLAIM_CONTRACT_ADDRESS, DEFAULT_MIXNET_CONTRACT_ADDRESS, ETH_EVENT_NAME,
ETH_MIN_BLOCK_DEPTH,
};
use network_defaults::{ETH_EVENT_NAME, ETH_MIN_BLOCK_DEPTH};
use validator_client::nymd::{AccountId, NymdClient, SigningNymdClient};
pub(crate) struct ERC20Bridge {
@@ -42,11 +40,11 @@ impl ERC20Bridge {
let mnemonic =
Mnemonic::from_str(&cosmos_mnemonic).expect("Invalid Cosmos mnemonic provided");
let nymd_client = NymdClient::connect_with_mnemonic(
config::defaults::default_network(),
DEFAULT_NETWORK,
nymd_url.as_ref(),
AccountId::from_str(DEFAULT_MIXNET_CONTRACT_ADDRESS).ok(),
AccountId::from_str(DEFAULT_NETWORK.mixnet_contract_address()).ok(),
None,
AccountId::from_str(DEFAULT_BANDWIDTH_CLAIM_CONTRACT_ADDRESS).ok(),
AccountId::from_str(DEFAULT_NETWORK.bandwidth_claim_contract_address()).ok(),
mnemonic,
None,
)
+325 -615
View File
File diff suppressed because it is too large Load Diff
+21 -26
View File
@@ -8,26 +8,34 @@ repository = ""
default-run = "nym_wallet"
edition = "2021"
build = "src/build.rs"
rust-version = "1.56"
rust-version = "1.58"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]
tauri-build = { version = "1.0.0-rc.3" }
tauri-build = { version = "=1.0.0-rc.2", features = [] }
tauri-codegen = "=1.0.0-rc.1"
tauri-macros = "=1.0.0-rc.1"
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
strum = { version = "0.23", features = ["derive"] }
tauri = { version = "1.0.0-rc.3", features = ["shell-open"] }
tokio = { version = "1.10", features = ["sync"] }
dirs = "4.0"
bip39 = "1.0"
thiserror = "1.0"
tendermint-rpc = "0.23.0"
url = "2.2"
rand = "0.6.5"
dirs = "4.0"
eyre = "0.6.5"
rand = "0.6.5"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
strum = { version = "0.23", features = ["derive"] }
tauri = { version = "=1.0.0-rc.2", features = [
"clipboard-all",
"shell-open",
"window-maximize",
] }
tendermint-rpc = "0.23.0"
thiserror = "1.0"
tokio = { version = "1.10", features = ["sync"] }
toml = "0.5.8"
url = "2.2"
aes-gcm = "0.9.4"
argon2 = { version = "0.3.2", features = ["std"] }
@@ -45,26 +53,13 @@ vesting-contract-common = { path = "../../common/cosmwasm-smart-contracts/vestin
config = { path = "../../common/config" }
coconut-interface = { path = "../../common/coconut-interface" }
credentials = { path = "../../common/credentials" }
# Used for Type conversion, can be extracted but its a lot of work
vesting-contract = { path = "../../contracts/vesting" }
[dev-dependencies]
ts-rs = "5.1"
ts-rs = "6.1.2"
tempfile = "3.3.0"
[dev-dependencies.mixnet-contract-common]
path = "../../common/cosmwasm-smart-contracts/mixnet-contract"
features = ["ts-rs"]
[dev-dependencies.validator-client]
path = "../../common/client-libs/validator-client"
features = ["typescript-types"]
[dev-dependencies.vesting-contract-common]
path = "../../common/cosmwasm-smart-contracts/vesting-contract"
features = ["ts-rs"]
[features]
default = ["custom-protocol"]
custom-protocol = ["tauri/custom-protocol"]
+2
View File
@@ -14,6 +14,7 @@ use strum::IntoEnumIterator;
use validator_client::nymd::{CosmosCoin, GasPrice};
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(test, ts(export, export, export_to = "../src/types/rust/denom.ts"))]
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
pub enum Denom {
Major,
@@ -48,6 +49,7 @@ impl TryFrom<CosmosDenom> for Denom {
}
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(test, ts(export, export_to = "../src/types/rust/coin.ts"))]
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
pub struct Coin {
amount: String,
+104 -17
View File
@@ -1,34 +1,37 @@
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use crate::network::Network;
use config::defaults::all::SupportedNetworks;
use crate::network::Network as WalletNetwork;
use config::defaults::{all::SupportedNetworks, ValidatorDetails};
use config::NymConfig;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use std::{fs, io, path::PathBuf};
use strum::IntoEnumIterator;
use url::Url;
mod template;
use template::config_template;
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
pub struct Config {
// Base configuration is not part of the configuration file as it's not intended to be changed.
#[serde(skip)]
base: Base,
// Network level configuration
network: Network,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
pub struct Base {
struct Base {
/// Information on all the networks that the wallet connects to.
networks: SupportedNetworks,
}
impl Default for Base {
fn default() -> Self {
let networks = Network::iter().map(|network| network.into()).collect();
let networks = WalletNetwork::iter()
.map(|network| network.into())
.collect();
Base {
networks: SupportedNetworks::new(networks),
}
@@ -37,7 +40,8 @@ impl Default for Base {
impl NymConfig for Config {
fn template() -> &'static str {
config_template()
// For now we're not using a template
unimplemented!();
}
fn default_root_directory() -> PathBuf {
@@ -58,10 +62,32 @@ impl NymConfig for Config {
fn data_directory(&self) -> PathBuf {
self.root_directory().join("data")
}
fn save_to_file(&self, custom_location: Option<PathBuf>) -> io::Result<()> {
let config_toml = toml::to_string_pretty(&self)
.map_err(|toml_err| io::Error::new(io::ErrorKind::Other, toml_err))?;
// Make sure the whole directory structure actually exists
match custom_location.clone() {
Some(loc) => {
if let Some(parent_dir) = loc.parent() {
fs::create_dir_all(parent_dir)
} else {
Ok(())
}
}
None => fs::create_dir_all(self.config_directory()),
}?;
fs::write(
custom_location.unwrap_or_else(|| self.config_directory().join(Self::config_file_name())),
config_toml,
)
}
}
impl Config {
pub fn get_nymd_validator_url(&self, network: Network) -> Url {
pub fn get_nymd_validator_url(&self, network: WalletNetwork) -> Url {
// TODO make this a random choice
if let Some(Some(validator_details)) = self
.base
@@ -75,7 +101,7 @@ impl Config {
}
}
pub fn get_validator_api_url(&self, network: Network) -> Url {
pub fn get_validator_api_url(&self, network: WalletNetwork) -> Url {
// TODO make this a random choice
if let Some(Some(validator_details)) = self
.base
@@ -89,7 +115,7 @@ impl Config {
}
}
pub fn get_mixnet_contract_address(&self, network: Network) -> Option<cosmrs::AccountId> {
pub fn get_mixnet_contract_address(&self, network: WalletNetwork) -> Option<cosmrs::AccountId> {
self
.base
.networks
@@ -99,7 +125,7 @@ impl Config {
.ok()
}
pub fn get_vesting_contract_address(&self, network: Network) -> Option<cosmrs::AccountId> {
pub fn get_vesting_contract_address(&self, network: WalletNetwork) -> Option<cosmrs::AccountId> {
self
.base
.networks
@@ -111,7 +137,7 @@ impl Config {
pub fn get_bandwidth_claim_contract_address(
&self,
network: Network,
network: WalletNetwork,
) -> Option<cosmrs::AccountId> {
self
.base
@@ -122,3 +148,64 @@ impl Config {
.ok()
}
}
#[derive(Debug, Default, Deserialize, Serialize, Clone, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
struct Network {
// User supplied additional validator urls in addition to the hardcoded ones.
// NOTE: these are separate fields, rather than a map, to force the serialization order.
mainnet: Option<Vec<ValidatorDetails>>,
sandbox: Option<Vec<ValidatorDetails>>,
qa: Option<Vec<ValidatorDetails>>,
}
#[cfg(test)]
mod tests {
use super::*;
use config::defaults::all::Network as NetworkConfig;
fn test_config() -> Config {
Config {
base: Base::default(),
network: Network {
mainnet: Some(vec![
// Add the default one, although the hardcoded default isn't intended to be included in
// the config file.
NetworkConfig::MAINNET.validators().next().unwrap().clone(),
// An additional one
ValidatorDetails {
nymd_url: "https://42".to_string(),
api_url: None,
},
]),
sandbox: Some(NetworkConfig::SANDBOX.validators().cloned().collect()),
qa: None,
},
}
}
#[test]
fn serialize_to_toml() {
assert_eq!(
toml::to_string_pretty(&test_config()).unwrap(),
r#"[[network.mainnet]]
nymd_url = 'https://rpc.nyx.nodes.guru/'
api_url = 'https://api.nyx.nodes.guru/'
[[network.mainnet]]
nymd_url = 'https://42'
[[network.sandbox]]
nymd_url = 'https://sandbox-validator.nymtech.net'
api_url = 'https://sandbox-validator.nymtech.net/api'
"#
);
}
#[test]
fn serialize_and_deserialize_to_toml() {
let config = test_config();
let config_str = toml::to_string_pretty(&config).unwrap();
let config_from_toml = toml::from_str(&config_str).unwrap();
assert_eq!(config, config_from_toml);
}
}
@@ -1,17 +0,0 @@
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
pub(crate) fn config_template() -> &'static str {
r#"
# This is a TOML config file.
# For more information, see https://github.com/toml-lang/toml
##### main base tauri-wallet config options #####
[base]
# Validator server to which the API will be getting information about the network.
validator_url = '{{ base.validator_url }}'
"#
}
-30
View File
@@ -86,33 +86,3 @@ fn main() {
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
#[cfg(test)]
mod test {
ts_rs::export! {
mixnet_contract_common::MixNode => "../src/types/rust/mixnode.ts",
crate::coin::Coin => "../src/types/rust/coin.ts",
crate::network::Network => "../src/types/rust/network.ts",
crate::mixnet::account::Balance => "../src/types/rust/balance.ts",
mixnet_contract_common::Gateway => "../src/types/rust/gateway.ts",
crate::mixnet::send::TauriTxResult => "../src/types/rust/tauritxresult.ts",
crate::mixnet::send::TransactionDetails => "../src/types/rust/transactiondetails.ts",
validator_client::nymd::fee::helpers::Operation => "../src/types/rust/operation.ts",
crate::coin::Denom => "../src/types/rust/denom.ts",
crate::utils::DelegationResult => "../src/types/rust/delegationresult.ts",
crate::mixnet::account::Account => "../src/types/rust/account.ts",
crate::mixnet::account::CreatedAccount => "../src/types/rust/createdaccount.ts",
crate::mixnet::admin::TauriContractStateParams => "../src/types/rust/stateparams.ts",
validator_client::models::CoreNodeStatusResponse => "../src/types/corenodestatusresponse.ts",
validator_client::models::MixnodeStatus => "../src/types/rust/mixnodestatus.ts",
validator_client::models::MixnodeStatusResponse => "../src/types/rust/mixnodestatusresponse.ts",
validator_client::models::RewardEstimationResponse => "../src/types/rust/rewardestimationresponse.ts",
validator_client::models::StakeSaturationResponse => "../src/types/rust/stakesaturaionresponse.ts",
validator_client::models::InclusionProbabilityResponse => "../src/types/rust/inclusionprobabilityresponse.ts",
vesting_contract_common::Period => "../src/types/rust/period.ts",
crate::vesting::PledgeData => "../src/types/rust/pledgedata.ts",
crate::vesting::OriginalVestingResponse => "../src/types/rust/originalvestingresponse.ts",
crate::vesting::VestingAccountInfo => "../src/types/rust/vestingaccountinfo.ts",
crate::vesting::VestingPeriod => "../src/types/rust/vestingperiod.ts",
}
}
+1
View File
@@ -13,6 +13,7 @@ use config::defaults::{mainnet, qa, sandbox};
#[allow(clippy::upper_case_acronyms)]
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(test, ts(export, export_to = "../src/types/rust/network.ts"))]
#[derive(Copy, Clone, Debug, Deserialize, EnumIter, Eq, Hash, PartialEq, Serialize)]
pub enum Network {
QA,
@@ -13,6 +13,7 @@ use strum::IntoEnumIterator;
use tokio::sync::RwLock;
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(test, ts(export, export_to = "../src/types/rust/account.ts"))]
#[derive(Serialize, Deserialize)]
pub struct Account {
contract_address: String,
@@ -31,6 +32,7 @@ impl Account {
}
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(test, ts(export, export_to = "../src/types/rust/createdaccount.ts"))]
#[derive(Serialize, Deserialize)]
pub struct CreatedAccount {
account: Account,
@@ -38,6 +40,7 @@ pub struct CreatedAccount {
}
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(test, ts(export, export_to = "../src/types/rust/balance.ts"))]
#[derive(Serialize, Deserialize)]
pub struct Balance {
coin: Coin,
@@ -129,7 +132,7 @@ async fn _connect_with_mnemonic(
mnemonic: Mnemonic,
state: tauri::State<'_, Arc<RwLock<State>>>,
) -> Result<Account, BackendError> {
let default_network = Network::try_from(config::defaults::default_network())?;
let default_network = Network::try_from(config::defaults::DEFAULT_NETWORK)?;
let mut default_account = None;
for network in Network::iter() {
let client = {
@@ -162,6 +165,7 @@ async fn _connect_with_mnemonic(
w_state.add_client(network, client);
}
default_account
.ok_or_else(|| BackendError::NetworkNotSupported(config::defaults::default_network()))
default_account.ok_or(BackendError::NetworkNotSupported(
config::defaults::DEFAULT_NETWORK,
))
}
@@ -9,6 +9,7 @@ use std::sync::Arc;
use tokio::sync::RwLock;
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(test, ts(export, export_to = "../src/types/rust/stateparams.ts"))]
#[derive(Serialize, Deserialize)]
pub struct TauriContractStateParams {
minimum_mixnode_pledge: String,
@@ -10,6 +10,7 @@ use tokio::sync::RwLock;
use validator_client::nymd::{AccountId, CosmosCoin};
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(test, ts(export, export_to = "../src/types/rust/tauritxresult.ts"))]
#[derive(Deserialize, Serialize)]
pub struct TauriTxResult {
block_height: u64,
@@ -21,6 +22,10 @@ pub struct TauriTxResult {
}
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(
test,
ts(export, export_to = "../src/types/rust/transactiondetails.ts")
)]
#[derive(Deserialize, Serialize)]
pub struct TransactionDetails {
amount: Coin,
@@ -10,6 +10,7 @@ pub mod delegate;
pub mod queries;
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(test, ts(export, export_to = "../src/types/rust/pledgedata.ts"))]
#[derive(Serialize, Deserialize, Debug)]
pub struct PledgeData {
pub amount: Coin,
@@ -32,6 +33,10 @@ impl PledgeData {
}
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(
test,
ts(export, export_to = "../src/types/rust/originalvestingresponse.ts")
)]
#[derive(Serialize, Deserialize, Debug)]
pub struct OriginalVestingResponse {
amount: Coin,
@@ -50,6 +55,10 @@ impl From<VestingOriginalVestingResponse> for OriginalVestingResponse {
}
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(
test,
ts(export, export_to = "../src/types/rust/vestingaccountinfo.ts")
)]
#[derive(Serialize, Deserialize, Debug)]
pub struct VestingAccountInfo {
owner_address: String,
@@ -76,6 +85,7 @@ impl From<VestingAccount> for VestingAccountInfo {
}
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(test, ts(export, export_to = "../src/types/rust/vestingperiod.ts"))]
#[derive(Serialize, Deserialize, Debug)]
pub struct VestingPeriod {
start_time: u64,
+1
View File
@@ -59,6 +59,7 @@ pub async fn outdated_get_approximate_fee(
}
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(test, ts(export, export_to = "../src/types/rust/delegationresult.ts"))]
#[derive(Serialize, Deserialize)]
pub struct DelegationResult {
source_address: String,
+6
View File
@@ -49,6 +49,12 @@
"active": false
},
"allowlist": {
"window": {
"maximize": true
},
"clipboard": {
"all": true
},
"shell": {
"open": true
}
+2 -6
View File
@@ -1,7 +1,3 @@
import { Denom } from "./denom";
import type { Denom } from "./denom";
export interface Account {
contract_address: string;
client_address: string;
denom: Denom;
}
export interface Account { contract_address: string, client_address: string, denom: Denom, }
+2 -5
View File
@@ -1,6 +1,3 @@
import { Coin } from "./coin";
import type { Coin } from "./coin";
export interface Balance {
coin: Coin;
printable_balance: string;
}
export interface Balance { coin: Coin, printable_balance: string, }
+2 -5
View File
@@ -1,6 +1,3 @@
import { Denom } from "./denom";
import type { Denom } from "./denom";
export interface Coin {
amount: string;
denom: Denom;
}
export interface Coin { amount: string, denom: Denom, }
@@ -1,4 +1,2 @@
export interface CoreNodeStatusResponse {
identity: string;
count: number;
}
export interface CoreNodeStatusResponse { identity: string, count: number, }
+2 -5
View File
@@ -1,6 +1,3 @@
import { Account } from "./account";
import type { Account } from "./account";
export interface CreatedAccount {
account: Account;
mnemonic: string;
}
export interface CreatedAccount { account: Account, mnemonic: string, }
@@ -1,7 +1,3 @@
import { Coin } from "./coin";
import type { Coin } from "./coin";
export interface DelegationResult {
source_address: string;
target_address: string;
amount: Coin | null;
}
export interface DelegationResult { source_address: string, target_address: string, amount: Coin | null, }
+1
View File
@@ -1 +1,2 @@
export type Denom = "Major" | "Minor";
+2 -9
View File
@@ -1,9 +1,2 @@
export interface Gateway {
host: string;
mix_port: number;
clients_port: number;
location: string;
sphinx_key: string;
identity_key: string;
version: string;
}
export interface Gateway { host: string, mix_port: number, clients_port: number, location: string, sphinx_key: string, identity_key: string, version: string, }
@@ -1,4 +1,2 @@
export interface InclusionProbabilityResponse {
in_active: number;
in_reserve: number;
}
export interface InclusionProbabilityResponse { in_active: number, in_reserve: number, }
+11 -10
View File
@@ -4,19 +4,20 @@ export * from './coin'
export * from './delegationresult'
export * from './denom'
export * from './gateway'
export * from './inclusionprobabilityresponse'
export * from './mixnode'
export * from './mixnodestatus'
export * from './mixnodestatus'
export * from './mixnodestatusresponse'
export * from './mixnodestatusresponse'
export * from './network'
export * from './operation'
export * from './originalvestingresponse'
export * from './rewardedsetnodestatus'
export * from './rewardestimationresponse'
export * from './stakesaturationresponse'
export * from './stateparams'
export * from './tauritxresult'
export * from './transactiondetails'
export * from './mixnodestatus'
export * from './mixnodestatusresponse'
export * from './stakesaturaionresponse'
export * from './rewardestimationresponse'
export * from './mixnodestatus'
export * from './mixnodestatusresponse'
export * from './inclusionprobabilityresponse'
export * from './network'
export * from './originalvestingresponse'
export * from './vestingperiod'
export * from './vestingaccountinfo'
export * from './vestingperiod'
+2 -10
View File
@@ -1,10 +1,2 @@
export interface MixNode {
host: string;
mix_port: number;
verloc_port: number;
http_api_port: number;
sphinx_key: string;
identity_key: string;
version: string;
profit_margin_percent: number;
}
export interface MixNode { host: string, mix_port: number, verloc_port: number, http_api_port: number, sphinx_key: string, identity_key: string, version: string, profit_margin_percent: number, }
+2 -1
View File
@@ -1 +1,2 @@
export type MixnodeStatus = "Active" | "Standby" | "Inactive" | "NotFound";
export type MixnodeStatus = "active" | "standby" | "inactive" | "not_found";
@@ -1,5 +1,3 @@
import { MixnodeStatus } from "./mixnodestatus";
import type { MixnodeStatus } from "./mixnodestatus";
export interface MixnodeStatusResponse {
status: MixnodeStatus;
}
export interface MixnodeStatusResponse { status: MixnodeStatus, }
+1
View File
@@ -1 +1,2 @@
export type Network = "QA" | "SANDBOX" | "MAINNET";
+2 -31
View File
@@ -1,31 +1,2 @@
export type Operation =
| "Upload"
| "Init"
| "Migrate"
| "ChangeAdmin"
| "Send"
| "BondMixnode"
| "BondMixnodeOnBehalf"
| "UnbondMixnode"
| "UnbondMixnodeOnBehalf"
| "UpdateMixnodeConfig"
| "DelegateToMixnode"
| "DelegateToMixnodeOnBehalf"
| "UndelegateFromMixnode"
| "UndelegateFromMixnodeOnBehalf"
| "BondGateway"
| "BondGatewayOnBehalf"
| "UnbondGateway"
| "UnbondGatewayOnBehalf"
| "UpdateContractSettings"
| "BeginMixnodeRewarding"
| "FinishMixnodeRewarding"
| "TrackUnbondGateway"
| "TrackUnbondMixnode"
| "WithdrawVestedCoins"
| "TrackUndelegation"
| "CreatePeriodicVestingAccount"
| "AdvanceCurrentInterval"
| "WriteRewardedSet"
| "ClearRewardedSet"
| "UpdateMixnetAddress";
export type Operation = "Upload" | "Init" | "Migrate" | "ChangeAdmin" | "Send" | "BondMixnode" | "BondMixnodeOnBehalf" | "UnbondMixnode" | "UnbondMixnodeOnBehalf" | "UpdateMixnodeConfig" | "DelegateToMixnode" | "DelegateToMixnodeOnBehalf" | "UndelegateFromMixnode" | "UndelegateFromMixnodeOnBehalf" | "BondGateway" | "BondGatewayOnBehalf" | "UnbondGateway" | "UnbondGatewayOnBehalf" | "UpdateContractSettings" | "BeginMixnodeRewarding" | "FinishMixnodeRewarding" | "TrackUnbondGateway" | "TrackUnbondMixnode" | "WithdrawVestedCoins" | "TrackUndelegation" | "CreatePeriodicVestingAccount" | "AdvanceCurrentInterval" | "WriteRewardedSet" | "ClearRewardedSet" | "UpdateMixnetAddress";
@@ -1,7 +1,3 @@
import { Coin } from "./coin";
import type { Coin } from "./coin";
export interface OriginalVestingResponse {
amount: Coin;
number_of_periods: number;
period_duration: bigint;
}
export interface OriginalVestingResponse { amount: Coin, number_of_periods: number, period_duration: bigint, }
+2 -1
View File
@@ -1 +1,2 @@
export type Period = "Before" | number | "After";
export type Period = "Before" | { In: number } | "After";
+2 -5
View File
@@ -1,6 +1,3 @@
import { Coin } from "./coin";
import type { Coin } from "./coin";
export interface PledgeData {
amount: Coin;
block_time: bigint;
}
export interface PledgeData { amount: Coin, block_time: bigint, }
@@ -0,0 +1,2 @@
export type RewardedSetNodeStatus = "Active" | "Standby";
@@ -1,9 +1,2 @@
export interface RewardEstimationResponse {
estimated_total_node_reward: bigint;
estimated_operator_reward: bigint;
estimated_delegators_reward: bigint;
current_interval_start: bigint;
current_interval_end: bigint;
current_interval_uptime: number;
as_at: bigint;
}
export interface RewardEstimationResponse { estimated_total_node_reward: bigint, estimated_operator_reward: bigint, estimated_delegators_reward: bigint, current_interval_start: bigint, current_interval_end: bigint, current_interval_uptime: number, as_at: bigint, }
@@ -1,4 +0,0 @@
export interface StakeSaturationResponse {
saturation: number;
as_at: bigint;
}
@@ -0,0 +1,2 @@
export interface StakeSaturationResponse { saturation: number, as_at: bigint, }
+2 -6
View File
@@ -1,6 +1,2 @@
export interface TauriContractStateParams {
minimum_mixnode_pledge: string;
minimum_gateway_pledge: string;
mixnode_rewarded_set_size: number;
mixnode_active_set_size: number;
}
export interface TauriContractStateParams { minimum_mixnode_pledge: string, minimum_gateway_pledge: string, mixnode_rewarded_set_size: number, mixnode_active_set_size: number, }
+2 -9
View File
@@ -1,10 +1,3 @@
import { TransactionDetails } from "./transactiondetails";
import type { TransactionDetails } from "./transactiondetails";
export interface TauriTxResult {
block_height: bigint;
code: number;
details: TransactionDetails;
gas_used: bigint;
gas_wanted: bigint;
tx_hash: string;
}
export interface TauriTxResult { block_height: bigint, code: number, details: TransactionDetails, gas_used: bigint, gas_wanted: bigint, tx_hash: string, }
@@ -1,7 +1,3 @@
import { Coin } from "./coin";
import type { Coin } from "./coin";
export interface TransactionDetails {
amount: Coin;
from_address: string;
to_address: string;
}
export interface TransactionDetails { amount: Coin, from_address: string, to_address: string, }
@@ -1,10 +1,4 @@
import { Coin } from "./coin";
import { VestingPeriod } from "./vestingperiod";
import type { Coin } from "./coin";
import type { VestingPeriod } from "./vestingperiod";
export interface VestingAccountInfo {
owner_address: string;
staking_address: string | null;
start_time: bigint;
periods: Array<VestingPeriod>;
coin: Coin;
}
export interface VestingAccountInfo { owner_address: string, staking_address: string | null, start_time: bigint, periods: Array<VestingPeriod>, coin: Coin, }
+2 -4
View File
@@ -1,4 +1,2 @@
export interface VestingPeriod {
start_time: bigint;
period_seconds: bigint;
}
export interface VestingPeriod { start_time: bigint, period_seconds: bigint, }
+2 -2
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
use crate::config::template::config_template;
use config::defaults::{default_api_endpoints, DEFAULT_MIXNET_CONTRACT_ADDRESS};
use config::defaults::{default_api_endpoints, DEFAULT_NETWORK};
use config::NymConfig;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
@@ -97,7 +97,7 @@ impl Default for Base {
local_validator: DEFAULT_LOCAL_VALIDATOR
.parse()
.expect("default local validator is malformed!"),
mixnet_contract_address: DEFAULT_MIXNET_CONTRACT_ADDRESS.to_string(),
mixnet_contract_address: DEFAULT_NETWORK.mixnet_contract_address().to_string(),
#[cfg(feature = "coconut")]
keypair_bs58: String::default(),
}
+3 -3
View File
@@ -3,7 +3,7 @@
use crate::config::Config;
use crate::rewarding::{error::RewardingError, IntervalRewardParams, MixnodeToReward};
use config::defaults::{default_network, DEFAULT_VALIDATOR_API_PORT};
use config::defaults::{DEFAULT_NETWORK, DEFAULT_VALIDATOR_API_PORT};
use mixnet_contract_common::{
ContractStateParams, Delegation, ExecuteMsg, GatewayBond, IdentityKey, Interval, MixNodeBond,
MixnodeRewardingStatusResponse, RewardedSetNodeStatus, RewardedSetUpdateDetails,
@@ -37,7 +37,7 @@ impl Client<QueryNymdClient> {
.parse()
.unwrap();
let nymd_url = config.get_nymd_validator_url();
let network = default_network();
let network = DEFAULT_NETWORK;
let mixnet_contract = config
.get_mixnet_contract_address()
@@ -67,7 +67,7 @@ impl Client<SigningNymdClient> {
.parse()
.unwrap();
let nymd_url = config.get_nymd_validator_url();
let network = default_network();
let network = DEFAULT_NETWORK;
let mixnet_contract = config
.get_mixnet_contract_address()
+7 -4
View File
@@ -9,7 +9,7 @@ use crate::storage::models::{
FailedMixnodeRewardChunk, PossiblyUnrewardedMixnode, RewardingReport,
};
use crate::storage::ValidatorApiStorage;
use config::defaults::DENOM;
use config::defaults::DEFAULT_NETWORK;
use log::{error, info};
use mixnet_contract_common::mixnode::NodeRewardParams;
use mixnet_contract_common::{
@@ -201,15 +201,18 @@ impl Rewarder {
info!("Rewarding pool stats");
info!(
"-- Reward pool: {} {}",
interval_reward_params.reward_pool, DENOM
interval_reward_params.reward_pool,
DEFAULT_NETWORK.denom()
);
info!(
"---- Interval reward pool: {} {}",
interval_reward_params.period_reward_pool, DENOM
interval_reward_params.period_reward_pool,
DEFAULT_NETWORK.denom()
);
info!(
"-- Circulating supply: {} {}",
interval_reward_params.circulating_supply, DENOM
interval_reward_params.circulating_supply,
DEFAULT_NETWORK.denom()
);
// 1. get list of all currently bonded nodes
@@ -7,5 +7,6 @@ edition = "2021"
[dependencies]
serde = "1.0"
ts-rs = { version = "5.1", optional = true }
[dev-dependencies]
ts-rs = "6.1.2"
@@ -5,7 +5,11 @@ use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(
test,
ts(export, export_to = "../../nym-wallet/src/types/rust/mixnodestatus.ts")
)]
#[serde(rename_all = "snake_case")]
pub enum MixnodeStatus {
Active, // in both the active set and the rewarded set
@@ -21,20 +25,41 @@ impl MixnodeStatus {
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(
test,
ts(
export,
export_to = "../../nym-wallet/src/types/rust/corenodestatusresponse.ts"
)
)]
pub struct CoreNodeStatusResponse {
pub identity: String,
pub count: i32,
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(
test,
ts(
export,
export_to = "../../nym-wallet/src/types/rust/mixnodestatusresponse.ts"
)
)]
pub struct MixnodeStatusResponse {
pub status: MixnodeStatus,
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(
test,
ts(
export,
export_to = "../../nym-wallet/src/types/rust/rewardestimationresponse.ts"
)
)]
pub struct RewardEstimationResponse {
pub estimated_total_node_reward: u64,
pub estimated_operator_reward: u64,
@@ -47,14 +72,28 @@ pub struct RewardEstimationResponse {
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(
test,
ts(
export,
export_to = "../../nym-wallet/src/types/rust/stakesaturationresponse.ts"
)
)]
pub struct StakeSaturationResponse {
pub saturation: f32,
pub as_at: i64,
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(test, derive(ts_rs::TS))]
#[cfg_attr(
test,
ts(
export,
export_to = "../../nym-wallet/src/types/rust/inclusionprobabilityresponse.ts"
)
)]
pub struct InclusionProbabilityResponse {
pub in_active: f32,
pub in_reserve: f32,