Dedicated workspace, random_mnemonic, gas_limits

This commit is contained in:
Drazen Urch
2021-09-09 13:21:27 +02:00
parent 926689da1d
commit 265f7a7c2e
8 changed files with 5318 additions and 107 deletions
Generated
+38 -62
View File
@@ -330,9 +330,9 @@ dependencies = [
[[package]]
name = "bip32"
version = "0.2.1"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b48054b307f98bf2ddb17ffd4e9d029bfaf3e7cd5fe807e412768e4370015e3d"
checksum = "c2d0f0fc59c7ba0333eed9dcc1b6980baa7b7a4dc7c6c5885994d0674f7adf34"
dependencies = [
"bs58",
"hkd32",
@@ -1124,9 +1124,9 @@ dependencies = [
[[package]]
name = "crypto-bigint"
version = "0.2.4"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc209804a22c34a98fe26a32d997ac64d4284816f65cf1a529c4e31a256218a0"
checksum = "e49339137316df1914fdb54a5eae75a73f45068fd0d2178fe235b11d93238a6e"
dependencies = [
"generic-array 0.14.4",
"rand_core 0.6.3",
@@ -2891,9 +2891,9 @@ dependencies = [
[[package]]
name = "js-sys"
version = "0.3.53"
version = "0.3.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4bf49d50e2961077d9c99f4b7997d770a1114f087c3c2e0069b36c13fc2979d"
checksum = "1866b355d9c878e5e607473cbe3f63282c0b7aad2db1dbebf55076c686918254"
dependencies = [
"wasm-bindgen",
]
@@ -3083,9 +3083,9 @@ checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
[[package]]
name = "minimal-lexical"
version = "0.1.2"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6595bb28ed34f43c3fe088e48f6cfb2e033cab45f25a5384d5fdf564fbc8c4b2"
checksum = "0c835948974f68e0bd58636fc6c5b1fbff7b297e3046f11b3b3c18bbac012c6d"
[[package]]
name = "miniz_oxide"
@@ -3607,30 +3607,6 @@ dependencies = [
"version-checker",
]
[[package]]
name = "nym_wallet"
version = "0.1.0"
dependencies = [
"bip39",
"coconut-interface",
"config",
"cosmos_sdk",
"cosmwasm-std",
"credentials",
"dirs",
"mixnet-contract",
"serde",
"serde_json",
"tauri",
"tauri-build",
"tendermint-rpc",
"thiserror",
"tokio",
"ts-rs",
"url",
"validator-client",
]
[[package]]
name = "nymsphinx"
version = "0.1.0"
@@ -5327,9 +5303,9 @@ checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d"
[[package]]
name = "sha2"
version = "0.9.6"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9204c41a1597a8c5af23c82d1c921cb01ec0a4c59e07a9c7306062829a3903f3"
checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa"
dependencies = [
"block-buffer 0.9.0",
"cfg-if 1.0.0",
@@ -5371,9 +5347,9 @@ dependencies = [
[[package]]
name = "siphasher"
version = "0.3.6"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "729a25c17d72b06c68cb47955d44fda88ad2d3e7d77e025663fdd69b93dd71a1"
checksum = "533494a8f9b724d33625ab53c6c4800f7cc445895924a8ef649222dcb76e938b"
[[package]]
name = "slab"
@@ -5960,9 +5936,9 @@ dependencies = [
[[package]]
name = "syn"
version = "1.0.75"
version = "1.0.76"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7f58f7e8eaa0009c5fec437aabf511bd9933e4b2d7407bd05273c01a8906ea7"
checksum = "c6f107db402c2c2055242dbf4d2af0e69197202e9faacbef9571bbe47f5a1b84"
dependencies = [
"proc-macro2",
"quote",
@@ -6338,18 +6314,18 @@ checksum = "8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c"
[[package]]
name = "thiserror"
version = "1.0.28"
version = "1.0.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "283d5230e63df9608ac7d9691adc1dfb6e701225436eb64d0b9a7f0a5a04f6ec"
checksum = "602eca064b2d83369e2b2f34b09c70b605402801927c65c11071ac911d299b88"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.28"
version = "1.0.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa3884228611f5cd3608e2d409bf7dce832e4eb3135e3f11addbd7e41bd68e71"
checksum = "bad553cc2c78e8de258400763a647e80e6d1b31ee237275d756f6836d204494c"
dependencies = [
"proc-macro2",
"quote",
@@ -6505,9 +6481,9 @@ dependencies = [
[[package]]
name = "tokio-util"
version = "0.6.7"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1caa0b0c8d94a049db56b5acf8cba99dc0623aab1b26d5b5f5e2d945846b3592"
checksum = "08d3725d3efa29485e87311c5b699de63cde14b00ed4d256b8318aa30ca452cd"
dependencies = [
"bytes",
"futures-core",
@@ -6882,9 +6858,9 @@ checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
name = "wasm-bindgen"
version = "0.2.76"
version = "0.2.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ce9b1b516211d33767048e5d47fa2a381ed8b76fc48d2ce4aa39877f9f183e0"
checksum = "5e68338db6becec24d3c7977b5bf8a48be992c934b5d07177e3931f5dc9b076c"
dependencies = [
"cfg-if 1.0.0",
"serde",
@@ -6894,9 +6870,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.76"
version = "0.2.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfe8dc78e2326ba5f845f4b5bf548401604fa20b1dd1d365fb73b6c1d6364041"
checksum = "f34c405b4f0658583dba0c1c7c9b694f3cac32655db463b56c254a1c75269523"
dependencies = [
"bumpalo",
"lazy_static",
@@ -6909,9 +6885,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.26"
version = "0.4.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95fded345a6559c2cfee778d562300c581f7d4ff3edb9b0d230d69800d213972"
checksum = "a87d738d4abc4cf22f6eb142f5b9a81301331ee3c767f2fef2fda4e325492060"
dependencies = [
"cfg-if 1.0.0",
"js-sys",
@@ -6921,9 +6897,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.76"
version = "0.2.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44468aa53335841d9d6b6c023eaab07c0cd4bddbcfdee3e2bb1e8d2cb8069fef"
checksum = "b9d5a6580be83b19dc570a8f9c324251687ab2184e57086f71625feb57ec77c8"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@@ -6931,9 +6907,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.76"
version = "0.2.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0195807922713af1e67dc66132c7328206ed9766af3858164fb583eedc25fbad"
checksum = "e3775a030dc6f5a0afd8a84981a21cc92a781eb429acef9ecce476d0c9113e92"
dependencies = [
"proc-macro2",
"quote",
@@ -6944,15 +6920,15 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.76"
version = "0.2.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acdb075a845574a1fa5f09fd77e43f7747599301ea3417a9fbffdeedfc1f4a29"
checksum = "c279e376c7a8e8752a8f1eaa35b7b0bee6bb9fb0cdacfa97cc3f1f289c87e2b4"
[[package]]
name = "wasm-bindgen-test"
version = "0.3.26"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "046f563713e2e7a602f0b45d49a564355f9a8a404cac3fa27b9855718f6ba97a"
checksum = "02129da5406bad6e3b2042d0e19f963c03b84f0b05908599fc7f0980afb3158b"
dependencies = [
"console_error_panic_hook",
"js-sys",
@@ -6964,9 +6940,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-test-macro"
version = "0.3.26"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b561e538d0e87b844dd2ce4608581373854f19c4fa2c473570d9fa3797eeb56"
checksum = "7848675a1de39f7470ba747c4aa689f2977e190ab9589cdce6bd8a77c5743bd4"
dependencies = [
"proc-macro2",
"quote",
@@ -6986,9 +6962,9 @@ dependencies = [
[[package]]
name = "web-sys"
version = "0.3.53"
version = "0.3.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "224b2f6b67919060055ef1a67807367c2066ed520c3862cc013d26cf893a783c"
checksum = "0a84d70d1ec7d2da2d26a5bd78f4bca1b8c3254805363ce743b7a05bc30d195a"
dependencies = [
"js-sys",
"wasm-bindgen",
-1
View File
@@ -49,7 +49,6 @@ members = [
"mixnode",
"service-providers/network-requester",
"validator-api",
"tauri-wallet/src-tauri",
]
default-members = [
@@ -6,6 +6,7 @@ use cosmos_sdk::tx::{Fee, Gas};
use cosmos_sdk::Coin;
use cosmwasm_std::Uint128;
use std::fmt;
use std::collections::HashMap;
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub enum Operation {
@@ -40,28 +41,28 @@ pub(crate) fn calculate_fee(gas_price: &GasPrice, gas_limit: Gas) -> Coin {
impl fmt::Display for Operation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Operation::Upload => f.write_str("Upload"),
Operation::Init => f.write_str("Init"),
Operation::Migrate => f.write_str("Migrate"),
Operation::ChangeAdmin => f.write_str("ChangeAdmin"),
Operation::Send => f.write_str("Send"),
Operation::BondMixnode => f.write_str("BondMixnode"),
Operation::UnbondMixnode => f.write_str("UnbondMixnode"),
Operation::DelegateToMixnode => f.write_str("DelegateToMixnode"),
Operation::UndelegateFromMixnode => f.write_str("UndelegateFromMixnode"),
Operation::BondGateway => f.write_str("BondGateway"),
Operation::UnbondGateway => f.write_str("UnbondGateway"),
Operation::DelegateToGateway => f.write_str("DelegateToGateway"),
Operation::UndelegateFromGateway => f.write_str("UndelegateFromGateway"),
Operation::UpdateStateParams => f.write_str("UpdateStateParams"),
}
match *self {
Operation::Upload => f.write_str("Upload"),
Operation::Init => f.write_str("Init"),
Operation::Migrate => f.write_str("Migrate"),
Operation::ChangeAdmin => f.write_str("ChangeAdmin"),
Operation::Send => f.write_str("Send"),
Operation::BondMixnode => f.write_str("BondMixnode"),
Operation::UnbondMixnode => f.write_str("UnbondMixnode"),
Operation::DelegateToMixnode => f.write_str("DelegateToMixnode"),
Operation::UndelegateFromMixnode => f.write_str("UndelegateFromMixnode"),
Operation::BondGateway => f.write_str("BondGateway"),
Operation::UnbondGateway => f.write_str("UnbondGateway"),
Operation::DelegateToGateway => f.write_str("DelegateToGateway"),
Operation::UndelegateFromGateway => f.write_str("UndelegateFromGateway"),
Operation::UpdateStateParams => f.write_str("UpdateStateParams"),
}
}
}
}
impl Operation {
// TODO: some value tweaking
pub(crate) fn default_gas_limit(&self) -> Gas {
pub fn default_gas_limit(&self) -> Gas {
match self {
Operation::Upload => 2_500_000u64.into(),
Operation::Init => 500_000u64.into(),
@@ -95,6 +96,25 @@ impl Operation {
}
}
pub fn default_gas_limits() -> HashMap<Operation, Gas> {
let mut limits = HashMap::new();
limits.insert(Operation::Upload, 2_500_000u64.into());
limits.insert(Operation::Init, 500_000u64.into());
limits.insert(Operation::Migrate, 200_000u64.into());
limits.insert(Operation::ChangeAdmin, 80_000u64.into());
limits.insert(Operation::Send, 80_000u64.into());
limits.insert(Operation::BondMixnode, 175_000u64.into());
limits.insert(Operation::UnbondMixnode, 175_000u64.into());
limits.insert(Operation::DelegateToMixnode, 175_000u64.into());
limits.insert(Operation::UndelegateFromMixnode, 175_000u64.into());
limits.insert(Operation::BondGateway, 175_000u64.into());
limits.insert(Operation::UnbondGateway, 175_000u64.into());
limits.insert(Operation::DelegateToGateway, 175_000u64.into());
limits.insert(Operation::UndelegateFromGateway, 175_000u64.into());
limits.insert(Operation::UpdateStateParams, 175_000u64.into());
limits
}
#[cfg(test)]
mod tests {
use super::*;
@@ -32,7 +32,7 @@ pub use signing_client::Client as SigningNymdClient;
pub mod cosmwasm_client;
pub mod error;
pub(crate) mod fee_helpers;
pub mod fee_helpers;
pub mod gas_price;
pub mod wallet;
+5206
View File
File diff suppressed because it is too large Load Diff
+2
View File
@@ -0,0 +1,2 @@
[workspace]
members = ["src-tauri"]
+2 -1
View File
@@ -1,7 +1,7 @@
[package]
name = "nym_wallet"
version = "0.1.0"
description = "A Tauri App"
description = "Nym Native Wallet"
authors = ["you"]
license = ""
repository = ""
@@ -26,6 +26,7 @@ thiserror = "1.0"
tendermint-rpc = "0.21.0"
ts-rs = "3.0"
url = "2.0"
rand = "0.6.5"
cosmos_sdk = { git = "https://github.com/cosmos/cosmos-rust/", rev = "ba012bd820240d3df2d9a0ab1deabe4ecd9a2f30", features = [
"rpc",
+31 -24
View File
@@ -4,7 +4,7 @@
)]
use ::config::defaults::DENOM;
use bip39::Mnemonic;
use bip39::{Language, Mnemonic};
use cosmos_sdk::Coin as CosmosCoin;
use cosmos_sdk::Denom as CosmosDenom;
use cosmos_sdk::{AccountId, Decimal};
@@ -12,14 +12,15 @@ use cosmwasm_std::Coin as CosmWasmCoin;
use error::BackendError;
use mixnet_contract::{Gateway, MixNode};
use serde::{Deserialize, Serialize};
use tendermint_rpc::endpoint::broadcast::tx_commit::Response;
use std::collections::HashMap;
use std::convert::{TryFrom, TryInto};
use std::fmt;
use std::str::FromStr;
use std::sync::Arc;
use tendermint_rpc::endpoint::broadcast::tx_commit::Response;
use tokio::sync::RwLock;
use ts_rs::{export, TS};
use validator_client::nymd::fee_helpers::default_gas_limits;
use validator_client::nymd::GasPrice;
use validator_client::nymd::{NymdClient, SigningNymdClient};
@@ -81,21 +82,20 @@ impl FromStr for Denom {
#[derive(Deserialize, Serialize, TS)]
struct TauriTxResult {
code: u32,
gas_wanted: u64,
gas_used: u64,
block_height: u64,
details: TransactionDetails,
code: u32,
gas_wanted: u64,
gas_used: u64,
block_height: u64,
details: TransactionDetails,
}
#[derive(Deserialize, Serialize, TS)]
struct TransactionDetails {
from_address: String,
to_address: String,
amount: Coin
amount: Coin,
}
impl TauriTxResult {
fn new(t: Response, details: TransactionDetails) -> TauriTxResult {
TauriTxResult {
@@ -103,12 +103,11 @@ impl TauriTxResult {
gas_wanted: t.check_tx.gas_wanted.value(),
gas_used: t.check_tx.gas_used.value(),
block_height: t.height.value(),
details
details,
}
}
}
// Proxy types to allow TS generation
#[derive(TS, Serialize, Deserialize, Clone)]
struct Coin {
@@ -434,11 +433,14 @@ async fn send(
let r_state = state.read().await;
let client = r_state.client()?;
match client.send(&address, vec![cosmos_amount], memo).await {
Ok(result) => Ok(TauriTxResult::new(result, TransactionDetails {
from_address: client.address().to_string(),
to_address: address.to_string(),
amount
})),
Ok(result) => Ok(TauriTxResult::new(
result,
TransactionDetails {
from_address: client.address().to_string(),
to_address: address.to_string(),
amount,
},
)),
Err(e) => Err(format_err!(e)),
}
}
@@ -452,16 +454,20 @@ async fn get_gas_price(state: tauri::State<'_, Arc<RwLock<State>>>) -> Result<Co
}
#[tauri::command]
async fn get_gas_limits(
state: tauri::State<'_, Arc<RwLock<State>>>,
) -> Result<HashMap<String, u64>, String> {
let r_state = state.read().await;
let client = r_state.client()?;
async fn get_gas_limits() -> HashMap<String, u64> {
let mut limits = HashMap::new();
for (k, v) in client.get_custom_gas_limits() {
for (k, v) in default_gas_limits() {
limits.insert(k.to_string(), v.value());
}
Ok(limits)
limits
}
#[tauri::command]
async fn random_mnemonic() -> String {
let mut rng = rand::thread_rng();
Mnemonic::generate_in_with(&mut rng, Language::English, 24)
.unwrap()
.to_string()
}
fn _connect_with_mnemonic(mnemonic: Mnemonic, config: &Config) -> NymdClient<SigningNymdClient> {
@@ -500,7 +506,8 @@ fn main() {
randomise_credential,
delete_credential,
list_credentials,
verify_credential
verify_credential,
random_mnemonic
])
.run(tauri::generate_context!())
.expect("error while running tauri application");