diff --git a/Cargo.lock b/Cargo.lock index dfefd1f7a6..ad69e7bb91 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3501,6 +3501,7 @@ dependencies = [ "bip39", "config", "cosmos_sdk", + "cosmwasm-std", "dirs", "mixnet-contract", "serde", diff --git a/tauri-wallet/src-tauri/Cargo.toml b/tauri-wallet/src-tauri/Cargo.toml index 6fb579cd4c..e7aea57ad2 100644 --- a/tauri-wallet/src-tauri/Cargo.toml +++ b/tauri-wallet/src-tauri/Cargo.toml @@ -25,7 +25,12 @@ bip39 = "1.0" thiserror = "1.0" tendermint-rpc = "0.21.0" -cosmos_sdk = { git = "https://github.com/cosmos/cosmos-rust/", rev="ba012bd820240d3df2d9a0ab1deabe4ecd9a2f30", features = ["rpc", "bip32", "cosmwasm"] } +cosmos_sdk = { git = "https://github.com/cosmos/cosmos-rust/", rev = "ba012bd820240d3df2d9a0ab1deabe4ecd9a2f30", features = [ + "rpc", + "bip32", + "cosmwasm", +] } +cosmwasm-std = { git = "https://github.com/jstuczyn/cosmwasm", branch = "0.14.1-updatedk256" } validator-client = { path = "../../common/client-libs/validator-client", features = [ "nymd-client", diff --git a/tauri-wallet/src-tauri/src/main.rs b/tauri-wallet/src-tauri/src/main.rs index 13a1dc5abe..6b0c6c1728 100644 --- a/tauri-wallet/src-tauri/src/main.rs +++ b/tauri-wallet/src-tauri/src/main.rs @@ -4,8 +4,11 @@ )] use bip39::Mnemonic; -use cosmos_sdk::{AccountId, Coin, Decimal}; +use cosmos_sdk::Coin as CosmosCoin; +use cosmos_sdk::{AccountId, Decimal}; +use cosmwasm_std::Coin; use error::BackendError; +use mixnet_contract::MixNode; use std::collections::HashMap; use std::str::FromStr; use validator_client::nymd::{NymdClient, SigningNymdClient}; @@ -31,7 +34,7 @@ macro_rules! format_err { }; } -fn printable_coin(coin: Option) -> Result { +fn printable_coin(coin: Option) -> Result { if let Some(coin) = coin { let amount = match native_to_printable(&coin.amount.to_string()) { Ok(amount) => amount, @@ -48,7 +51,7 @@ fn printable_coin(coin: Option) -> Result { } } -fn printable_balance(balance: Option>) -> Result { +fn printable_balance(balance: Option>) -> Result { if let Some(balance) = balance { if !balance.is_empty() { return Ok( @@ -159,7 +162,58 @@ async fn get_balance( Err(e) => Err(BackendError::from(e).to_string()), } } else { - Err(String::from("Client has not been initialized yet")) + Err(String::from( + "Client has not been initialized yet, connect with mnemonic to initialize", + )) + } +} + +#[tauri::command] +async fn owns_mixnode(state: tauri::State<'_, Arc>>) -> Result { + let r_state = state.read().await; + if let Some(client) = &r_state.signing_client { + match client.owns_mixnode(client.address()).await { + Ok(o) => Ok(o), + Err(e) => Err(format_err!(e)), + } + } else { + Err(String::from( + "Client has not been initialized yet, connect with mnemonic to initialize", + )) + } +} + +#[tauri::command] +async fn owns_gateway(state: tauri::State<'_, Arc>>) -> Result { + let r_state = state.read().await; + if let Some(client) = &r_state.signing_client { + match client.owns_gateway(client.address()).await { + Ok(o) => Ok(o), + Err(e) => Err(format_err!(e)), + } + } else { + Err(String::from( + "Client has not been initialized yet, connect with mnemonic to initialize", + )) + } +} + +#[tauri::command] +async fn bond_mixnode( + mixnode: MixNode, + bond: Coin, + state: tauri::State<'_, Arc>>, +) -> Result<(), String> { + let r_state = state.read().await; + if let Some(client) = &r_state.signing_client { + match client.bond_mixnode(mixnode, bond).await { + Ok(_result) => Ok(()), + Err(e) => Err(format_err!(e)), + } + } else { + Err(String::from( + "Client has not been initialized yet, connect with mnemonic to initialize", + )) } } @@ -181,7 +235,10 @@ fn main() { connect_with_mnemonic, get_balance, printable_balance_to_native, - native_to_printable + native_to_printable, + owns_gateway, + owns_mixnode, + bond_mixnode ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); diff --git a/tauri-wallet/src/routes/internal-docs/ApiList.tsx b/tauri-wallet/src/routes/internal-docs/ApiList.tsx index 607a2bb382..a5afb6c499 100644 --- a/tauri-wallet/src/routes/internal-docs/ApiList.tsx +++ b/tauri-wallet/src/routes/internal-docs/ApiList.tsx @@ -47,6 +47,33 @@ export const ApiList = () => { }} /> + + + + + + + + + ); };