From 58b5389ed9042a72ce104269edb42da153a42b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Tue, 31 May 2022 14:10:19 +0100 Subject: [PATCH 1/2] Consolidate validator-client coin (#1295) * Created nymd internal coin * Additional From implementations plus a constructor * try_add * Changed client API to use the new coin type * CoinConverter trait * Made wallet compilable with the recent changes * Simplified the API by removing the generics in favour of explicit Coin type * Fixed validator api * Fixed up tests and clippy * Refactored missed coin-generic API methods * changelog --- CHANGELOG.md | 5 + clients/credential/src/client.rs | 19 +- .../validator-client/src/nymd/coin.rs | 130 ++++++++++++++ .../src/nymd/cosmwasm_client/client.rs | 21 +-- .../nymd/cosmwasm_client/signing_client.rs | 16 +- .../src/nymd/cosmwasm_client/types.rs | 21 ++- .../src/nymd/fee/gas_price.rs | 27 ++- .../validator-client/src/nymd/mod.rs | 89 ++++------ .../src/nymd/traits/vesting_query_client.rs | 21 ++- .../src/nymd/traits/vesting_signing_client.rs | 25 +-- nym-wallet/src-tauri/src/coin.rs | 163 +++++------------- nym-wallet/src-tauri/src/error.rs | 3 + nym-wallet/src-tauri/src/network.rs | 17 +- .../src/operations/mixnet/account.rs | 17 +- .../src-tauri/src/operations/mixnet/bond.rs | 6 +- .../src/operations/mixnet/delegate.rs | 7 +- .../src-tauri/src/operations/mixnet/send.rs | 9 +- .../src/operations/simulate/cosmos.rs | 5 +- .../src/operations/simulate/mixnet.rs | 9 +- .../src/operations/simulate/vesting.rs | 17 +- .../src-tauri/src/operations/vesting/bond.rs | 9 +- .../src/operations/vesting/delegate.rs | 5 +- validator-api/src/nymd_client.rs | 6 +- validator-api/src/rewarded_set_updater/mod.rs | 6 +- 24 files changed, 347 insertions(+), 306 deletions(-) create mode 100644 common/client-libs/validator-client/src/nymd/coin.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 927eb0fa5c..b8334cd702 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,10 @@ - mixnet-contract: Under certain circumstances nodes could not be unbonded ([#1255](https://github.com/nymtech/nym/issues/1255)) ([#1258]) - mixnode, gateway: attempting to determine reconnection backoff to persistently failing mixnode could result in a crash ([#1260]) +### Changed + +- validator-client: created internal `Coin` type that replaces coins from `cosmrs` and `cosmwasm` for API entrypoints [[#1295]] + [#1258]: https://github.com/nymtech/nym/pull/1258 [#1249]: https://github.com/nymtech/nym/pull/1249 [#1256]: https://github.com/nymtech/nym/pull/1256 @@ -37,6 +41,7 @@ [#1278]: https://github.com/nymtech/nym/pull/1278 [#1284]: https://github.com/nymtech/nym/pull/1284 [#1292]: https://github.com/nymtech/nym/pull/1292 +[#1295]: https://github.com/nymtech/nym/pull/1295 ## [nym-wallet-v1.0.4](https://github.com/nymtech/nym/tree/nym-wallet-v1.0.4) (2022-05-04) diff --git a/clients/credential/src/client.rs b/clients/credential/src/client.rs index 678a4bdd1d..40f035c6b9 100644 --- a/clients/credential/src/client.rs +++ b/clients/credential/src/client.rs @@ -1,19 +1,15 @@ // Copyright 2022 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 -use bip39::Mnemonic; -use coconut_bandwidth_contract_common::deposit::DepositData; -use std::str::FromStr; -use url::Url; - use crate::error::Result; use crate::{CONTRACT_ADDRESS, MNEMONIC, NYMD_URL}; - +use bip39::Mnemonic; +use coconut_bandwidth_contract_common::deposit::DepositData; use coconut_bandwidth_contract_common::msg::ExecuteMsg; use network_defaults::DEFAULT_NETWORK; -use validator_client::nymd::{ - AccountId, CosmosCoin, Decimal, Denom, NymdClient, SigningNymdClient, -}; +use std::str::FromStr; +use url::Url; +use validator_client::nymd::{AccountId, Coin, Denom, NymdClient, SigningNymdClient}; pub(crate) struct Client { nymd_client: NymdClient, @@ -55,10 +51,7 @@ impl Client { let req = ExecuteMsg::DepositFunds { data: DepositData::new(info.to_string(), verification_key, encryption_key), }; - let funds = vec![CosmosCoin { - denom: self.denom.clone(), - amount: Decimal::from(amount), - }]; + let funds = vec![Coin::new(amount as u128, self.denom.to_string())]; Ok(self .nymd_client .execute(&self.contract_address, &req, Default::default(), "", funds) diff --git a/common/client-libs/validator-client/src/nymd/coin.rs b/common/client-libs/validator-client/src/nymd/coin.rs new file mode 100644 index 0000000000..77451032ac --- /dev/null +++ b/common/client-libs/validator-client/src/nymd/coin.rs @@ -0,0 +1,130 @@ +// Copyright 2022 - Nym Technologies SA +// SPDX-License-Identifier: Apache-2.0 +use serde::{Deserialize, Serialize}; +use std::fmt; + +pub use cosmrs::Coin as CosmosCoin; +pub use cosmwasm_std::Coin as CosmWasmCoin; + +#[derive(Serialize, Deserialize, Clone, Copy, Default, Debug, PartialEq)] +pub struct MismatchedDenoms; + +// the reason the coin is created here as opposed to different place in the codebase is that +// eventually we want to either publish the cosmwasm client separately or commit it to +// some other project, like cosmrs. Either way, in that case we can't really have +// a dependency on an internal type +#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq)] +pub struct Coin { + pub amount: u128, + pub denom: String, +} + +impl Coin { + pub fn new>(amount: u128, denom: S) -> Self { + Coin { + amount, + denom: denom.into(), + } + } + + pub fn try_add(&self, other: &Self) -> Result { + if self.denom != other.denom { + Err(MismatchedDenoms) + } else { + Ok(Coin { + amount: self.amount + other.amount, + denom: self.denom.clone(), + }) + } + } +} + +impl fmt::Display for Coin { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}{}", self.amount, self.denom) + } +} + +impl From for CosmosCoin { + fn from(coin: Coin) -> Self { + assert!( + coin.amount <= u64::MAX as u128, + "the coin amount is higher than the maximum supported by cosmrs" + ); + + CosmosCoin { + denom: coin + .denom + .parse() + .expect("the coin should have had a valid denom!"), + amount: (coin.amount as u64).into(), + } + } +} + +impl From for Coin { + fn from(coin: CosmosCoin) -> Self { + Coin { + amount: coin + .amount + .to_string() + .parse() + .expect("somehow failed to parse string representation of u64"), + denom: coin.denom.to_string(), + } + } +} + +impl From for CosmWasmCoin { + fn from(coin: Coin) -> Self { + CosmWasmCoin::new(coin.amount, coin.denom) + } +} + +impl From for Coin { + fn from(coin: CosmWasmCoin) -> Self { + Coin { + amount: coin.amount.u128(), + denom: coin.denom, + } + } +} + +pub trait CoinConverter { + type Target; + + fn convert_coin(&self) -> Self::Target; +} + +impl CoinConverter for CosmosCoin { + type Target = CosmWasmCoin; + + fn convert_coin(&self) -> Self::Target { + CosmWasmCoin::new( + self.amount + .to_string() + .parse() + .expect("cosmos coin had an invalid amount assigned"), + self.denom.to_string(), + ) + } +} + +impl CoinConverter for CosmWasmCoin { + type Target = CosmosCoin; + + fn convert_coin(&self) -> Self::Target { + assert!( + self.amount.u128() <= u64::MAX as u128, + "the coin amount is higher than the maximum supported by cosmrs" + ); + + CosmosCoin { + denom: self + .denom + .parse() + .expect("cosmwasm coin had an invalid amount assigned"), + amount: (self.amount.u128() as u64).into(), + } + } +} diff --git a/common/client-libs/validator-client/src/nymd/cosmwasm_client/client.rs b/common/client-libs/validator-client/src/nymd/cosmwasm_client/client.rs index 594092bc86..08a3ce22a2 100644 --- a/common/client-libs/validator-client/src/nymd/cosmwasm_client/client.rs +++ b/common/client-libs/validator-client/src/nymd/cosmwasm_client/client.rs @@ -1,6 +1,7 @@ // Copyright 2021 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 +use crate::nymd::coin::Coin; use crate::nymd::cosmwasm_client::helpers::{create_pagination, next_page_key}; use crate::nymd::cosmwasm_client::types::{ Account, Code, CodeDetails, Contract, ContractCodeHistoryEntry, ContractCodeId, @@ -25,8 +26,7 @@ use cosmrs::rpc::{self, HttpClient, Order}; use cosmrs::tendermint::abci::Code as AbciCode; use cosmrs::tendermint::abci::Transaction; use cosmrs::tendermint::{abci, block, chain}; -use cosmrs::{tx, AccountId, Coin, Denom, Tx}; -use cosmwasm_std::Coin as CosmWasmCoin; +use cosmrs::{tx, AccountId, Coin as CosmosCoin, Denom, Tx}; use prost::Message; use serde::{Deserialize, Serialize}; use std::convert::{TryFrom, TryInto}; @@ -135,7 +135,7 @@ pub trait CosmWasmClient: rpc::Client { .await?; res.balance - .map(TryFrom::try_from) + .map(|proto| CosmosCoin::try_from(proto).map(Into::into)) .transpose() .map_err(|_| NymdError::SerializationError("Coin".to_owned())) } @@ -166,16 +166,12 @@ pub trait CosmWasmClient: rpc::Client { raw_balances .into_iter() - .map(TryFrom::try_from) + .map(|proto| CosmosCoin::try_from(proto).map(Into::into)) .collect::>() .map_err(|_| NymdError::SerializationError("Coins".to_owned())) } - // this is annoyingly and inconsistently returning `Vec` rather than - // Vec, since cosmrs::Coin can't deal with IBC denoms. - // Presumably after https://github.com/cosmos/cosmos-rust/issues/173 is resolved, - // the code could be adjusted - async fn get_total_supply(&self) -> Result, NymdError> { + async fn get_total_supply(&self) -> Result, NymdError> { let path = Some("/cosmos.bank.v1beta1.Query/TotalSupply".parse().unwrap()); let mut supply = Vec::new(); @@ -198,12 +194,7 @@ pub trait CosmWasmClient: rpc::Client { supply .into_iter() - .map(|coin| { - coin.amount.parse().map(|amount| CosmWasmCoin { - denom: coin.denom, - amount, - }) - }) + .map(|proto| CosmosCoin::try_from(proto).map(Into::into)) .collect::>() .map_err(|_| NymdError::SerializationError("Coins".to_owned())) } diff --git a/common/client-libs/validator-client/src/nymd/cosmwasm_client/signing_client.rs b/common/client-libs/validator-client/src/nymd/cosmwasm_client/signing_client.rs index 58e10c8655..1f690d6812 100644 --- a/common/client-libs/validator-client/src/nymd/cosmwasm_client/signing_client.rs +++ b/common/client-libs/validator-client/src/nymd/cosmwasm_client/signing_client.rs @@ -8,7 +8,7 @@ use crate::nymd::cosmwasm_client::types::*; use crate::nymd::error::NymdError; use crate::nymd::fee::{Fee, DEFAULT_SIMULATED_GAS_MULTIPLIER}; use crate::nymd::wallet::DirectSecp256k1HdWallet; -use crate::nymd::{GasPrice, TxResponse}; +use crate::nymd::{Coin, GasPrice, TxResponse}; use async_trait::async_trait; use cosmrs::bank::MsgSend; use cosmrs::distribution::MsgWithdrawDelegatorReward; @@ -17,7 +17,7 @@ use cosmrs::rpc::endpoint::broadcast; use cosmrs::rpc::{Error as TendermintRpcError, HttpClient, HttpClientUrl, SimpleRequest}; use cosmrs::staking::{MsgDelegate, MsgUndelegate}; use cosmrs::tx::{self, Msg, SignDoc, SignerInfo}; -use cosmrs::{cosmwasm, rpc, AccountId, Any, Coin, Tx}; +use cosmrs::{cosmwasm, rpc, AccountId, Any, Tx}; use log::debug; use serde::Serialize; use sha2::Digest; @@ -310,7 +310,7 @@ pub trait SigningCosmWasmClient: CosmWasmClient { sender: sender_address.clone(), contract: contract_address.clone(), msg: serde_json::to_vec(msg)?, - funds, + funds: funds.into_iter().map(Into::into).collect(), } .to_any() .map_err(|_| NymdError::SerializationError("MsgExecuteContract".to_owned()))?; @@ -349,7 +349,7 @@ pub trait SigningCosmWasmClient: CosmWasmClient { sender: sender_address.clone(), contract: contract_address.clone(), msg: serde_json::to_vec(&msg)?, - funds, + funds: funds.into_iter().map(Into::into).collect(), } .to_any() .map_err(|_| NymdError::SerializationError("MsgExecuteContract".to_owned())) @@ -382,7 +382,7 @@ pub trait SigningCosmWasmClient: CosmWasmClient { let send_msg = MsgSend { from_address: sender_address.clone(), to_address: recipient_address.clone(), - amount, + amount: amount.into_iter().map(Into::into).collect(), } .to_any() .map_err(|_| NymdError::SerializationError("MsgSend".to_owned()))?; @@ -408,7 +408,7 @@ pub trait SigningCosmWasmClient: CosmWasmClient { MsgSend { from_address: sender_address.clone(), to_address, - amount, + amount: amount.into_iter().map(Into::into).collect(), } .to_any() .map_err(|_| NymdError::SerializationError("MsgExecuteContract".to_owned())) @@ -431,7 +431,7 @@ pub trait SigningCosmWasmClient: CosmWasmClient { let delegate_msg = MsgDelegate { delegator_address: delegator_address.to_owned(), validator_address: validator_address.to_owned(), - amount, + amount: amount.into(), } .to_any() .map_err(|_| NymdError::SerializationError("MsgDelegate".to_owned()))?; @@ -452,7 +452,7 @@ pub trait SigningCosmWasmClient: CosmWasmClient { let undelegate_msg = MsgUndelegate { delegator_address: delegator_address.to_owned(), validator_address: validator_address.to_owned(), - amount, + amount: amount.into(), } .to_any() .map_err(|_| NymdError::SerializationError("MsgUndelegate".to_owned()))?; diff --git a/common/client-libs/validator-client/src/nymd/cosmwasm_client/types.rs b/common/client-libs/validator-client/src/nymd/cosmwasm_client/types.rs index 5d3994bd15..3c28d8991f 100644 --- a/common/client-libs/validator-client/src/nymd/cosmwasm_client/types.rs +++ b/common/client-libs/validator-client/src/nymd/cosmwasm_client/types.rs @@ -28,7 +28,7 @@ use cosmrs::proto::cosmwasm::wasm::v1::{ use cosmrs::tendermint::abci::Data; use cosmrs::tendermint::{abci, chain}; use cosmrs::tx::{AccountNumber, Gas, SequenceNumber}; -use cosmrs::{tx, AccountId, Any, Coin}; +use cosmrs::{tx, AccountId, Any, Coin as CosmosCoin}; use prost::Message; use serde::Serialize; use std::convert::{TryFrom, TryInto}; @@ -107,9 +107,9 @@ impl TryFrom for ModuleAccount { #[derive(Debug)] pub struct BaseVestingAccount { pub base_account: Option, - pub original_vesting: Vec, - pub delegated_free: Vec, - pub delegated_vesting: Vec, + pub original_vesting: Vec, + pub delegated_free: Vec, + pub delegated_vesting: Vec, pub end_time: i64, } @@ -184,7 +184,7 @@ impl TryFrom for DelayedVestingAccount { #[derive(Debug)] pub struct Period { pub length: i64, - pub amount: Vec, + pub amount: Vec, } impl TryFrom for Period { @@ -628,7 +628,7 @@ pub struct InstantiateOptions { /// created and before the instantiation message is executed by the contract. /// /// Only native tokens are supported. - pub funds: Vec, + pub funds: Vec, /// A bech32 encoded address of an admin account. /// Caution: an admin has the privilege to upgrade a contract. @@ -636,6 +636,15 @@ pub struct InstantiateOptions { pub admin: Option, } +impl InstantiateOptions { + pub fn new>(funds: Vec, admin: Option) -> Self { + InstantiateOptions { + funds: funds.into_iter().map(Into::into).collect(), + admin, + } + } +} + #[derive(Debug)] pub struct InstantiateResult { /// The address of the newly instantiated contract diff --git a/common/client-libs/validator-client/src/nymd/fee/gas_price.rs b/common/client-libs/validator-client/src/nymd/fee/gas_price.rs index e7e69a32a5..c79015ff22 100644 --- a/common/client-libs/validator-client/src/nymd/fee/gas_price.rs +++ b/common/client-libs/validator-client/src/nymd/fee/gas_price.rs @@ -4,7 +4,7 @@ use crate::nymd::error::NymdError; use config::defaults; use cosmrs::tx::Gas; -use cosmrs::{Coin, Denom}; +use cosmrs::Coin; use cosmwasm_std::{Decimal, Fraction, Uint128}; use std::ops::Mul; use std::str::FromStr; @@ -13,11 +13,12 @@ use std::str::FromStr; /// the smallest fee token unit, such as 0.012utoken. #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] pub struct GasPrice { - // I really hate the combination of cosmwasm Decimal with cosmos-sdk Denom, - // but cosmos-sdk's Decimal is too basic for our needs + // I really dislike the usage of cosmwasm Decimal, but I didn't feel like implementing + // our own maths subcrate just for the purposes of calculating gas requirements + // this should definitely be rectified later on pub amount: Decimal, - pub denom: Denom, + pub denom: String, } impl<'a> Mul for &'a GasPrice { @@ -44,7 +45,10 @@ impl<'a> Mul for &'a GasPrice { assert!(amount.u128() <= u64::MAX as u128); Coin { - denom: self.denom.clone(), + denom: self + .denom + .parse() + .expect("the gas price has been created with invalid denom"), amount: (amount.u128() as u64).into(), } } @@ -63,9 +67,7 @@ impl FromStr for GasPrice { .parse() .map_err(|_| NymdError::MalformedGasPrice)?; let possible_denom = s.chars().skip(amount_len).collect::(); - let denom = possible_denom - .parse() - .map_err(|_| NymdError::MalformedGasPrice)?; + let denom = possible_denom.trim().to_string(); Ok(GasPrice { amount, denom }) } @@ -106,7 +108,14 @@ mod tests { ); assert!(".25upunk".parse::().is_err()); - assert!("0.025 upunk".parse::().is_err()); + + assert_eq!( + "0.025upunk".parse::().unwrap(), + "0.025 upunk".parse().unwrap() + ); + + let gas: GasPrice = "0.025 upunk ".parse().unwrap(); + assert_eq!("upunk", gas.denom); } #[test] diff --git a/common/client-libs/validator-client/src/nymd/mod.rs b/common/client-libs/validator-client/src/nymd/mod.rs index 94a543dcb3..19d17f390a 100644 --- a/common/client-libs/validator-client/src/nymd/mod.rs +++ b/common/client-libs/validator-client/src/nymd/mod.rs @@ -9,10 +9,11 @@ use crate::nymd::cosmwasm_client::types::{ use crate::nymd::error::NymdError; use crate::nymd::fee::DEFAULT_SIMULATED_GAS_MULTIPLIER; use crate::nymd::wallet::DirectSecp256k1HdWallet; +use cosmrs::cosmwasm; use cosmrs::rpc::Error as TendermintRpcError; use cosmrs::rpc::HttpClientUrl; use cosmrs::tx::Msg; -use cosmwasm_std::{Coin, Uint128}; +use cosmwasm_std::Uint128; pub use fee::gas_price::GasPrice; use mixnet_contract_common::mixnode::DelegationEvent; use mixnet_contract_common::{ @@ -28,8 +29,8 @@ use std::convert::TryInto; pub use crate::nymd::cosmwasm_client::client::CosmWasmClient; pub use crate::nymd::cosmwasm_client::signing_client::SigningCosmWasmClient; pub use crate::nymd::fee::Fee; +pub use coin::Coin; pub use cosmrs::bank::MsgSend; -use cosmrs::cosmwasm; pub use cosmrs::rpc::endpoint::tx::Response as TxResponse; pub use cosmrs::rpc::endpoint::validators::Response as ValidatorResponse; pub use cosmrs::rpc::HttpClient as QueryNymdClient; @@ -43,9 +44,11 @@ pub use cosmrs::tendermint::Time as TendermintTime; pub use cosmrs::tx::{self, Gas}; pub use cosmrs::Coin as CosmosCoin; pub use cosmrs::{bip32, AccountId, Decimal, Denom}; +pub use cosmwasm_std::Coin as CosmWasmCoin; pub use signing_client::Client as SigningNymdClient; pub use traits::{VestingQueryClient, VestingSigningClient}; +pub mod coin; pub mod cosmwasm_client; pub mod error; pub mod fee; @@ -175,7 +178,7 @@ impl NymdClient { &self, contract_address: &AccountId, msg: &M, - funds: Vec, + funds: Vec, ) -> Result where C: SigningCosmWasmClient, @@ -185,7 +188,7 @@ impl NymdClient { sender: self.address().clone(), contract: contract_address.clone(), msg: serde_json::to_vec(msg)?, - funds, + funds: funds.into_iter().map(Into::into).collect(), }) } @@ -265,7 +268,7 @@ impl NymdClient { &self, address: &AccountId, denom: Denom, - ) -> Result, NymdError> + ) -> Result, NymdError> where C: CosmWasmClient + Sync, { @@ -640,7 +643,7 @@ impl NymdClient { pub async fn send( &self, recipient: &AccountId, - amount: Vec, + amount: Vec, memo: impl Into + Send + 'static, fee: Option, ) -> Result @@ -656,7 +659,7 @@ impl NymdClient { /// Send funds from one address to multiple others pub async fn send_multiple( &self, - msgs: Vec<(AccountId, Vec)>, + msgs: Vec<(AccountId, Vec)>, memo: impl Into + Send + 'static, fee: Option, ) -> Result @@ -675,7 +678,7 @@ impl NymdClient { msg: &M, fee: Fee, memo: impl Into + Send + 'static, - funds: Vec, + funds: Vec, ) -> Result where C: SigningCosmWasmClient + Sync, @@ -695,7 +698,7 @@ impl NymdClient { ) -> Result where C: SigningCosmWasmClient + Sync, - I: IntoIterator)> + Send, + I: IntoIterator)> + Send, M: Serialize, { self.client @@ -893,7 +896,7 @@ impl NymdClient { &req, fee, "Bonding mixnode from rust!", - vec![cosmwasm_coin_to_cosmos_coin(pledge)], + vec![pledge], ) .await } @@ -924,7 +927,7 @@ impl NymdClient { &req, fee, "Bonding mixnode on behalf from rust!", - vec![cosmwasm_coin_to_cosmos_coin(pledge)], + vec![pledge], ) .await } @@ -940,7 +943,7 @@ impl NymdClient { { let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); - let reqs: Vec<(ExecuteMsg, Vec)> = mixnode_bonds_with_sigs + let reqs: Vec<(ExecuteMsg, Vec)> = mixnode_bonds_with_sigs .into_iter() .map(|(bond, owner_signature)| { ( @@ -949,7 +952,7 @@ impl NymdClient { owner: bond.owner.to_string(), owner_signature, }, - vec![cosmwasm_coin_to_cosmos_coin(bond.pledge_amount)], + vec![bond.pledge_amount.into()], ) }) .collect(); @@ -980,7 +983,7 @@ impl NymdClient { &req, fee, "Unbonding mixnode from rust!", - Vec::new(), + vec![], ) .await } @@ -1004,7 +1007,7 @@ impl NymdClient { &req, fee, "Unbonding mixnode on behalf from rust!", - Vec::new(), + vec![], ) .await } @@ -1030,7 +1033,7 @@ impl NymdClient { &req, fee, "Updating mixnode configuration from rust!", - Vec::new(), + vec![], ) .await } @@ -1039,7 +1042,7 @@ impl NymdClient { pub async fn delegate_to_mixnode( &self, mix_identity: &str, - amount: &Coin, + amount: Coin, fee: Option, ) -> Result where @@ -1057,7 +1060,7 @@ impl NymdClient { &req, fee, "Delegating to mixnode from rust!", - vec![cosmwasm_coin_ptr_to_cosmos_coin(amount)], + vec![amount], ) .await } @@ -1068,7 +1071,7 @@ impl NymdClient { &self, mix_identity: &str, delegate: &str, - amount: &Coin, + amount: Coin, fee: Option, ) -> Result where @@ -1087,7 +1090,7 @@ impl NymdClient { &req, fee, "Delegating to mixnode on behalf from rust!", - vec![cosmwasm_coin_ptr_to_cosmos_coin(amount)], + vec![amount], ) .await } @@ -1103,7 +1106,7 @@ impl NymdClient { { let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); - let reqs: Vec<(ExecuteMsg, Vec)> = mixnode_delegations + let reqs: Vec<(ExecuteMsg, Vec)> = mixnode_delegations .into_iter() .map(|delegation| { ( @@ -1111,7 +1114,7 @@ impl NymdClient { mix_identity: delegation.node_identity(), delegate: delegation.owner().to_string(), }, - vec![cosmwasm_coin_to_cosmos_coin(delegation.amount().clone())], + vec![delegation.amount().clone().into()], ) }) .collect(); @@ -1148,7 +1151,7 @@ impl NymdClient { &req, fee, "Removing mixnode delegation from rust!", - Vec::new(), + vec![], ) .await } @@ -1176,7 +1179,7 @@ impl NymdClient { &req, fee, "Removing mixnode delegation on behalf from rust!", - Vec::new(), + vec![], ) .await } @@ -1205,7 +1208,7 @@ impl NymdClient { &req, fee, "Bonding gateway from rust!", - vec![cosmwasm_coin_to_cosmos_coin(pledge)], + vec![pledge], ) .await } @@ -1236,7 +1239,7 @@ impl NymdClient { &req, fee, "Bonding gateway on behalf from rust!", - vec![cosmwasm_coin_to_cosmos_coin(pledge)], + vec![pledge], ) .await } @@ -1252,7 +1255,7 @@ impl NymdClient { { let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); - let reqs: Vec<(ExecuteMsg, Vec)> = gateway_bonds_with_sigs + let reqs: Vec<(ExecuteMsg, Vec)> = gateway_bonds_with_sigs .into_iter() .map(|(bond, owner_signature)| { ( @@ -1261,7 +1264,7 @@ impl NymdClient { owner: bond.owner.to_string(), owner_signature, }, - vec![cosmwasm_coin_to_cosmos_coin(bond.pledge_amount)], + vec![bond.pledge_amount.into()], ) }) .collect(); @@ -1292,7 +1295,7 @@ impl NymdClient { &req, fee, "Unbonding gateway from rust!", - Vec::new(), + vec![], ) .await } @@ -1317,7 +1320,7 @@ impl NymdClient { &req, fee, "Unbonding gateway on behalf from rust!", - Vec::new(), + vec![], ) .await } @@ -1340,7 +1343,7 @@ impl NymdClient { &req, fee, "Updating contract state from rust!", - Vec::new(), + vec![], ) .await } @@ -1359,7 +1362,7 @@ impl NymdClient { &req, fee, "Advance current epoch", - Vec::new(), + vec![], ) .await } @@ -1378,7 +1381,7 @@ impl NymdClient { &req, fee, "Reconciling delegation events", - Vec::new(), + vec![], ) .await } @@ -1397,7 +1400,7 @@ impl NymdClient { &req, fee, "Snapshotting mixnodes", - Vec::new(), + vec![], ) .await } @@ -1424,24 +1427,8 @@ impl NymdClient { &req, fee, "Writing rewarded set", - Vec::new(), + vec![], ) .await } } - -fn cosmwasm_coin_to_cosmos_coin(coin: Coin) -> CosmosCoin { - CosmosCoin { - denom: coin.denom.parse().unwrap(), - // this might be a bit iffy, cosmwasm coin stores value as u128, while cosmos does it as u64 - amount: (coin.amount.u128() as u64).into(), - } -} - -fn cosmwasm_coin_ptr_to_cosmos_coin(coin: &Coin) -> CosmosCoin { - CosmosCoin { - denom: coin.denom.parse().unwrap(), - // this might be a bit iffy, cosmwasm coin stores value as u128, while cosmos does it as u64 - amount: (coin.amount.u128() as u64).into(), - } -} diff --git a/common/client-libs/validator-client/src/nymd/traits/vesting_query_client.rs b/common/client-libs/validator-client/src/nymd/traits/vesting_query_client.rs index 3101850b7c..a020dea2ea 100644 --- a/common/client-libs/validator-client/src/nymd/traits/vesting_query_client.rs +++ b/common/client-libs/validator-client/src/nymd/traits/vesting_query_client.rs @@ -1,11 +1,12 @@ // Copyright 2021 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 +use crate::nymd::coin::Coin; pub use crate::nymd::cosmwasm_client::client::CosmWasmClient; use crate::nymd::error::NymdError; use crate::nymd::NymdClient; use async_trait::async_trait; -use cosmwasm_std::{Coin, Timestamp}; +use cosmwasm_std::{Coin as CosmWasmCoin, Timestamp}; use vesting_contract::vesting::Account; use vesting_contract_common::{ messages::QueryMsg as VestingQueryMsg, OriginalVestingResponse, Period, PledgeData, @@ -83,8 +84,9 @@ impl VestingQueryClient for NymdClient { block_time, }; self.client - .query_contract_smart(self.vesting_contract_address()?, &request) + .query_contract_smart::<_, CosmWasmCoin>(self.vesting_contract_address()?, &request) .await + .map(Into::into) } async fn spendable_coins( @@ -97,8 +99,9 @@ impl VestingQueryClient for NymdClient { block_time, }; self.client - .query_contract_smart(self.vesting_contract_address()?, &request) + .query_contract_smart::<_, CosmWasmCoin>(self.vesting_contract_address()?, &request) .await + .map(Into::into) } async fn vested_coins( &self, @@ -110,8 +113,9 @@ impl VestingQueryClient for NymdClient { block_time, }; self.client - .query_contract_smart(self.vesting_contract_address()?, &request) + .query_contract_smart::<_, CosmWasmCoin>(self.vesting_contract_address()?, &request) .await + .map(Into::into) } async fn vesting_coins( &self, @@ -123,8 +127,9 @@ impl VestingQueryClient for NymdClient { block_time, }; self.client - .query_contract_smart(self.vesting_contract_address()?, &request) + .query_contract_smart::<_, CosmWasmCoin>(self.vesting_contract_address()?, &request) .await + .map(Into::into) } async fn vesting_start_time( @@ -173,8 +178,9 @@ impl VestingQueryClient for NymdClient { block_time, }; self.client - .query_contract_smart(self.vesting_contract_address()?, &request) + .query_contract_smart::<_, CosmWasmCoin>(self.vesting_contract_address()?, &request) .await + .map(Into::into) } async fn delegated_vesting( @@ -187,8 +193,9 @@ impl VestingQueryClient for NymdClient { block_time, }; self.client - .query_contract_smart(self.vesting_contract_address()?, &request) + .query_contract_smart::<_, CosmWasmCoin>(self.vesting_contract_address()?, &request) .await + .map(Into::into) } async fn get_account(&self, address: &str) -> Result { diff --git a/common/client-libs/validator-client/src/nymd/traits/vesting_signing_client.rs b/common/client-libs/validator-client/src/nymd/traits/vesting_signing_client.rs index 3fcf05a218..163b6957db 100644 --- a/common/client-libs/validator-client/src/nymd/traits/vesting_signing_client.rs +++ b/common/client-libs/validator-client/src/nymd/traits/vesting_signing_client.rs @@ -4,9 +4,8 @@ pub use crate::nymd::cosmwasm_client::signing_client::SigningCosmWasmClient; use crate::nymd::cosmwasm_client::types::ExecuteResult; use crate::nymd::error::NymdError; -use crate::nymd::{cosmwasm_coin_to_cosmos_coin, Fee, NymdClient}; +use crate::nymd::{Coin, Fee, NymdClient}; use async_trait::async_trait; -use cosmwasm_std::Coin; use mixnet_contract_common::{Gateway, IdentityKey, IdentityKeyRef, MixNode}; use vesting_contract_common::messages::{ExecuteMsg as VestingExecuteMsg, VestingSpecification}; @@ -96,7 +95,7 @@ pub trait VestingSigningClient { async fn vesting_delegate_to_mixnode<'a>( &self, mix_identity: IdentityKeyRef<'a>, - amount: &Coin, + amount: Coin, fee: Option, ) -> Result; @@ -171,7 +170,7 @@ impl VestingSigningClient for NymdClient let req = VestingExecuteMsg::BondGateway { gateway, owner_signature: owner_signature.to_string(), - amount: pledge, + amount: pledge.into(), }; self.client .execute( @@ -209,7 +208,7 @@ impl VestingSigningClient for NymdClient let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); let req = VestingExecuteMsg::TrackUnbondGateway { owner: owner.to_string(), - amount, + amount: amount.into(), }; self.client .execute( @@ -234,7 +233,7 @@ impl VestingSigningClient for NymdClient let req = VestingExecuteMsg::BondMixnode { mix_node, owner_signature: owner_signature.to_string(), - amount: pledge, + amount: pledge.into(), }; self.client .execute( @@ -272,7 +271,7 @@ impl VestingSigningClient for NymdClient let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); let req = VestingExecuteMsg::TrackUnbondMixnode { owner: owner.to_string(), - amount, + amount: amount.into(), }; self.client .execute( @@ -291,7 +290,9 @@ impl VestingSigningClient for NymdClient fee: Option, ) -> Result { let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); - let req = VestingExecuteMsg::WithdrawVestedCoins { amount }; + let req = VestingExecuteMsg::WithdrawVestedCoins { + amount: amount.into(), + }; self.client .execute( self.address(), @@ -314,7 +315,7 @@ impl VestingSigningClient for NymdClient let req = VestingExecuteMsg::TrackUndelegation { owner: address.to_string(), mix_identity, - amount, + amount: amount.into(), }; self.client .execute( @@ -330,13 +331,13 @@ impl VestingSigningClient for NymdClient async fn vesting_delegate_to_mixnode<'a>( &self, mix_identity: IdentityKeyRef<'a>, - amount: &Coin, + amount: Coin, fee: Option, ) -> Result { let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); let req = VestingExecuteMsg::DelegateToMixnode { mix_identity: mix_identity.into(), - amount: amount.clone(), + amount: amount.into(), }; self.client .execute( @@ -392,7 +393,7 @@ impl VestingSigningClient for NymdClient &req, fee, "VestingContract::CreatePeriodicVestingAccount", - vec![cosmwasm_coin_to_cosmos_coin(amount)], + vec![amount], ) .await } diff --git a/nym-wallet/src-tauri/src/coin.rs b/nym-wallet/src-tauri/src/coin.rs index 83ed92c807..1903e869f9 100644 --- a/nym-wallet/src-tauri/src/coin.rs +++ b/nym-wallet/src-tauri/src/coin.rs @@ -2,16 +2,16 @@ use crate::error::BackendError; use crate::network::Network; -use cosmwasm_std::Coin as CosmWasmCoin; -use cosmwasm_std::Uint128; use serde::{Deserialize, Serialize}; use std::convert::TryFrom; use std::ops::{Add, Sub}; use std::str::FromStr; use strum::IntoEnumIterator; use validator_client::nymd::CosmosCoin; -use validator_client::nymd::Decimal; use validator_client::nymd::Denom as CosmosDenom; +use validator_client::nymd::{Coin as BackendCoin, CosmWasmCoin}; + +const MINOR_IN_MAJOR: f64 = 1_000_000.; #[cfg_attr(test, derive(ts_rs::TS))] #[cfg_attr(test, ts(export, export, export_to = "../src/types/rust/denom.ts"))] @@ -21,8 +21,6 @@ pub enum Denom { Minor, } -const MINOR_IN_MAJOR: f64 = 1_000_000.; - impl FromStr for Denom { type Err = BackendError; @@ -30,9 +28,9 @@ impl FromStr for Denom { let s = s.to_lowercase(); for network in Network::iter() { let denom = network.denom(); - if s == denom.as_ref().to_lowercase() || s == "minor" { + if s == denom.to_lowercase() || s == "minor" { return Ok(Denom::Minor); - } else if s == denom.as_ref()[1..].to_lowercase() || s == "major" { + } else if s == denom[1..].to_lowercase() || s == "major" { return Ok(Denom::Major); } } @@ -64,8 +62,8 @@ impl Add for Coin { let denom = self.denom.clone(); let lhs = self.to_minor(); let rhs = rhs.to_minor(); - let lhs_amount = lhs.amount.parse::().unwrap(); - let rhs_amount = rhs.amount.parse::().unwrap(); + let lhs_amount = lhs.amount.parse::().unwrap(); + let rhs_amount = rhs.amount.parse::().unwrap(); let amount = lhs_amount + rhs_amount; let coin = Coin { amount: amount.to_string(), @@ -86,8 +84,8 @@ impl Sub for Coin { let denom = self.denom.clone(); let lhs = self.to_minor(); let rhs = rhs.to_minor(); - let lhs_amount = lhs.amount.parse::().unwrap(); - let rhs_amount = rhs.amount.parse::().unwrap(); + let lhs_amount = lhs.amount.parse::().unwrap(); + let rhs_amount = rhs.amount.parse::().unwrap(); let amount = lhs_amount - rhs_amount; let coin = Coin { amount: amount.to_string(), @@ -154,10 +152,10 @@ impl Coin { } // Helper function that returns the local denom in terms of the specified network denom. - fn denom_as_string(&self, network_denom: &CosmosDenom) -> Result { + fn denom_as_string(&self, network_denom: &str) -> Result { // Currently there is the widespread assumption that network denomination is always in // `Denom::Minor`, and starts with 'u'. - let network_denom = network_denom.to_string(); + let network_denom = network_denom.to_owned(); if !network_denom.starts_with('u') { return Err(BackendError::InvalidNetworkDenom(network_denom)); } @@ -168,24 +166,20 @@ impl Coin { }) } - pub fn into_cosmos_coin(self, network_denom: &CosmosDenom) -> Result { - match Decimal::from_str(&self.amount) { - Ok(amount) => Ok(CosmosCoin { - amount, - denom: CosmosDenom::from_str(&self.denom_as_string(network_denom)?)?, - }), - Err(e) => Err(e.into()), - } + pub fn into_backend_coin(self, network_denom: &str) -> Result { + Ok(BackendCoin::new( + self.amount.parse()?, + self.denom_as_string(network_denom)?, + )) } +} - pub fn into_cosmwasm_coin( - self, - network_denom: &CosmosDenom, - ) -> Result { - Ok(CosmWasmCoin { - denom: self.denom_as_string(network_denom)?, - amount: Uint128::try_from(self.amount.as_str())?, - }) +impl From for Coin { + fn from(c: BackendCoin) -> Self { + Coin { + amount: c.amount.to_string(), + denom: Denom::from_str(c.denom.as_ref()).unwrap(), + } } } @@ -211,7 +205,6 @@ impl From for Coin { mod test { use super::*; use crate::error::BackendError; - use cosmwasm_std::Coin as CosmWasmCoin; use serde_json::json; use std::convert::TryFrom; use std::str::FromStr; @@ -264,10 +257,10 @@ mod test { #[test] fn network_denom_is_assumed_to_be_in_minor_denom() { - let network_denom = CosmosDenom::from_str("nym").unwrap(); + let network_denom = "nym"; assert!(matches!( Coin::minor("42") - .denom_as_string(&network_denom) + .denom_as_string(network_denom) .unwrap_err(), BackendError::InvalidNetworkDenom { .. } )); @@ -275,51 +268,33 @@ mod test { #[test] fn local_denom_to_interpreted_using_network_denom() { - let network_denom = CosmosDenom::from_str("unym").unwrap(); + let network_denom = "unym"; assert_eq!( - Coin::minor("42").denom_as_string(&network_denom).unwrap(), + Coin::minor("42").denom_as_string(network_denom).unwrap(), "unym", ); assert_eq!( - Coin::major("42").denom_as_string(&network_denom).unwrap(), + Coin::major("42").denom_as_string(network_denom).unwrap(), "nym", ); } #[test] fn coin_to_coin_minor() { - let network_denom = CosmosDenom::from_str("unym").unwrap(); + let network_denom = "unym"; let coin = Coin::minor("42"); - let cosmoswasm_coin = coin.clone().into_cosmwasm_coin(&network_denom).unwrap(); - assert_eq!(cosmoswasm_coin, CosmWasmCoin::new(42, "unym"),); - - let cosmos_coin = coin.into_cosmos_coin(&network_denom).unwrap(); - assert_eq!( - cosmos_coin, - CosmosCoin { - denom: CosmosDenom::from_str("unym").unwrap(), - amount: Decimal::from_str("42").unwrap(), - }, - ); + let backend_coin = coin.clone().into_backend_coin(&network_denom).unwrap(); + assert_eq!(backend_coin, BackendCoin::new(42, "unym")); } #[test] fn coin_to_coin_major() { - let network_denom = CosmosDenom::from_str("unym").unwrap(); + let network_denom = "unym"; let coin = Coin::major("52"); - let cosmoswasm_coin = coin.clone().into_cosmwasm_coin(&network_denom).unwrap(); - assert_eq!(cosmoswasm_coin, CosmWasmCoin::new(52, "nym"),); - - let cosmos_coin = coin.into_cosmos_coin(&network_denom).unwrap(); - assert_eq!( - cosmos_coin, - CosmosCoin { - denom: CosmosDenom::from_str("nym").unwrap(), - amount: Decimal::from_str("52").unwrap(), - }, - ); + let backend_coin = coin.clone().into_backend_coin(network_denom).unwrap(); + assert_eq!(backend_coin, BackendCoin::new(52, "nym")); } fn amounts() -> Vec<&'static str> { @@ -346,74 +321,24 @@ mod test { } #[test] - fn coin_to_cosmoswasm() { - let network_denom = CosmosDenom::from_str("unym").unwrap(); + fn coin_to_backend() { + let network_denom = "unym"; for amount in amounts() { let coin = Coin::minor(amount); - let cosmoswasm_coin: CosmWasmCoin = coin.into_cosmwasm_coin(&network_denom).unwrap(); + let backend_coin = coin.into_backend_coin(network_denom).unwrap(); assert_eq!( - cosmoswasm_coin, - CosmWasmCoin::new(amount.parse::().unwrap(), "unym") - ); - assert_eq!( - Coin::try_from(cosmoswasm_coin).unwrap(), - Coin::minor(amount) + backend_coin, + BackendCoin::new(amount.parse::().unwrap(), "unym") ); + assert_eq!(Coin::try_from(backend_coin).unwrap(), Coin::minor(amount)); let coin = Coin::major(amount); - let cosmoswasm_coin: CosmWasmCoin = coin.into_cosmwasm_coin(&network_denom).unwrap(); + let backend_coin = coin.into_backend_coin(network_denom).unwrap(); assert_eq!( - cosmoswasm_coin, - CosmWasmCoin::new(amount.parse::().unwrap(), "nym") - ); - assert_eq!( - Coin::try_from(cosmoswasm_coin).unwrap(), - Coin::major(amount) + backend_coin, + BackendCoin::new(amount.parse::().unwrap(), "nym") ); + assert_eq!(Coin::try_from(backend_coin).unwrap(), Coin::major(amount)); } } - - #[test] - fn coin_to_cosmos() { - let network_denom = CosmosDenom::from_str("unym").unwrap(); - for amount in amounts() { - let coin = Coin::minor(amount); - let cosmos_coin: CosmosCoin = coin.into_cosmos_coin(&network_denom).unwrap(); - assert_eq!( - cosmos_coin, - CosmosCoin { - amount: Decimal::from_str(amount).unwrap(), - denom: CosmosDenom::from_str("unym").unwrap() - } - ); - assert_eq!(Coin::try_from(cosmos_coin).unwrap(), Coin::minor(amount)); - - let coin = Coin::major(amount); - let cosmos_coin: CosmosCoin = coin.into_cosmos_coin(&network_denom).unwrap(); - assert_eq!( - cosmos_coin, - CosmosCoin { - amount: Decimal::from_str(amount).unwrap(), - denom: CosmosDenom::from_str("nym").unwrap() - } - ); - assert_eq!(Coin::try_from(cosmos_coin).unwrap(), Coin::major(amount)); - } - } - - #[test] - fn test_add() { - assert_eq!(Coin::minor("1") + Coin::minor("1"), Coin::minor("2")); - assert_eq!(Coin::major("1") + Coin::major("1"), Coin::major("2")); - assert_eq!(Coin::minor("1") + Coin::major("1"), Coin::minor("1000001")); - assert_eq!(Coin::major("1") + Coin::minor("1"), Coin::major("1.000001")); - } - - #[test] - fn test_sub() { - assert_eq!(Coin::minor("1") - Coin::minor("1"), Coin::minor("0")); - assert_eq!(Coin::major("1") - Coin::major("1"), Coin::major("0")); - assert_eq!(Coin::minor("1") - Coin::major("1"), Coin::minor("-999999")); - assert_eq!(Coin::major("1") - Coin::minor("1"), Coin::major("0.999999")); - } } diff --git a/nym-wallet/src-tauri/src/error.rs b/nym-wallet/src-tauri/src/error.rs index 3f6181e008..e0fb1e565b 100644 --- a/nym-wallet/src-tauri/src/error.rs +++ b/nym-wallet/src-tauri/src/error.rs @@ -1,5 +1,6 @@ use serde::{Serialize, Serializer}; use std::io; +use std::num::ParseIntError; use thiserror::Error; use validator_client::validator_api::error::ValidatorAPIError; use validator_client::{nymd::error::NymdError, ValidatorClientError}; @@ -101,6 +102,8 @@ pub enum BackendError { WalletUnexpectedMultipleAccounts, #[error("Failed to derive address from mnemonic")] FailedToDeriveAddress, + #[error("{0}")] + ValueParseError(#[from] ParseIntError), } impl Serialize for BackendError { diff --git a/nym-wallet/src-tauri/src/network.rs b/nym-wallet/src-tauri/src/network.rs index eae5058519..9f0e21f990 100644 --- a/nym-wallet/src-tauri/src/network.rs +++ b/nym-wallet/src-tauri/src/network.rs @@ -1,14 +1,11 @@ // Copyright 2021 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 -use serde::{Deserialize, Serialize}; -use std::fmt; -use std::str::FromStr; -use strum::EnumIter; - use config::defaults::all::Network as ConfigNetwork; use config::defaults::{mainnet, qa, sandbox}; -use validator_client::nymd::Denom; +use serde::{Deserialize, Serialize}; +use std::fmt; +use strum::EnumIter; #[allow(clippy::upper_case_acronyms)] #[cfg_attr(test, derive(ts_rs::TS))] @@ -25,12 +22,12 @@ impl Network { self.to_string().to_lowercase() } - pub fn denom(&self) -> Denom { + pub fn denom(&self) -> &str { match self { // network defaults should be correctly formatted - Network::QA => Denom::from_str(qa::DENOM).unwrap(), - Network::SANDBOX => Denom::from_str(sandbox::DENOM).unwrap(), - Network::MAINNET => Denom::from_str(mainnet::DENOM).unwrap(), + Network::QA => qa::DENOM, + Network::SANDBOX => sandbox::DENOM, + Network::MAINNET => mainnet::DENOM, } } } diff --git a/nym-wallet/src-tauri/src/operations/mixnet/account.rs b/nym-wallet/src-tauri/src/operations/mixnet/account.rs index 3b3900872c..f48cffe515 100644 --- a/nym-wallet/src-tauri/src/operations/mixnet/account.rs +++ b/nym-wallet/src-tauri/src/operations/mixnet/account.rs @@ -14,7 +14,6 @@ use itertools::Itertools; use rand::seq::SliceRandom; use serde::{Deserialize, Serialize}; use std::collections::HashMap; -use std::convert::TryInto; use std::str::FromStr; use std::sync::Arc; use strum::IntoEnumIterator; @@ -81,19 +80,17 @@ pub async fn connect_with_mnemonic( pub async fn get_balance( state: tauri::State<'_, Arc>>, ) -> Result { - let denom = state.read().await.current_network().denom(); + let denom = state.read().await.current_network().denom().to_owned(); match nymd_client!(state) - .get_balance(nymd_client!(state).address(), denom.clone()) + .get_balance(nymd_client!(state).address(), denom.parse()?) .await { Ok(Some(coin)) => { - let coin = Coin::new( - &coin.amount.to_string(), - &Denom::from_str(&coin.denom.to_string())?, - ); + let coin = Coin::new(&coin.amount.to_string(), &Denom::from_str(&coin.denom)?); Ok(Balance { coin: coin.clone(), - printable_balance: format!("{} {}", coin.to_major().amount(), &denom.as_ref()[1..]), + // haha, that's so junky : ) + printable_balance: format!("{} {}", coin.to_major().amount(), &denom[1..]), }) } Ok(None) => Err(BackendError::NoBalance( @@ -138,7 +135,7 @@ pub async fn switch_network( Account::new( client.nymd.mixnet_contract_address()?.to_string(), client.nymd.address().to_string(), - denom.try_into()?, + denom.parse()?, ) }; @@ -221,7 +218,7 @@ async fn _connect_with_mnemonic( Some(client) => Ok(Account::new( client.nymd.mixnet_contract_address()?.to_string(), client.nymd.address().to_string(), - default_network.denom().try_into()?, + default_network.denom().parse()?, )), None => Err(BackendError::NetworkNotSupported( config::defaults::DEFAULT_NETWORK, diff --git a/nym-wallet/src-tauri/src/operations/mixnet/bond.rs b/nym-wallet/src-tauri/src/operations/mixnet/bond.rs index 938896e769..e940ff60ac 100644 --- a/nym-wallet/src-tauri/src/operations/mixnet/bond.rs +++ b/nym-wallet/src-tauri/src/operations/mixnet/bond.rs @@ -17,8 +17,7 @@ pub async fn bond_gateway( fee: Option, state: tauri::State<'_, Arc>>, ) -> Result<(), BackendError> { - let denom = state.read().await.current_network().denom(); - let pledge = pledge.into_cosmwasm_coin(&denom)?; + let pledge = pledge.into_backend_coin(state.read().await.current_network().denom())?; nymd_client!(state) .bond_gateway(gateway, owner_signature, pledge, fee) .await?; @@ -51,8 +50,7 @@ pub async fn bond_mixnode( fee: Option, state: tauri::State<'_, Arc>>, ) -> Result<(), BackendError> { - let denom = state.read().await.current_network().denom(); - let pledge = pledge.into_cosmwasm_coin(&denom)?; + let pledge = pledge.into_backend_coin(state.read().await.current_network().denom())?; nymd_client!(state) .bond_mixnode(mixnode, owner_signature, pledge, fee) .await?; diff --git a/nym-wallet/src-tauri/src/operations/mixnet/delegate.rs b/nym-wallet/src-tauri/src/operations/mixnet/delegate.rs index ebd4ebec54..c559b18e43 100644 --- a/nym-wallet/src-tauri/src/operations/mixnet/delegate.rs +++ b/nym-wallet/src-tauri/src/operations/mixnet/delegate.rs @@ -4,7 +4,7 @@ use crate::nymd_client; use crate::state::State; use crate::utils::DelegationEvent; use crate::utils::DelegationResult; -use cosmwasm_std::{Coin as CosmWasmCoin, Uint128}; +use cosmwasm_std::Uint128; use mixnet_contract_common::{IdentityKey, PagedDelegatorDelegationsResponse}; use std::sync::Arc; use tokio::sync::RwLock; @@ -29,10 +29,9 @@ pub async fn delegate_to_mixnode( fee: Option, state: tauri::State<'_, Arc>>, ) -> Result { - let denom = state.read().await.current_network().denom(); - let delegation: CosmWasmCoin = amount.into_cosmwasm_coin(&denom)?; + let delegation = amount.into_backend_coin(state.read().await.current_network().denom())?; nymd_client!(state) - .delegate_to_mixnode(identity, &delegation, fee) + .delegate_to_mixnode(identity, delegation.clone(), fee) .await?; Ok(DelegationResult::new( nymd_client!(state).address().as_ref(), diff --git a/nym-wallet/src-tauri/src/operations/mixnet/send.rs b/nym-wallet/src-tauri/src/operations/mixnet/send.rs index a50730ab5a..52a7258dfc 100644 --- a/nym-wallet/src-tauri/src/operations/mixnet/send.rs +++ b/nym-wallet/src-tauri/src/operations/mixnet/send.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; use std::str::FromStr; use std::sync::Arc; use tokio::sync::RwLock; -use validator_client::nymd::{AccountId, CosmosCoin, Fee, TxResponse}; +use validator_client::nymd::{AccountId, Fee, TxResponse}; #[cfg_attr(test, derive(ts_rs::TS))] #[cfg_attr(test, ts(export, export_to = "../src/types/rust/tauritxresult.ts"))] @@ -54,17 +54,16 @@ pub async fn send( state: tauri::State<'_, Arc>>, ) -> Result { let address = AccountId::from_str(address)?; - let network_denom = state.read().await.current_network().denom(); - let cosmos_amount: CosmosCoin = amount.clone().into_cosmos_coin(&network_denom)?; + let amount = amount.into_backend_coin(state.read().await.current_network().denom())?; let result = nymd_client!(state) - .send(&address, vec![cosmos_amount], memo, fee) + .send(&address, vec![amount.clone()], memo, fee) .await?; Ok(TauriTxResult::new( result, TransactionDetails { from_address: nymd_client!(state).address().to_string(), to_address: address.to_string(), - amount, + amount: amount.into(), }, )) } diff --git a/nym-wallet/src-tauri/src/operations/simulate/cosmos.rs b/nym-wallet/src-tauri/src/operations/simulate/cosmos.rs index e2647c69ea..4f2078713a 100644 --- a/nym-wallet/src-tauri/src/operations/simulate/cosmos.rs +++ b/nym-wallet/src-tauri/src/operations/simulate/cosmos.rs @@ -19,8 +19,7 @@ pub async fn simulate_send( let guard = state.read().await; let to_address = AccountId::from_str(address)?; - let network_denom = guard.current_network().denom(); - let amount = vec![amount.clone().into_cosmos_coin(&network_denom)?]; + let amount = amount.into_backend_coin(guard.current_network().denom())?; let client = guard.current_client()?; let from_address = client.nymd.address().clone(); @@ -30,7 +29,7 @@ pub async fn simulate_send( let msg = MsgSend { from_address, to_address, - amount, + amount: vec![amount.into()], }; let result = client.nymd.simulate(vec![msg]).await?; diff --git a/nym-wallet/src-tauri/src/operations/simulate/mixnet.rs b/nym-wallet/src-tauri/src/operations/simulate/mixnet.rs index 014e003cbc..37d48859aa 100644 --- a/nym-wallet/src-tauri/src/operations/simulate/mixnet.rs +++ b/nym-wallet/src-tauri/src/operations/simulate/mixnet.rs @@ -17,8 +17,7 @@ pub async fn simulate_bond_gateway( state: tauri::State<'_, Arc>>, ) -> Result { let guard = state.read().await; - let network_denom = guard.current_network().denom(); - let pledge = pledge.into_cosmos_coin(&network_denom)?; + let pledge = pledge.into_backend_coin(guard.current_network().denom())?; let client = guard.current_client()?; let mixnet_contract = client.nymd.mixnet_contract_address()?; @@ -66,8 +65,7 @@ pub async fn simulate_bond_mixnode( state: tauri::State<'_, Arc>>, ) -> Result { let guard = state.read().await; - let network_denom = guard.current_network().denom(); - let pledge = pledge.into_cosmos_coin(&network_denom)?; + let pledge = pledge.into_backend_coin(guard.current_network().denom())?; let client = guard.current_client()?; let mixnet_contract = client.nymd.mixnet_contract_address()?; @@ -136,8 +134,7 @@ pub async fn simulate_delegate_to_mixnode( state: tauri::State<'_, Arc>>, ) -> Result { let guard = state.read().await; - let network_denom = guard.current_network().denom(); - let delegation = amount.into_cosmos_coin(&network_denom)?; + let delegation = amount.into_backend_coin(guard.current_network().denom())?; let client = guard.current_client()?; let mixnet_contract = client.nymd.mixnet_contract_address()?; diff --git a/nym-wallet/src-tauri/src/operations/simulate/vesting.rs b/nym-wallet/src-tauri/src/operations/simulate/vesting.rs index d424777496..c72b7be820 100644 --- a/nym-wallet/src-tauri/src/operations/simulate/vesting.rs +++ b/nym-wallet/src-tauri/src/operations/simulate/vesting.rs @@ -18,8 +18,7 @@ pub async fn simulate_vesting_bond_gateway( state: tauri::State<'_, Arc>>, ) -> Result { let guard = state.read().await; - let network_denom = guard.current_network().denom(); - let pledge = pledge.into_cosmwasm_coin(&network_denom)?; + let pledge = pledge.into_backend_coin(guard.current_network().denom())?; let client = guard.current_client()?; let vesting_contract = client.nymd.vesting_contract_address()?; @@ -30,7 +29,7 @@ pub async fn simulate_vesting_bond_gateway( &ExecuteMsg::BondGateway { gateway, owner_signature, - amount: pledge, + amount: pledge.into(), }, vec![], )?; @@ -67,8 +66,7 @@ pub async fn simulate_vesting_bond_mixnode( state: tauri::State<'_, Arc>>, ) -> Result { let guard = state.read().await; - let network_denom = guard.current_network().denom(); - let pledge = pledge.into_cosmwasm_coin(&network_denom)?; + let pledge = pledge.into_backend_coin(guard.current_network().denom())?; let client = guard.current_client()?; let vesting_contract = client.nymd.vesting_contract_address()?; @@ -79,7 +77,7 @@ pub async fn simulate_vesting_bond_mixnode( &ExecuteMsg::BondMixnode { mix_node: mixnode, owner_signature, - amount: pledge, + amount: pledge.into(), }, vec![], )?; @@ -137,8 +135,7 @@ pub async fn simulate_withdraw_vested_coins( state: tauri::State<'_, Arc>>, ) -> Result { let guard = state.read().await; - let network_denom = guard.current_network().denom(); - let amount = amount.into_cosmwasm_coin(&network_denom)?; + let amount = amount.into_backend_coin(guard.current_network().denom())?; let client = guard.current_client()?; let vesting_contract = client.nymd.vesting_contract_address()?; @@ -146,7 +143,9 @@ pub async fn simulate_withdraw_vested_coins( let msg = client.nymd.wrap_contract_execute_message( vesting_contract, - &ExecuteMsg::WithdrawVestedCoins { amount }, + &ExecuteMsg::WithdrawVestedCoins { + amount: amount.into(), + }, vec![], )?; diff --git a/nym-wallet/src-tauri/src/operations/vesting/bond.rs b/nym-wallet/src-tauri/src/operations/vesting/bond.rs index 8a5b103cea..d06842f067 100644 --- a/nym-wallet/src-tauri/src/operations/vesting/bond.rs +++ b/nym-wallet/src-tauri/src/operations/vesting/bond.rs @@ -15,8 +15,7 @@ pub async fn vesting_bond_gateway( fee: Option, state: tauri::State<'_, Arc>>, ) -> Result<(), BackendError> { - let denom = state.read().await.current_network().denom(); - let pledge = pledge.into_cosmwasm_coin(&denom)?; + let pledge = pledge.into_backend_coin(state.read().await.current_network().denom())?; nymd_client!(state) .vesting_bond_gateway(gateway, &owner_signature, pledge, fee) .await?; @@ -49,8 +48,7 @@ pub async fn vesting_bond_mixnode( fee: Option, state: tauri::State<'_, Arc>>, ) -> Result<(), BackendError> { - let denom = state.read().await.current_network().denom(); - let pledge = pledge.into_cosmwasm_coin(&denom)?; + let pledge = pledge.into_backend_coin(state.read().await.current_network().denom())?; nymd_client!(state) .vesting_bond_mixnode(mixnode, &owner_signature, pledge, fee) .await?; @@ -63,8 +61,7 @@ pub async fn withdraw_vested_coins( fee: Option, state: tauri::State<'_, Arc>>, ) -> Result<(), BackendError> { - let denom = state.read().await.current_network().denom(); - let amount = amount.into_cosmwasm_coin(&denom)?; + let amount = amount.into_backend_coin(state.read().await.current_network().denom())?; nymd_client!(state) .withdraw_vested_coins(amount, fee) .await?; diff --git a/nym-wallet/src-tauri/src/operations/vesting/delegate.rs b/nym-wallet/src-tauri/src/operations/vesting/delegate.rs index 94b6c654e8..a212afe7f1 100644 --- a/nym-wallet/src-tauri/src/operations/vesting/delegate.rs +++ b/nym-wallet/src-tauri/src/operations/vesting/delegate.rs @@ -34,10 +34,9 @@ pub async fn vesting_delegate_to_mixnode( fee: Option, state: tauri::State<'_, Arc>>, ) -> Result { - let denom = state.read().await.current_network().denom(); - let delegation = amount.into_cosmwasm_coin(&denom)?; + let delegation = amount.into_backend_coin(state.read().await.current_network().denom())?; nymd_client!(state) - .vesting_delegate_to_mixnode(identity, &delegation, fee) + .vesting_delegate_to_mixnode(identity, delegation.clone(), fee) .await?; Ok(DelegationResult::new( nymd_client!(state).address().as_ref(), diff --git a/validator-api/src/nymd_client.rs b/validator-api/src/nymd_client.rs index 7de1c49be6..3e32d40bef 100644 --- a/validator-api/src/nymd_client.rs +++ b/validator-api/src/nymd_client.rs @@ -18,7 +18,7 @@ use tokio::sync::RwLock; use tokio::time::sleep; use validator_client::nymd::{ hash::{Hash, SHA256_HASH_SIZE}, - CosmWasmClient, CosmosCoin, Fee, QueryNymdClient, SigningCosmWasmClient, SigningNymdClient, + Coin, CosmWasmClient, Fee, QueryNymdClient, SigningCosmWasmClient, SigningNymdClient, TendermintTime, }; use validator_client::ValidatorClientError; @@ -326,7 +326,7 @@ impl Client { &self, rewarded_set: Vec, expected_active_set_size: u32, - reward_msgs: Vec<(ExecuteMsg, Vec)>, + reward_msgs: Vec<(ExecuteMsg, Vec)>, ) -> Result<(), RewardingError> where C: SigningCosmWasmClient + Sync, @@ -358,7 +358,7 @@ impl Client { async fn execute_multiple_with_retry( &self, - msgs: Vec<(M, Vec)>, + msgs: Vec<(M, Vec)>, fee: Fee, memo: String, ) -> Result<(), RewardingError> diff --git a/validator-api/src/rewarded_set_updater/mod.rs b/validator-api/src/rewarded_set_updater/mod.rs index 8de7d0c891..9f008348d0 100644 --- a/validator-api/src/rewarded_set_updater/mod.rs +++ b/validator-api/src/rewarded_set_updater/mod.rs @@ -25,7 +25,7 @@ use std::collections::HashSet; use std::time::Duration; use time::OffsetDateTime; use tokio::time::sleep; -use validator_client::nymd::{CosmosCoin, SigningNymdClient}; +use validator_client::nymd::{Coin, SigningNymdClient}; pub(crate) mod error; @@ -120,7 +120,7 @@ impl RewardedSetUpdater { async fn reward_current_rewarded_set( &self, - ) -> Result)>, RewardingError> { + ) -> Result)>, RewardingError> { let to_reward = self.nodes_to_reward().await?; let epoch = self.epoch().await?; @@ -143,7 +143,7 @@ impl RewardedSetUpdater { async fn generate_reward_messages( &self, eligible_mixnodes: &[MixnodeToReward], - ) -> Result)>, RewardingError> { + ) -> Result)>, RewardingError> { cfg_if::cfg_if! { if #[cfg(feature = "no-reward")] { Ok(vec![]) From 9f51c60bacd320bce2726237101a2747dc41a3f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Tue, 31 May 2022 15:52:26 +0100 Subject: [PATCH 2/2] Wallet simulate bandaid (#1296) * Removed Add/Sub that somehow got brought back in a merge * Created 'get_old_and_incorrect_hardcoded_fee' to make wallet as it did before * Brought back all Operation variants just in case --- nym-wallet/src-tauri/src/coin.rs | 45 ------------ nym-wallet/src-tauri/src/main.rs | 1 + nym-wallet/src-tauri/src/utils.rs | 113 +++++++++++++++++++++++++++++ nym-wallet/src/requests/queries.ts | 8 +- 4 files changed, 118 insertions(+), 49 deletions(-) diff --git a/nym-wallet/src-tauri/src/coin.rs b/nym-wallet/src-tauri/src/coin.rs index 1903e869f9..9f4c1d7f3a 100644 --- a/nym-wallet/src-tauri/src/coin.rs +++ b/nym-wallet/src-tauri/src/coin.rs @@ -4,7 +4,6 @@ use crate::error::BackendError; use crate::network::Network; use serde::{Deserialize, Serialize}; use std::convert::TryFrom; -use std::ops::{Add, Sub}; use std::str::FromStr; use strum::IntoEnumIterator; use validator_client::nymd::CosmosCoin; @@ -54,50 +53,6 @@ pub struct Coin { denom: Denom, } -// Allows adding minor and major denominations, output will have the LHS denom. -impl Add for Coin { - type Output = Self; - - fn add(self, rhs: Self) -> Self { - let denom = self.denom.clone(); - let lhs = self.to_minor(); - let rhs = rhs.to_minor(); - let lhs_amount = lhs.amount.parse::().unwrap(); - let rhs_amount = rhs.amount.parse::().unwrap(); - let amount = lhs_amount + rhs_amount; - let coin = Coin { - amount: amount.to_string(), - denom: Denom::Minor, - }; - match denom { - Denom::Major => coin.to_major(), - Denom::Minor => coin, - } - } -} - -// Allows adding minor and major denominations, output will have the LHS denom. -impl Sub for Coin { - type Output = Self; - - fn sub(self, rhs: Self) -> Self { - let denom = self.denom.clone(); - let lhs = self.to_minor(); - let rhs = rhs.to_minor(); - let lhs_amount = lhs.amount.parse::().unwrap(); - let rhs_amount = rhs.amount.parse::().unwrap(); - let amount = lhs_amount - rhs_amount; - let coin = Coin { - amount: amount.to_string(), - denom: Denom::Minor, - }; - match denom { - Denom::Major => coin.to_major(), - Denom::Minor => coin, - } - } -} - impl Coin { #[allow(unused)] pub fn major(amount: T) -> Coin { diff --git a/nym-wallet/src-tauri/src/main.rs b/nym-wallet/src-tauri/src/main.rs index 91e3734cdf..9f78cef22b 100644 --- a/nym-wallet/src-tauri/src/main.rs +++ b/nym-wallet/src-tauri/src/main.rs @@ -77,6 +77,7 @@ fn main() { utils::owns_gateway, utils::owns_mixnode, utils::get_env, + utils::get_old_and_incorrect_hardcoded_fee, validator_api::status::gateway_core_node_status, validator_api::status::mixnode_core_node_status, validator_api::status::mixnode_inclusion_probability, diff --git a/nym-wallet/src-tauri/src/utils.rs b/nym-wallet/src-tauri/src/utils.rs index 405da42ee3..8bb1982d26 100644 --- a/nym-wallet/src-tauri/src/utils.rs +++ b/nym-wallet/src-tauri/src/utils.rs @@ -8,6 +8,7 @@ use mixnet_contract_common::Delegation; use serde::{Deserialize, Serialize}; use std::sync::Arc; use tokio::sync::RwLock; +use validator_client::nymd::{tx, CosmosCoin, Gas, GasPrice}; #[allow(non_snake_case)] #[cfg_attr(test, derive(ts_rs::TS))] @@ -65,6 +66,118 @@ pub async fn owns_gateway( .is_some()) } +#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Serialize, Deserialize)] +pub enum Operation { + Upload, + Init, + Migrate, + ChangeAdmin, + Send, + + BondMixnode, + BondMixnodeOnBehalf, + UnbondMixnode, + UnbondMixnodeOnBehalf, + UpdateMixnodeConfig, + DelegateToMixnode, + DelegateToMixnodeOnBehalf, + UndelegateFromMixnode, + UndelegateFromMixnodeOnBehalf, + + BondGateway, + BondGatewayOnBehalf, + UnbondGateway, + UnbondGatewayOnBehalf, + + UpdateContractSettings, + + BeginMixnodeRewarding, + FinishMixnodeRewarding, + + TrackUnbondGateway, + TrackUnbondMixnode, + WithdrawVestedCoins, + TrackUndelegation, + CreatePeriodicVestingAccount, + + AdvanceCurrentInterval, + AdvanceCurrentEpoch, + WriteRewardedSet, + ClearRewardedSet, + UpdateMixnetAddress, + CheckpointMixnodes, + ReconcileDelegations, +} + +impl Operation { + fn default_gas_limit(&self) -> Gas { + match self { + Operation::Upload => 3_000_000u64.into(), + Operation::Init => 500_000u64.into(), + Operation::Migrate => 200_000u64.into(), + Operation::ChangeAdmin => 80_000u64.into(), + Operation::Send => 80_000u64.into(), + + Operation::BondMixnode => 175_000u64.into(), + Operation::BondMixnodeOnBehalf => 200_000u64.into(), + Operation::UnbondMixnode => 175_000u64.into(), + Operation::UnbondMixnodeOnBehalf => 175_000u64.into(), + Operation::UpdateMixnodeConfig => 175_000u64.into(), + Operation::DelegateToMixnode => 175_000u64.into(), + Operation::DelegateToMixnodeOnBehalf => 175_000u64.into(), + Operation::UndelegateFromMixnode => 175_000u64.into(), + Operation::UndelegateFromMixnodeOnBehalf => 175_000u64.into(), + + Operation::BondGateway => 175_000u64.into(), + Operation::BondGatewayOnBehalf => 200_000u64.into(), + Operation::UnbondGateway => 175_000u64.into(), + Operation::UnbondGatewayOnBehalf => 200_000u64.into(), + + Operation::UpdateContractSettings => 175_000u64.into(), + Operation::BeginMixnodeRewarding => 175_000u64.into(), + Operation::FinishMixnodeRewarding => 175_000u64.into(), + Operation::TrackUnbondGateway => 175_000u64.into(), + Operation::TrackUnbondMixnode => 175_000u64.into(), + Operation::WithdrawVestedCoins => 175_000u64.into(), + Operation::TrackUndelegation => 175_000u64.into(), + Operation::CreatePeriodicVestingAccount => 175_000u64.into(), + Operation::AdvanceCurrentInterval => 175_000u64.into(), + Operation::WriteRewardedSet => 175_000u64.into(), + Operation::ClearRewardedSet => 175_000u64.into(), + Operation::UpdateMixnetAddress => 80_000u64.into(), + Operation::CheckpointMixnodes => 175_000u64.into(), + Operation::ReconcileDelegations => 500_000u64.into(), + Operation::AdvanceCurrentEpoch => 175_000u64.into(), + } + } + + fn calculate_fee(gas_price: &GasPrice, gas_limit: Gas) -> CosmosCoin { + gas_price * gas_limit + } + + fn determine_custom_fee(gas_price: &GasPrice, gas_limit: Gas) -> tx::Fee { + let fee = Self::calculate_fee(gas_price, gas_limit); + tx::Fee::from_amount_and_gas(fee, gas_limit) + } + + fn default_fee(&self, gas_price: &GasPrice) -> tx::Fee { + Self::determine_custom_fee(gas_price, self.default_gas_limit()) + } +} + +#[tauri::command] +pub async fn get_old_and_incorrect_hardcoded_fee( + state: tauri::State<'_, Arc>>, + operation: Operation, +) -> Result { + let mut approximate_fee = operation.default_fee(nymd_client!(state).gas_price()); + // on all our chains it should only ever contain a single type of currency + assert_eq!(approximate_fee.amount.len(), 1); + let coin: Coin = approximate_fee.amount.pop().unwrap().into(); + log::info!("hardcoded fee for {:?} is {:?}", operation, coin); + Ok(coin.to_major()) +} + #[cfg_attr(test, derive(ts_rs::TS))] #[cfg_attr(test, ts(export, export_to = "../src/types/rust/delegationresult.ts"))] #[derive(Serialize, Deserialize)] diff --git a/nym-wallet/src/requests/queries.ts b/nym-wallet/src/requests/queries.ts index cd3b03da46..aed26e023a 100644 --- a/nym-wallet/src/requests/queries.ts +++ b/nym-wallet/src/requests/queries.ts @@ -60,10 +60,10 @@ export const checkGatewayOwnership = async (): Promise => { // NOTE: this uses OUTDATED defaults that might have no resemblance with the reality // as for the actual transaction, the gas cost is being simulated beforehand export const getGasFee = async (operation: Operation): Promise => { - // THIS NO LONGER EXISTS : ) - // const res: Coin = await invoke('outdated_get_approximate_fee', { operation }); - // return res; - return new Promise(((resolve, reject) => reject())) + // current bandaid until `simulation` is properly implemented on the frontend. + // This essentially moves the usage of hardcoded values closer to the point of use. + const res: Coin = await invoke('get_old_and_incorrect_hardcoded_fee', { operation }); + return res; }; export const getInclusionProbability = async (identity: string): Promise => {