diff --git a/common/client-libs/validator-client/src/nymd/mod.rs b/common/client-libs/validator-client/src/nymd/mod.rs index be3b49c297..85484391ec 100644 --- a/common/client-libs/validator-client/src/nymd/mod.rs +++ b/common/client-libs/validator-client/src/nymd/mod.rs @@ -507,14 +507,14 @@ impl NymdClient { /// Removes stake delegation from a particular mixnode. pub async fn remove_mixnode_delegation( &self, - mix_identity: IdentityKey, + mix_identity: &str, ) -> Result where C: SigningCosmWasmClient + Sync, { let fee = self.get_fee(Operation::UndelegateFromMixnode); - let req = ExecuteMsg::UndelegateFromMixnode { mix_identity }; + let req = ExecuteMsg::UndelegateFromMixnode { mix_identity: mix_identity.to_string() }; self.client .execute( self.address(), @@ -574,15 +574,15 @@ impl NymdClient { /// Delegates specified amount of stake to particular gateway. pub async fn delegate_to_gateway( &self, - gateway_identity: IdentityKey, - amount: Coin, + gateway_identity: &str, + amount: &Coin, ) -> Result where C: SigningCosmWasmClient + Sync, { let fee = self.get_fee(Operation::DelegateToGateway); - let req = ExecuteMsg::DelegateToGateway { gateway_identity }; + let req = ExecuteMsg::DelegateToGateway { gateway_identity: gateway_identity.to_string() }; self.client .execute( self.address(), @@ -590,7 +590,7 @@ impl NymdClient { &req, fee, "Delegating to gateway from rust!", - vec![cosmwasm_coin_to_cosmos_coin(amount)], + vec![cosmwasm_coin_ptr_to_cosmos_coin(amount)], ) .await } @@ -598,14 +598,14 @@ impl NymdClient { /// Removes stake delegation from a particular gateway. pub async fn remove_gateway_delegation( &self, - gateway_identity: IdentityKey, + gateway_identity: &str, ) -> Result where C: SigningCosmWasmClient + Sync, { let fee = self.get_fee(Operation::UndelegateFromGateway); - let req = ExecuteMsg::UndelegateFromGateway { gateway_identity }; + let req = ExecuteMsg::UndelegateFromGateway { gateway_identity: gateway_identity.to_string() }; self.client .execute( self.address(), diff --git a/tauri-wallet/src-tauri/src/coconut.rs b/tauri-wallet/src-tauri/src/coconut.rs index 3288617278..554186f980 100644 --- a/tauri-wallet/src-tauri/src/coconut.rs +++ b/tauri-wallet/src-tauri/src/coconut.rs @@ -1,13 +1,10 @@ +use crate::state::State; +use coconut_interface::{self, Credential, Signature, Theta, VerificationKey}; +use credentials::{obtain_aggregate_signature, obtain_aggregate_verification_key}; use std::sync::Arc; use tokio::sync::RwLock; -use coconut_interface::{ - self, Credential, Signature, Theta, VerificationKey, - }; -use crate::state::State; -use credentials::{obtain_aggregate_signature, obtain_aggregate_verification_key}; use url::Url; - #[tauri::command] pub async fn randomise_credential( idx: usize, @@ -65,61 +62,61 @@ pub async fn verify_credential( } async fn prove_credential( - idx: usize, - validator_urls: Vec, - state: tauri::State<'_, Arc>>, - ) -> Result { - let verification_key = get_aggregated_verification_key(validator_urls, state.clone()).await?; - let state = state.read().await; - - if let Some(signature) = state.signatures.get(idx) { - match coconut_interface::prove_credential( - state.params()?, - &verification_key, - signature, - &state.private_attributes(), - ) { - Ok(theta) => Ok(theta), - Err(e) => Err(format!("{}", e)), - } - } else { - Err("Got invalid Signature idx".to_string()) + idx: usize, + validator_urls: Vec, + state: tauri::State<'_, Arc>>, +) -> Result { + let verification_key = get_aggregated_verification_key(validator_urls, state.clone()).await?; + let state = state.read().await; + + if let Some(signature) = state.signatures.get(idx) { + match coconut_interface::prove_credential( + state.params()?, + &verification_key, + signature, + &state.private_attributes(), + ) { + Ok(theta) => Ok(theta), + Err(e) => Err(format!("{}", e)), } + } else { + Err("Got invalid Signature idx".to_string()) + } +} + +async fn get_aggregated_verification_key( + validator_urls: Vec, + state: tauri::State<'_, Arc>>, +) -> Result { + if let Some(verification_key) = &state.read().await.aggregated_verification_key { + return Ok(verification_key.clone()); } - async fn get_aggregated_verification_key( - validator_urls: Vec, - state: tauri::State<'_, Arc>>, - ) -> Result { - if let Some(verification_key) = &state.read().await.aggregated_verification_key { - return Ok(verification_key.clone()); - } - - let parsed_urls = parse_url_validators(&validator_urls)?; - let key = obtain_aggregate_verification_key(&parsed_urls) - .await - .map_err(|err| format!("failed to obtain aggregate verification key - {:?}", err))?; - - state - .write() - .await - .aggregated_verification_key - .replace(key.clone()); - - Ok(key) - } + let parsed_urls = parse_url_validators(&validator_urls)?; + let key = obtain_aggregate_verification_key(&parsed_urls) + .await + .map_err(|err| format!("failed to obtain aggregate verification key - {:?}", err))?; - fn parse_url_validators(raw: &[String]) -> Result, String> { - let mut parsed_urls = Vec::with_capacity(raw.len()); - for url in raw { - let parsed_url: Url = url - .parse() - .map_err(|err| format!("one of validator urls is malformed - {}", err))?; - parsed_urls.push(parsed_url) - } - Ok(parsed_urls) + state + .write() + .await + .aggregated_verification_key + .replace(key.clone()); + + Ok(key) +} + +fn parse_url_validators(raw: &[String]) -> Result, String> { + let mut parsed_urls = Vec::with_capacity(raw.len()); + for url in raw { + let parsed_url: Url = url + .parse() + .map_err(|err| format!("one of validator urls is malformed - {}", err))?; + parsed_urls.push(parsed_url) } - + Ok(parsed_urls) +} + #[tauri::command] pub async fn get_credential( validator_urls: Vec, @@ -140,4 +137,4 @@ pub async fn get_credential( let mut state = state.write().await; state.signatures.push(signature); Ok(state.signatures.clone()) -} \ No newline at end of file +} diff --git a/tauri-wallet/src-tauri/src/coin.rs b/tauri-wallet/src-tauri/src/coin.rs index 598de937ea..313527aa6b 100644 --- a/tauri-wallet/src-tauri/src/coin.rs +++ b/tauri-wallet/src-tauri/src/coin.rs @@ -123,7 +123,7 @@ impl Coin { pub fn new(amount: &str, denom: &Denom) -> Coin { Coin { amount: amount.to_string(), - denom: denom.clone() + denom: denom.clone(), } } } @@ -170,7 +170,7 @@ impl From for Coin { fn from(c: CosmWasmCoin) -> Coin { Coin { amount: c.amount.to_string(), - denom: Denom::from_str(&c.denom.to_string()).unwrap(), + denom: Denom::from_str(&c.denom).unwrap(), } } } diff --git a/tauri-wallet/src-tauri/src/main.rs b/tauri-wallet/src-tauri/src/main.rs index 75194d71c8..5e85ff5c16 100644 --- a/tauri-wallet/src-tauri/src/main.rs +++ b/tauri-wallet/src-tauri/src/main.rs @@ -205,7 +205,7 @@ async fn bond_mixnode( #[tauri::command] async fn delegate_to_mixnode( - identity: String, + identity: &str, amount: Coin, state: tauri::State<'_, Arc>>, ) -> Result { @@ -215,10 +215,10 @@ async fn delegate_to_mixnode( Err(e) => return Err(format_err!(e)), }; let client = r_state.client()?; - match client.delegate_to_mixnode(&identity, &bond).await { + match client.delegate_to_mixnode(identity, &bond).await { Ok(_result) => Ok(DelegationResult { source_address: client.address().to_string(), - target_address: identity, + target_address: identity.to_string(), amount: Some(bond.into()), }), Err(e) => Err(format_err!(e)), @@ -227,44 +227,56 @@ async fn delegate_to_mixnode( #[tauri::command] async fn undelegate_from_mixnode( - identity: String, + identity: &str, state: tauri::State<'_, Arc>>, -) -> Result<(), String> { +) -> Result { let r_state = state.read().await; let client = r_state.client()?; match client.remove_mixnode_delegation(identity).await { - Ok(_result) => Ok(()), + Ok(_result) => Ok(DelegationResult { + source_address: client.address().to_string(), + target_address: identity.to_string(), + amount: None, + }), Err(e) => Err(format_err!(e)), } } #[tauri::command] async fn delegate_to_gateway( - identity: String, + identity: &str, amount: Coin, state: tauri::State<'_, Arc>>, -) -> Result<(), String> { +) -> Result { let r_state = state.read().await; let bond: CosmWasmCoin = match amount.try_into() { Ok(b) => b, Err(e) => return Err(format_err!(e)), }; let client = r_state.client()?; - match client.delegate_to_gateway(identity, bond).await { - Ok(_result) => Ok(()), + match client.delegate_to_gateway(identity, &bond).await { + Ok(_result) => Ok(DelegationResult { + source_address: client.address().to_string(), + target_address: identity.to_string(), + amount: Some(bond.into()), + }), Err(e) => Err(format_err!(e)), } } #[tauri::command] async fn undelegate_from_gateway( - identity: String, + identity: &str, state: tauri::State<'_, Arc>>, -) -> Result<(), String> { +) -> Result { let r_state = state.read().await; let client = r_state.client()?; match client.remove_gateway_delegation(identity).await { - Ok(_result) => Ok(()), + Ok(_result) => Ok(DelegationResult { + source_address: client.address().to_string(), + target_address: identity.to_string(), + amount: None, + }), Err(e) => Err(format_err!(e)), } } @@ -407,5 +419,7 @@ export! { Gateway => "../src/types/rust/gateway.ts", TauriTxResult => "../src/types/rust/tauritxresult.ts", TransactionDetails => "../src/types/rust/transactiondetails.ts", - Operation => "../src/types/rust/operation.ts" + Operation => "../src/types/rust/operation.ts", + Denom => "../src/types/rust/denom.ts", + DelegationResult => "../src/types/rust/delegationresult.ts" } diff --git a/tauri-wallet/src-tauri/src/state.rs b/tauri-wallet/src-tauri/src/state.rs index b437aba84c..501e469cac 100644 --- a/tauri-wallet/src-tauri/src/state.rs +++ b/tauri-wallet/src-tauri/src/state.rs @@ -1,8 +1,6 @@ use crate::config::Config; use crate::format_err; -use coconut_interface::{ - self, Attribute, Parameters, Signature, VerificationKey, -}; +use coconut_interface::{self, Attribute, Parameters, Signature, VerificationKey}; use validator_client::nymd::{NymdClient, SigningNymdClient}; #[derive(Default)] @@ -51,5 +49,4 @@ impl State { pub fn n_attributes(&self) -> u32 { self.n_attributes } - } diff --git a/tauri-wallet/src/types/rust/coin.ts b/tauri-wallet/src/types/rust/coin.ts index cdc4fb18f5..db465263b6 100644 --- a/tauri-wallet/src/types/rust/coin.ts +++ b/tauri-wallet/src/types/rust/coin.ts @@ -1,4 +1,6 @@ +import { Denom } from "./denom"; + export interface Coin { amount: string; - denom: string; + denom: Denom; } \ No newline at end of file diff --git a/tauri-wallet/src/types/rust/delegationresult.ts b/tauri-wallet/src/types/rust/delegationresult.ts new file mode 100644 index 0000000000..a02bcf6b83 --- /dev/null +++ b/tauri-wallet/src/types/rust/delegationresult.ts @@ -0,0 +1,7 @@ +import { Coin } from "./coin"; + +export interface DelegationResult { + source_address: string; + target_address: string; + amount: Coin | null; +} \ No newline at end of file diff --git a/tauri-wallet/src/types/rust/denom.ts b/tauri-wallet/src/types/rust/denom.ts new file mode 100644 index 0000000000..f8f1d41147 --- /dev/null +++ b/tauri-wallet/src/types/rust/denom.ts @@ -0,0 +1 @@ +export type Denom = "Major" | "Minor"; \ No newline at end of file