diff --git a/common/mixnet-contract/src/gateway.rs b/common/mixnet-contract/src/gateway.rs index 7b9c816b4a..eb63fb4dae 100644 --- a/common/mixnet-contract/src/gateway.rs +++ b/common/mixnet-contract/src/gateway.rs @@ -6,8 +6,9 @@ use cosmwasm_std::{coin, Addr, Coin}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; 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 Gateway { pub host: String, pub mix_port: u16, diff --git a/tauri-wallet/src-tauri/src/main.rs b/tauri-wallet/src-tauri/src/main.rs index 4a17e72b3a..e1bdd12199 100644 --- a/tauri-wallet/src-tauri/src/main.rs +++ b/tauri-wallet/src-tauri/src/main.rs @@ -10,7 +10,7 @@ use cosmos_sdk::Denom as CosmosDenom; use cosmos_sdk::{AccountId, Decimal}; use cosmwasm_std::Coin as CosmWasmCoin; use error::BackendError; -use mixnet_contract::MixNode; +use mixnet_contract::{Gateway, MixNode}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::convert::{TryFrom, TryInto}; @@ -310,6 +310,44 @@ async fn bond_mixnode( } } +#[tauri::command] +async fn bond_gateway( + gateway: Gateway, + bond: Coin, + state: tauri::State<'_, Arc>>, +) -> 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_gateway(gateway, 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", + )) + } +} + +#[tauri::command] +async fn unbond_gateway(state: tauri::State<'_, Arc>>) -> Result<(), String> { + let r_state = state.read().await; + if let Some(client) = &r_state.signing_client { + match client.unbond_gateway().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", + )) + } +} + fn _connect_with_mnemonic(mnemonic: Mnemonic, config: &Config) -> NymdClient { match NymdClient::connect_with_mnemonic( config.get_nymd_validator_url().unwrap(), @@ -332,7 +370,9 @@ fn main() { owns_gateway, owns_mixnode, bond_mixnode, - unbond_mixnode + unbond_mixnode, + bond_gateway, + unbond_gateway, ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); @@ -341,5 +381,6 @@ fn main() { export! { MixNode => "../src/types/rust/mixnode.ts", Coin => "../src/types/rust/coin.ts", - Balance => "../src/types/rust/balance.ts" + Balance => "../src/types/rust/balance.ts", + Gateway => "../src/types/rust/gateway.ts" } diff --git a/tauri-wallet/src/routes/internal-docs/ApiList.tsx b/tauri-wallet/src/routes/internal-docs/ApiList.tsx index 22c09d2659..0dda972472 100644 --- a/tauri-wallet/src/routes/internal-docs/ApiList.tsx +++ b/tauri-wallet/src/routes/internal-docs/ApiList.tsx @@ -74,6 +74,33 @@ export const ApiList = () => { }} /> + + + + + + + + + ); }; diff --git a/tauri-wallet/src/types/rust/gateway.ts b/tauri-wallet/src/types/rust/gateway.ts new file mode 100644 index 0000000000..98a81a9914 --- /dev/null +++ b/tauri-wallet/src/types/rust/gateway.ts @@ -0,0 +1,9 @@ +export interface Gateway { + host: string; + mix_port: number; + clients_port: number; + location: string; + sphinx_key: string; + identity_key: string; + version: string; +} \ No newline at end of file