TS exports, rework internals

This commit is contained in:
Drazen Urch
2021-09-02 20:57:10 +02:00
parent 63107c2bca
commit 2587906473
11 changed files with 517 additions and 99 deletions
Generated
+320 -12
View File
@@ -4,6 +4,16 @@
# SPDX-License-Identifier: Apache-2.0
version = 3
[[package]]
name = "Inflector"
version = "0.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3"
dependencies = [
"lazy_static",
"regex",
]
[[package]]
name = "addr2line"
version = "0.16.0"
@@ -147,6 +157,20 @@ version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be4dc07131ffa69b8072d35f5007352af944213cde02545e2103680baed38fcd"
[[package]]
name = "ast_node"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f93f52ce8fac3d0e6720a92b0576d737c01b1b5db4dd786e962e5925f00bf755"
dependencies = [
"darling 0.10.2",
"pmutil",
"proc-macro2",
"quote",
"swc_macros_common",
"syn",
]
[[package]]
name = "async-stream"
version = "0.3.2"
@@ -532,9 +556,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.0.69"
version = "1.0.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e70cc2f62c6ce1868963827bd677764c62d07c3d9a3e1fb1177ee1a9ab199eb2"
checksum = "d26a6ce4b6a484fa3edb70f7efa6fc430fd2b87285fe8b84304fd0936faa0dc0"
dependencies = [
"jobserver",
]
@@ -1466,6 +1490,45 @@ version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]]
name = "dprint-core"
version = "0.35.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93bd44f40b1881477837edc7112695d4b174f058c36c1cbc4c50f8d0482e2ac8"
dependencies = [
"bumpalo",
"fnv",
"serde",
]
[[package]]
name = "dprint-plugin-typescript"
version = "0.43.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67ba0077bd2ab9235848e793fbbfb563e6a04b4c8e4149827802a84063c15805"
dependencies = [
"dprint-core",
"dprint-swc-ecma-ast-view",
"fnv",
"serde",
"swc_common",
"swc_ecmascript",
]
[[package]]
name = "dprint-swc-ecma-ast-view"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecf692a2ee5c5f699ed0e95f21686cf6367f3a591e5d8e7bd3041bbf184651f9"
dependencies = [
"bumpalo",
"fnv",
"num-bigint",
"swc_atoms",
"swc_common",
"swc_ecmascript",
]
[[package]]
name = "dtoa"
version = "0.4.8"
@@ -1575,6 +1638,18 @@ dependencies = [
"cfg-if 1.0.0",
]
[[package]]
name = "enum_kind"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78b940da354ae81ef0926c5eaa428207b8f4f091d3956c891dfbd124162bed99"
dependencies = [
"pmutil",
"proc-macro2",
"swc_macros_common",
"syn",
]
[[package]]
name = "env_logger"
version = "0.7.1"
@@ -1749,6 +1824,18 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "from_variant"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0951635027ca477be98f8774abd6f0345233439d63f307e47101acb40c7cc63d"
dependencies = [
"pmutil",
"proc-macro2",
"swc_macros_common",
"syn",
]
[[package]]
name = "fs2"
version = "0.4.3"
@@ -1946,9 +2033,9 @@ dependencies = [
[[package]]
name = "gdk"
version = "0.14.0"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "679e22651cd15888e7acd01767950edca2ee9fcd6421fbf5b3c3b420d4e88bb0"
checksum = "a453eae5ec10345b3a96ca1b547328bfc94edd40aa95b08f14bb4c35863db140"
dependencies = [
"bitflags",
"cairo-rs",
@@ -2080,9 +2167,9 @@ checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7"
[[package]]
name = "gio"
version = "0.14.3"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "402a7057cd21d64bfa7ac027b344a7f50f677fb3308693df0e8c70fb55d29f0d"
checksum = "81a4c12fcba7a6402ae843a0085ec16d3658a87901763b6a7f0a7c5d60e555a5"
dependencies = [
"bitflags",
"futures-channel",
@@ -2123,9 +2210,9 @@ dependencies = [
[[package]]
name = "glib"
version = "0.14.4"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8fb802e3798d75b415bea8f016eed88d50106ce82f1274e80f31d80cfd4b056"
checksum = "d4a930b7208e6e0ab839eea5f65ac2b82109f729621430d47fe905e2e09d33f4"
dependencies = [
"bitflags",
"futures-channel",
@@ -2721,6 +2808,19 @@ dependencies = [
"serde",
]
[[package]]
name = "is-macro"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a322dd16d960e322c3d92f541b4c1a4f0a2e81e1fdeee430d8cecc8b72e8015f"
dependencies = [
"Inflector",
"pmutil",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "isocountry"
version = "0.3.2"
@@ -3047,6 +3147,7 @@ dependencies = [
"schemars",
"serde",
"serde_repr",
"ts-rs",
]
[[package]]
@@ -3208,6 +3309,18 @@ dependencies = [
"winapi",
]
[[package]]
name = "num-bigint"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304"
dependencies = [
"autocfg 1.0.1",
"num-integer",
"num-traits",
"serde",
]
[[package]]
name = "num-derive"
version = "0.3.3"
@@ -3511,6 +3624,7 @@ dependencies = [
"tendermint-rpc",
"thiserror",
"tokio",
"ts-rs",
"validator-client",
]
@@ -3739,6 +3853,15 @@ dependencies = [
"log",
]
[[package]]
name = "owning_ref"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ff55baddef9e4ad00f88b6c743a2a8062d4c6ade126c2a528644b8e444d52ce"
dependencies = [
"stable_deref_trait",
]
[[package]]
name = "pairing"
version = "0.20.0"
@@ -4049,6 +4172,17 @@ version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c"
[[package]]
name = "pmutil"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3894e5d549cccbe44afecf72922f277f603cd4bb0219c8342631ef18fffbe004"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "png"
version = "0.11.0"
@@ -5585,6 +5719,19 @@ dependencies = [
"quote",
]
[[package]]
name = "string_enum"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f584cc881e9e5f1fd6bf827b0444aa94c30d8fe6378cf241071b5f5700b2871f"
dependencies = [
"pmutil",
"proc-macro2",
"quote",
"swc_macros_common",
"syn",
]
[[package]]
name = "stringprep"
version = "0.1.2"
@@ -5670,6 +5817,144 @@ dependencies = [
"zeroize",
]
[[package]]
name = "swc_atoms"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "837a3ef86c2817228e733b6f173c821fd76f9eb21a0bc9001a826be48b00b4e7"
dependencies = [
"string_cache",
"string_cache_codegen",
]
[[package]]
name = "swc_common"
version = "0.10.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c93df65683ec1a001e15ce1de438c7c2c226c0c2462d1cb93fa1bd2a7664170b"
dependencies = [
"ast_node",
"cfg-if 0.1.10",
"either",
"from_variant",
"fxhash",
"log",
"num-bigint",
"once_cell",
"owning_ref",
"scoped-tls",
"serde",
"string_cache",
"swc_eq_ignore_macros",
"swc_visit",
"unicode-width",
]
[[package]]
name = "swc_ecma_ast"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83eb6a73820660a5af3c24ae1d436e84e4d4c13822021140011361e678df247b"
dependencies = [
"is-macro",
"num-bigint",
"serde",
"string_enum",
"swc_atoms",
"swc_common",
]
[[package]]
name = "swc_ecma_parser"
version = "0.52.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c03250697857164f16fa98f8e1726f566652d13e52ea3f0c3ecea9deb63ee327"
dependencies = [
"either",
"enum_kind",
"fxhash",
"log",
"num-bigint",
"serde",
"smallvec 1.6.1",
"swc_atoms",
"swc_common",
"swc_ecma_ast",
"swc_ecma_visit",
"unicode-xid",
]
[[package]]
name = "swc_ecma_visit"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd3d60b9dc97ae4f181d4d60f43142d8ac9669953db410bcedefb29a14627e19"
dependencies = [
"num-bigint",
"swc_atoms",
"swc_common",
"swc_ecma_ast",
"swc_visit",
]
[[package]]
name = "swc_ecmascript"
version = "0.29.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ffb53afe008c15d4dc4957e80148c4b457659f93e4d4e8736eaeae352e48ec8"
dependencies = [
"swc_ecma_ast",
"swc_ecma_parser",
]
[[package]]
name = "swc_eq_ignore_macros"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c8f200a2eaed938e7c1a685faaa66e6d42fa9e17da5f62572d3cbc335898f5e"
dependencies = [
"pmutil",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "swc_macros_common"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf7c68e78ffbcba3d38abe6d0b76a0e1a37888b5c9301db3426537207090ada3"
dependencies = [
"pmutil",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "swc_visit"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a423caa0b4585118164dbad8f1ad52b592a9a9370b25decc4d84c6b4309132c0"
dependencies = [
"either",
"swc_visit_macros",
]
[[package]]
name = "swc_visit_macros"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3b2825fee79f10d0166e8e650e79c7a862fb991db275743083f07555d7641f0"
dependencies = [
"Inflector",
"pmutil",
"proc-macro2",
"quote",
"swc_macros_common",
"syn",
]
[[package]]
name = "syn"
version = "1.0.75"
@@ -6128,9 +6413,9 @@ dependencies = [
[[package]]
name = "tokio"
version = "1.10.1"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92036be488bb6594459f2e03b60e42df6f937fe6ca5c5ffdcb539c6b84dc40f5"
checksum = "b4efe6fc2395938c8155973d7be49fe8d03a843726e285e100a8a383cc0154ce"
dependencies = [
"autocfg 1.0.1",
"bytes",
@@ -6297,6 +6582,29 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
[[package]]
name = "ts-rs"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89634b937615f3e50462b9529a36aa309d557c893eb79ce8a93d7e1915820859"
dependencies = [
"dprint-plugin-typescript",
"ts-rs-macros",
]
[[package]]
name = "ts-rs-macros"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "117c837b4f78dbaa8e7d06aefae35267f49cb0a47f5df4ed75b777acb83ba14d"
dependencies = [
"Inflector",
"proc-macro2",
"quote",
"syn",
"termcolor",
]
[[package]]
name = "tungstenite"
version = "0.13.0"
@@ -6329,9 +6637,9 @@ dependencies = [
[[package]]
name = "typenum"
version = "1.13.0"
version = "1.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06"
checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec"
[[package]]
name = "ubyte"
+1
View File
@@ -14,3 +14,4 @@ cosmwasm-std = { git = "https://github.com/jstuczyn/cosmwasm", branch="0.14.1-up
serde = { version = "1.0", features = ["derive"] }
serde_repr = "0.1"
schemars = "0.8"
ts-rs = "3.0"
+2 -1
View File
@@ -7,8 +7,9 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
use std::fmt::Display;
use ts_rs::TS;
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, JsonSchema)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, JsonSchema, TS)]
pub struct MixNode {
pub host: String,
pub mix_port: u16,
+2 -1
View File
@@ -17,13 +17,14 @@ tauri-build = { version = "1.0.0-beta.4" }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.0.0-beta.6", features = [] }
tauri = { version = "1.0.0-beta.8", features = [] }
tokio = { version = "1.10", features = ["sync"] }
dirs = "3.0"
# url = "2.2"
bip39 = "1.0"
thiserror = "1.0"
tendermint-rpc = "0.21.0"
ts-rs = "3.0"
cosmos_sdk = { git = "https://github.com/cosmos/cosmos-rust/", rev = "ba012bd820240d3df2d9a0ab1deabe4ecd9a2f30", features = [
"rpc",
+2 -6
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
use config::defaults::{
default_api_endpoints, default_validators, ValidatorDetails, DEFAULT_MIXNET_CONTRACT_ADDRESS,
default_api_endpoints, default_validators, ValidatorDetails, DEFAULT_MIXNET_CONTRACT_ADDRESS
};
use config::NymConfig;
use serde::{Deserialize, Serialize};
@@ -32,9 +32,6 @@ pub struct Base {
/// Mnemonic (currently of the network monitor) used for rewarding
mnemonic: String,
// Avoid breaking derives for now
keypair_bs58: String,
}
impl Default for Base {
@@ -42,8 +39,7 @@ impl Default for Base {
Base {
validators: default_validators(),
mixnet_contract_address: DEFAULT_MIXNET_CONTRACT_ADDRESS.to_string(),
mnemonic: String::default(),
keypair_bs58: String::default(),
mnemonic: String::default()
}
}
}
+163 -75
View File
@@ -3,14 +3,20 @@
windows_subsystem = "windows"
)]
use ::config::defaults::DENOM;
use bip39::Mnemonic;
use cosmos_sdk::Coin as CosmosCoin;
use cosmos_sdk::Denom as CosmosDenom;
use cosmos_sdk::{AccountId, Decimal};
use cosmwasm_std::Coin;
use cosmwasm_std::Coin as CosmWasmCoin;
use error::BackendError;
use mixnet_contract::MixNode;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::convert::{TryFrom, TryInto};
use std::fmt;
use std::str::FromStr;
use ts_rs::{export, TS};
use validator_client::nymd::{NymdClient, SigningNymdClient};
mod config;
@@ -22,88 +28,155 @@ use tokio::sync::RwLock;
use crate::config::Config;
#[derive(Debug, Default)]
struct State {
config: Config,
signing_client: Option<NymdClient<SigningNymdClient>>,
}
macro_rules! format_err {
($e:expr) => {
format!("line {}: {}", line!(), $e)
};
}
fn printable_coin(coin: Option<CosmosCoin>) -> Result<String, String> {
if let Some(coin) = coin {
let amount = match native_to_printable(&coin.amount.to_string()) {
Ok(amount) => amount,
Err(e) => return Err(e),
};
let ticker = if coin.denom.to_string().starts_with("u") {
coin.denom.to_string()[1..].to_uppercase()
} else {
coin.denom.to_string().to_uppercase()
};
Ok(format!("{} {}", amount, ticker))
} else {
Ok("0".to_string())
}
#[derive(TS, Serialize, Deserialize)]
struct Balance {
coin: Coin,
printable_balance: String,
}
fn printable_balance(balance: Option<Vec<CosmosCoin>>) -> Result<String, String> {
if let Some(balance) = balance {
if !balance.is_empty() {
return Ok(
balance
.into_iter()
.map(|coin| match printable_coin(Some(coin)) {
Ok(native) => native,
Err(e) => e,
})
.collect::<Vec<String>>()
.join(", "),
);
enum Denom {
Major,
Minor,
}
impl fmt::Display for Denom {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
&Denom::Major => f.write_str(&DENOM[1..].to_uppercase()),
&Denom::Minor => f.write_str(DENOM),
}
}
Ok("-".to_string())
}
// converts display amount, such as "12.0346" to its native token representation,
// with 6 fractional digits. So in that case it would result in "12034600"
// Basically does the same job as `displayAmountToNative` but without the requirement
// of having the coinMap
#[tauri::command]
fn printable_balance_to_native(amount: &str) -> Result<String, String> {
match amount.parse::<f64>() {
Ok(f) => match Decimal::from_str(&(f * 1_000_000.).to_string()) {
Ok(amount) => Ok(amount.to_string()),
Err(e) => Err(format_err!(format!(
"Could not convert `{}` to Decimal",
amount
))),
},
Err(e) => Err(format_err!(format!(
"Could not convert `{}` to f64",
amount
))),
impl FromStr for Denom {
type Err = String;
fn from_str(s: &str) -> Result<Denom, String> {
if s.to_lowercase() == DENOM.to_lowercase() {
Ok(Denom::Minor)
} else if s.to_lowercase() == DENOM[1..].to_lowercase() {
Ok(Denom::Major)
} else {
Err(format_err!(format!(
"{} is not a valid denomination string",
s
)))
}
}
}
#[tauri::command]
fn native_to_printable(native_value: &str) -> Result<String, String> {
match Decimal::from_str(native_value) {
Ok(decimal) => Ok(format!(
"{}",
decimal.to_string().parse::<f64>().unwrap() / 1_000_000.
)),
Err(e) => Err(format_err!(format!(
"Could not convert `{}` to Decimal",
native_value
))),
// Proxy types to allow TS generation
#[derive(TS, Serialize, Deserialize, Clone)]
struct Coin {
amount: String,
denom: String,
}
impl fmt::Display for Coin {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&format!("{} {}", self.amount, self.denom))
}
}
impl Coin {
fn to_major(&self) -> Coin {
if let Ok(denom) = Denom::from_str(&self.denom) {
match denom {
Denom::Major => self.clone(),
Denom::Minor => Coin {
amount: (self.amount.parse::<f64>().unwrap() / 1_000_000.).to_string(),
denom: Denom::Major.to_string(),
},
}
} else {
unreachable!()
}
}
fn to_minor(&self) -> Coin {
if let Ok(denom) = Denom::from_str(&self.denom) {
match denom {
Denom::Minor => self.clone(),
Denom::Major => Coin {
amount: (self.amount.parse::<f64>().unwrap() * 1_000_000.).to_string(),
denom: Denom::Minor.to_string(),
},
}
} else {
unreachable!()
}
}
}
impl TryFrom<Coin> for CosmWasmCoin {
type Error = String;
fn try_from(coin: Coin) -> Result<CosmWasmCoin, String> {
match serde_json::to_value(coin) {
Ok(value) => match serde_json::from_value(value) {
Ok(coin) => Ok(coin),
Err(e) => Err(format_err!(e)),
},
Err(e) => Err(format_err!(e)),
}
}
}
// There is some confusion here over coins and denoms, it feels like we should use types to differentiate between the two
impl TryFrom<Coin> for CosmosCoin {
type Error = String;
fn try_from(coin: Coin) -> Result<CosmosCoin, String> {
let coin = coin.to_minor();
match Decimal::from_str(&coin.amount) {
Ok(d) => Ok(CosmosCoin {
amount: d,
denom: CosmosDenom::from_str(&coin.denom).unwrap(),
}),
Err(e) => Err(format_err!(e)),
}
}
}
impl From<CosmosCoin> for Coin {
fn from(c: CosmosCoin) -> Coin {
Coin {
amount: c.amount.to_string(),
denom: c.denom.to_string(),
}
}
}
#[derive(Debug, Default)]
struct State {
config: Config,
signing_client: Option<NymdClient<SigningNymdClient>>,
}
#[tauri::command]
fn major_to_minor(amount: String) -> Result<Coin, String> {
let coin = Coin {
amount: amount,
denom: Denom::Major.to_string(),
};
Ok(coin.to_minor())
}
#[tauri::command]
fn minor_to_major(amount: String) -> Result<Coin, String> {
let coin = Coin {
amount: amount,
denom: Denom::Minor.to_string(),
};
Ok(coin.to_major())
}
#[tauri::command]
async fn connect_with_mnemonic(
mnemonic: String,
@@ -142,18 +215,19 @@ async fn connect_with_mnemonic(
}
#[tauri::command]
async fn get_balance(
state: tauri::State<'_, Arc<RwLock<State>>>,
) -> Result<HashMap<&str, String>, String> {
async fn get_balance(state: tauri::State<'_, Arc<RwLock<State>>>) -> Result<Balance, String> {
let r_state = state.read().await;
if let Some(client) = &r_state.signing_client {
match client.get_balance(client.address()).await {
Ok(Some(coin)) => {
let mut balance = HashMap::new();
balance.insert("amount", coin.amount.to_string());
balance.insert("denom", coin.denom.to_string());
balance.insert("printable_balance", printable_coin(Some(coin))?);
Ok(balance)
let coin = Coin {
amount: coin.amount.to_string(),
denom: coin.denom.to_string(),
};
Ok(Balance {
coin: coin.clone(),
printable_balance: coin.to_string(),
})
}
Ok(None) => Err(format!(
"No balance available for address {}",
@@ -198,6 +272,10 @@ async fn owns_gateway(state: tauri::State<'_, Arc<RwLock<State>>>) -> Result<boo
}
}
// coin: {"denom": "upunk", "amount": 0}
// {"host": "", "mix_port": 0, "verloc_port": 0, "http_api_port": 0, "sphinx_key": "", "identity_key": "", "version": ""}
#[tauri::command]
async fn bond_mixnode(
mixnode: MixNode,
@@ -205,6 +283,10 @@ async fn bond_mixnode(
state: tauri::State<'_, Arc<RwLock<State>>>,
) -> Result<(), String> {
let r_state = state.read().await;
let bond: CosmWasmCoin = match bond.try_into() {
Ok(b) => b,
Err(e) => return Err(format_err!(e)),
};
if let Some(client) = &r_state.signing_client {
match client.bond_mixnode(mixnode, bond).await {
Ok(_result) => Ok(()),
@@ -234,8 +316,8 @@ fn main() {
.invoke_handler(tauri::generate_handler![
connect_with_mnemonic,
get_balance,
printable_balance_to_native,
native_to_printable,
minor_to_major,
major_to_minor,
owns_gateway,
owns_mixnode,
bond_mixnode
@@ -243,3 +325,9 @@ fn main() {
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
export! {
MixNode => "../src/types/rust/mixnode.ts",
Coin => "../src/types/rust/coin.ts",
Balance => "../src/types/rust/balance.ts"
}
@@ -34,7 +34,7 @@ export const ApiList = () => {
<ListItem>
<DocEntry
function={{
name: "printable_balance_to_native",
name: "minor_to_major",
args: [{ name: "amount", type: "str" }],
}}
/>
@@ -42,8 +42,8 @@ export const ApiList = () => {
<ListItem>
<DocEntry
function={{
name: "native_to_printable",
args: [{ name: "nativeValue", type: "str" }],
name: "major_to_minor",
args: [{ name: "amount", type: "str" }],
}}
/>
</ListItem>
@@ -34,7 +34,11 @@ const argKey = (functionName: string, arg: string) => `${functionName}_${arg}`
function collectArgs(functionName: string, args: ArgDef[]) {
let invokeArgs = {}
for (let arg of args) {
invokeArgs[arg.name] = document.getElementById(argKey(functionName, arg.name)).value
if (arg.type === 'object') {
invokeArgs[arg.name] = JSON.parse(document.getElementById(argKey(functionName, arg.name)).value)
} else {
invokeArgs[arg.name] = document.getElementById(argKey(functionName, arg.name)).value
}
}
return invokeArgs
}
+6
View File
@@ -0,0 +1,6 @@
import { Coin } from "./coin";
export interface Balance {
coin: Coin;
printable_balance: string;
}
+4
View File
@@ -0,0 +1,4 @@
export interface Coin {
amount: string;
denom: string;
}
+9
View File
@@ -0,0 +1,9 @@
export interface MixNode {
host: string;
mix_port: number;
verloc_port: number;
http_api_port: number;
sphinx_key: string;
identity_key: string;
version: string;
}