From f020b21106c8b8ffdcfe3a823dc67d3fe0883ca3 Mon Sep 17 00:00:00 2001 From: Drazen Urch Date: Thu, 2 Sep 2021 21:08:19 +0200 Subject: [PATCH] node unbond --- tauri-wallet/src-tauri/src/config/mod.rs | 6 ++--- tauri-wallet/src-tauri/src/error.rs | 32 ++++++++++++------------ tauri-wallet/src-tauri/src/main.rs | 30 +++++++++++++++------- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/tauri-wallet/src-tauri/src/config/mod.rs b/tauri-wallet/src-tauri/src/config/mod.rs index f046ff4b7e..011744e0bf 100644 --- a/tauri-wallet/src-tauri/src/config/mod.rs +++ b/tauri-wallet/src-tauri/src/config/mod.rs @@ -1,9 +1,7 @@ // Copyright 2021 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 -use config::defaults::{ - default_api_endpoints, default_validators, ValidatorDetails, DEFAULT_MIXNET_CONTRACT_ADDRESS -}; +use config::defaults::{default_validators, ValidatorDetails, DEFAULT_MIXNET_CONTRACT_ADDRESS}; use config::NymConfig; use serde::{Deserialize, Serialize}; use std::path::PathBuf; @@ -39,7 +37,7 @@ impl Default for Base { Base { validators: default_validators(), mixnet_contract_address: DEFAULT_MIXNET_CONTRACT_ADDRESS.to_string(), - mnemonic: String::default() + mnemonic: String::default(), } } } diff --git a/tauri-wallet/src-tauri/src/error.rs b/tauri-wallet/src-tauri/src/error.rs index bac80998ad..2031829a9a 100644 --- a/tauri-wallet/src-tauri/src/error.rs +++ b/tauri-wallet/src-tauri/src/error.rs @@ -3,19 +3,19 @@ use validator_client::nymd::error::NymdError; #[derive(Error, Debug)] pub enum BackendError { - #[error("Error parsing bip39 mnemonic")] - Bip39Error { - #[from] - source: bip39::Error - }, - #[error("Error parsing into tendermint Url")] - TendermintError { - #[from] - source: tendermint_rpc::Error - }, - #[error("Error getting balances")] - NymdError { - #[from] - source: NymdError - } -} \ No newline at end of file + #[error("Error parsing bip39 mnemonic")] + Bip39Error { + #[from] + source: bip39::Error, + }, + #[error("Error parsing into tendermint Url")] + TendermintError { + #[from] + source: tendermint_rpc::Error, + }, + #[error("Error getting balances")] + NymdError { + #[from] + source: NymdError, + }, +} diff --git a/tauri-wallet/src-tauri/src/main.rs b/tauri-wallet/src-tauri/src/main.rs index bb6e467906..4a17e72b3a 100644 --- a/tauri-wallet/src-tauri/src/main.rs +++ b/tauri-wallet/src-tauri/src/main.rs @@ -47,9 +47,9 @@ enum Denom { 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), + match *self { + Denom::Major => f.write_str(&DENOM[1..].to_uppercase()), + Denom::Minor => f.write_str(DENOM), } } } @@ -162,7 +162,7 @@ struct State { #[tauri::command] fn major_to_minor(amount: String) -> Result { let coin = Coin { - amount: amount, + amount, denom: Denom::Major.to_string(), }; Ok(coin.to_minor()) @@ -171,7 +171,7 @@ fn major_to_minor(amount: String) -> Result { #[tauri::command] fn minor_to_major(amount: String) -> Result { let coin = Coin { - amount: amount, + amount, denom: Denom::Minor.to_string(), }; Ok(coin.to_major()) @@ -272,9 +272,20 @@ async fn owns_gateway(state: tauri::State<'_, Arc>>) -> Result>>) -> Result<(), String> { + let r_state = state.read().await; + if let Some(client) = &r_state.signing_client { + match client.unbond_mixnode().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", + )) + } +} #[tauri::command] async fn bond_mixnode( @@ -320,7 +331,8 @@ fn main() { major_to_minor, owns_gateway, owns_mixnode, - bond_mixnode + bond_mixnode, + unbond_mixnode ]) .run(tauri::generate_context!()) .expect("error while running tauri application");