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..13a3ac6678 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 @@ -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, Coin as CosmosCoin, Tx}; use log::debug; use serde::Serialize; use sha2::Digest; @@ -294,23 +294,45 @@ pub trait SigningCosmWasmClient: CosmWasmClient { }) } - async fn execute( + // a helper to automatically infer required types so that you wouldn't need the turbofish + // for normal `execute` if you're not sending any funds with your transaction + async fn fundless_execute( &self, sender_address: &AccountId, contract_address: &AccountId, msg: &M, fee: Fee, memo: impl Into + Send + 'static, - funds: Vec, ) -> Result where M: ?Sized + Serialize + Sync, + { + // todo!() + self.execute::<_, CosmosCoin, _>(sender_address, contract_address, msg, fee, memo, vec![]) + .await + } + + // the memo had to be extracted into an explicit generic due to: https://github.com/rust-lang/rust/issues/83701 + async fn execute( + &self, + sender_address: &AccountId, + contract_address: &AccountId, + msg: &M, + fee: Fee, + memo: S, + funds: Vec, + ) -> Result + where + M: ?Sized + Serialize + Sync, + // this allows you to use both CosmosCoin and Coin + T: Into + Send, + S: Into + Send + 'static, { let execute_msg = cosmwasm::MsgExecuteContract { 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()))?; @@ -330,7 +352,7 @@ pub trait SigningCosmWasmClient: CosmWasmClient { }) } - async fn execute_multiple( + async fn execute_multiple( &self, sender_address: &AccountId, contract_address: &AccountId, @@ -339,7 +361,9 @@ pub trait SigningCosmWasmClient: CosmWasmClient { memo: impl Into + Send + 'static, ) -> Result where - I: IntoIterator)> + Send, + // this allows you to use both CosmosCoin and Coin + T: Into + Send, + I: IntoIterator)> + Send, M: Serialize, { let messages = msgs @@ -349,7 +373,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())) @@ -371,18 +395,22 @@ pub trait SigningCosmWasmClient: CosmWasmClient { }) } - async fn send_tokens( + async fn send_tokens( &self, sender_address: &AccountId, recipient_address: &AccountId, - amount: Vec, + amount: Vec, fee: Fee, memo: impl Into + Send + 'static, - ) -> Result { + ) -> Result + where + // this allows you to use both CosmosCoin and Coin + T: Into + Send, + { 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()))?; @@ -392,7 +420,7 @@ pub trait SigningCosmWasmClient: CosmWasmClient { .check_response() } - async fn send_tokens_multiple( + async fn send_tokens_multiple( &self, sender_address: &AccountId, msgs: I, @@ -400,7 +428,9 @@ pub trait SigningCosmWasmClient: CosmWasmClient { memo: impl Into + Send + 'static, ) -> Result where - I: IntoIterator)> + Send, + // this allows you to use both CosmosCoin and Coin + T: Into + Send, + I: IntoIterator)> + Send, { let messages = msgs .into_iter() @@ -408,7 +438,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())) @@ -420,18 +450,22 @@ pub trait SigningCosmWasmClient: CosmWasmClient { .check_response() } - async fn delegate_tokens( + async fn delegate_tokens( &self, delegator_address: &AccountId, validator_address: &AccountId, - amount: Coin, + amount: T, fee: Fee, memo: impl Into + Send + 'static, - ) -> Result { + ) -> Result + where + // this allows you to use both CosmosCoin and Coin + T: Into + Send, + { 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()))?; @@ -441,18 +475,22 @@ pub trait SigningCosmWasmClient: CosmWasmClient { .check_response() } - async fn undelegate_tokens( + async fn undelegate_tokens( &self, delegator_address: &AccountId, validator_address: &AccountId, - amount: Coin, + amount: T, fee: Fee, memo: impl Into + Send + 'static, - ) -> Result { + ) -> Result + where + // this allows you to use both CosmosCoin and Coin + T: Into + Send, + { 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..9d26f1bd49 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(), } } diff --git a/common/client-libs/validator-client/src/nymd/mod.rs b/common/client-libs/validator-client/src/nymd/mod.rs index cef740c993..8769433dc1 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; @@ -266,7 +267,7 @@ impl NymdClient { &self, address: &AccountId, denom: Denom, - ) -> Result, NymdError> + ) -> Result, NymdError> where C: CosmWasmClient + Sync, { @@ -811,7 +812,7 @@ impl NymdClient { &req, fee, "Bonding mixnode from rust!", - vec![cosmwasm_coin_to_cosmos_coin(pledge)], + vec![pledge], ) .await } @@ -842,7 +843,7 @@ impl NymdClient { &req, fee, "Bonding mixnode on behalf from rust!", - vec![cosmwasm_coin_to_cosmos_coin(pledge)], + vec![pledge], ) .await } @@ -858,7 +859,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)| { ( @@ -867,7 +868,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(); @@ -892,13 +893,12 @@ impl NymdClient { let req = ExecuteMsg::UnbondMixnode {}; self.client - .execute( + .fundless_execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Unbonding mixnode from rust!", - Vec::new(), ) .await } @@ -916,13 +916,12 @@ impl NymdClient { let req = ExecuteMsg::UnbondMixnodeOnBehalf { owner }; self.client - .execute( + .fundless_execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Unbonding mixnode on behalf from rust!", - Vec::new(), ) .await } @@ -942,13 +941,12 @@ impl NymdClient { profit_margin_percent, }; self.client - .execute( + .fundless_execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Updating mixnode configuration from rust!", - Vec::new(), ) .await } @@ -957,7 +955,7 @@ impl NymdClient { pub async fn delegate_to_mixnode( &self, mix_identity: &str, - amount: &Coin, + amount: Coin, fee: Option, ) -> Result where @@ -975,7 +973,7 @@ impl NymdClient { &req, fee, "Delegating to mixnode from rust!", - vec![cosmwasm_coin_ptr_to_cosmos_coin(amount)], + vec![amount], ) .await } @@ -986,7 +984,7 @@ impl NymdClient { &self, mix_identity: &str, delegate: &str, - amount: &Coin, + amount: Coin, fee: Option, ) -> Result where @@ -1005,7 +1003,7 @@ impl NymdClient { &req, fee, "Delegating to mixnode on behalf from rust!", - vec![cosmwasm_coin_ptr_to_cosmos_coin(amount)], + vec![amount], ) .await } @@ -1021,7 +1019,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| { ( @@ -1029,7 +1027,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(); @@ -1060,13 +1058,12 @@ impl NymdClient { mix_identity: mix_identity.to_string(), }; self.client - .execute( + .fundless_execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Removing mixnode delegation from rust!", - Vec::new(), ) .await } @@ -1088,13 +1085,12 @@ impl NymdClient { delegate: delegate.to_string(), }; self.client - .execute( + .fundless_execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Removing mixnode delegation on behalf from rust!", - Vec::new(), ) .await } @@ -1123,7 +1119,7 @@ impl NymdClient { &req, fee, "Bonding gateway from rust!", - vec![cosmwasm_coin_to_cosmos_coin(pledge)], + vec![pledge], ) .await } @@ -1154,7 +1150,7 @@ impl NymdClient { &req, fee, "Bonding gateway on behalf from rust!", - vec![cosmwasm_coin_to_cosmos_coin(pledge)], + vec![pledge], ) .await } @@ -1170,7 +1166,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)| { ( @@ -1179,7 +1175,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(); @@ -1204,13 +1200,12 @@ impl NymdClient { let req = ExecuteMsg::UnbondGateway {}; self.client - .execute( + .fundless_execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Unbonding gateway from rust!", - Vec::new(), ) .await } @@ -1229,13 +1224,12 @@ impl NymdClient { let req = ExecuteMsg::UnbondGatewayOnBehalf { owner }; self.client - .execute( + .fundless_execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Unbonding gateway on behalf from rust!", - Vec::new(), ) .await } @@ -1252,13 +1246,12 @@ impl NymdClient { let req = ExecuteMsg::UpdateContractStateParams(new_params); self.client - .execute( + .fundless_execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Updating contract state from rust!", - Vec::new(), ) .await } @@ -1271,13 +1264,12 @@ impl NymdClient { let req = ExecuteMsg::AdvanceCurrentEpoch {}; self.client - .execute( + .fundless_execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Advance current epoch", - Vec::new(), ) .await } @@ -1290,13 +1282,12 @@ impl NymdClient { let req = ExecuteMsg::ReconcileDelegations {}; self.client - .execute( + .fundless_execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Reconciling delegation events", - Vec::new(), ) .await } @@ -1309,13 +1300,12 @@ impl NymdClient { let req = ExecuteMsg::CheckpointMixnodes {}; self.client - .execute( + .fundless_execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Snapshotting mixnodes", - Vec::new(), ) .await } @@ -1336,30 +1326,13 @@ impl NymdClient { expected_active_set_size, }; self.client - .execute( + .fundless_execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Writing rewarded set", - Vec::new(), ) .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 073cfb7052..b38b53b408 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,10 @@ 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::{Fee, NymdClient}; use async_trait::async_trait; -use cosmwasm_std::Coin; +use cosmrs::Coin as CosmosCoin; +use cosmwasm_std::Coin as CosmWasmCoin; use mixnet_contract_common::{Gateway, IdentityKey, IdentityKeyRef, MixNode}; use vesting_contract_common::messages::{ExecuteMsg as VestingExecuteMsg, VestingSpecification}; @@ -24,57 +25,57 @@ pub trait VestingSigningClient { fee: Option, ) -> Result; - async fn vesting_bond_gateway( + async fn vesting_bond_gateway + Send>( &self, gateway: Gateway, owner_signature: &str, - pledge: Coin, + pledge: T, fee: Option, ) -> Result; async fn vesting_unbond_gateway(&self, fee: Option) -> Result; - async fn vesting_track_unbond_gateway( + async fn vesting_track_unbond_gateway + Send>( &self, owner: &str, - amount: Coin, + amount: T, fee: Option, ) -> Result; - async fn vesting_bond_mixnode( + async fn vesting_bond_mixnode + Send>( &self, mix_node: MixNode, owner_signature: &str, - pledge: Coin, + pledge: T, fee: Option, ) -> Result; async fn vesting_unbond_mixnode(&self, fee: Option) -> Result; - async fn vesting_track_unbond_mixnode( + async fn vesting_track_unbond_mixnode + Send>( &self, owner: &str, - amount: Coin, + amount: T, fee: Option, ) -> Result; - async fn withdraw_vested_coins( + async fn withdraw_vested_coins + Send>( &self, - amount: Coin, + amount: T, fee: Option, ) -> Result; - async fn vesting_track_undelegation( + async fn vesting_track_undelegation + Send>( &self, address: &str, mix_identity: IdentityKey, - amount: Coin, + amount: T, fee: Option, ) -> Result; - async fn vesting_delegate_to_mixnode<'a>( + async fn vesting_delegate_to_mixnode<'a, T: Into + Send>( &self, mix_identity: IdentityKeyRef<'a>, - amount: &Coin, + amount: T, fee: Option, ) -> Result; @@ -84,12 +85,12 @@ pub trait VestingSigningClient { fee: Option, ) -> Result; - async fn create_periodic_vesting_account( + async fn create_periodic_vesting_account + Send>( &self, owner_address: &str, staking_address: Option, vesting_spec: Option, - amount: Coin, + amount: T, fee: Option, ) -> Result; } @@ -106,13 +107,12 @@ impl VestingSigningClient for NymdClient profit_margin_percent, }; self.client - .execute( + .fundless_execute( self.address(), self.vesting_contract_address()?, &req, fee, "VestingContract::UpdateMixnetConfig", - vec![], ) .await } @@ -127,38 +127,39 @@ impl VestingSigningClient for NymdClient address: address.to_string(), }; self.client - .execute( + .fundless_execute( self.address(), self.vesting_contract_address()?, &req, fee, "VestingContract::UpdateMixnetAddress", - vec![], ) .await } - async fn vesting_bond_gateway( + async fn vesting_bond_gateway( &self, gateway: Gateway, owner_signature: &str, - pledge: Coin, + pledge: T, fee: Option, - ) -> Result { + ) -> Result + where + T: Into + Send, + { let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); let req = VestingExecuteMsg::BondGateway { gateway, owner_signature: owner_signature.to_string(), - amount: pledge, + amount: pledge.into(), }; self.client - .execute( + .fundless_execute( self.address(), self.vesting_contract_address()?, &req, fee, "VestingContract::BondGateway", - vec![], ) .await } @@ -167,61 +168,64 @@ impl VestingSigningClient for NymdClient let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); let req = VestingExecuteMsg::UnbondGateway {}; self.client - .execute( + .fundless_execute( self.address(), self.vesting_contract_address()?, &req, fee, "VestingContract::UnbondGateway", - vec![], ) .await } - async fn vesting_track_unbond_gateway( + async fn vesting_track_unbond_gateway( &self, owner: &str, - amount: Coin, + amount: T, fee: Option, - ) -> Result { + ) -> Result + where + T: Into + Send, + { 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( + .fundless_execute( self.address(), self.vesting_contract_address()?, &req, fee, "VestingContract::TrackUnbondGateway", - vec![], ) .await } - async fn vesting_bond_mixnode( + async fn vesting_bond_mixnode( &self, mix_node: MixNode, owner_signature: &str, - pledge: Coin, + pledge: T, fee: Option, - ) -> Result { + ) -> Result + where + T: Into + Send, + { let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); let req = VestingExecuteMsg::BondMixnode { mix_node, owner_signature: owner_signature.to_string(), - amount: pledge, + amount: pledge.into(), }; self.client - .execute( + .fundless_execute( self.address(), self.vesting_contract_address()?, &req, fee, "VestingContract::BondMixnode", - vec![], ) .await } @@ -230,100 +234,109 @@ impl VestingSigningClient for NymdClient let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); let req = VestingExecuteMsg::UnbondMixnode {}; self.client - .execute( + .fundless_execute( self.address(), self.vesting_contract_address()?, &req, fee, "VestingContract::UnbondMixnode", - vec![], ) .await } - async fn vesting_track_unbond_mixnode( + async fn vesting_track_unbond_mixnode( &self, owner: &str, - amount: Coin, + amount: T, fee: Option, - ) -> Result { + ) -> Result + where + T: Into + Send, + { 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( + .fundless_execute( self.address(), self.vesting_contract_address()?, &req, fee, "VestingContract::TrackUnbondMixnode", - vec![], ) .await } - async fn withdraw_vested_coins( + async fn withdraw_vested_coins( &self, - amount: Coin, + amount: T, fee: Option, - ) -> Result { + ) -> Result + where + T: Into + Send, + { 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( + .fundless_execute( self.address(), self.vesting_contract_address()?, &req, fee, "VestingContract::WithdrawVested", - vec![], ) .await } - async fn vesting_track_undelegation( + async fn vesting_track_undelegation( &self, address: &str, mix_identity: IdentityKey, - amount: Coin, + amount: T, fee: Option, - ) -> Result { + ) -> Result + where + T: Into + Send, + { let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); let req = VestingExecuteMsg::TrackUndelegation { owner: address.to_string(), mix_identity, - amount, + amount: amount.into(), }; self.client - .execute( + .fundless_execute( self.address(), self.vesting_contract_address()?, &req, fee, "VestingContract::TrackUndelegation", - vec![], ) .await } - async fn vesting_delegate_to_mixnode<'a>( + async fn vesting_delegate_to_mixnode<'a, T>( &self, mix_identity: IdentityKeyRef<'a>, - amount: &Coin, + amount: T, fee: Option, - ) -> Result { + ) -> Result + where + T: Into + Send, + { 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( + .fundless_execute( self.address(), self.vesting_contract_address()?, &req, fee, "VestingContract::DelegateToMixnode", - vec![], ) .await } @@ -338,25 +351,27 @@ impl VestingSigningClient for NymdClient mix_identity: mix_identity.into(), }; self.client - .execute( + .fundless_execute( self.address(), self.vesting_contract_address()?, &req, fee, "VestingContract::UndelegateFromMixnode", - vec![], ) .await } - async fn create_periodic_vesting_account( + async fn create_periodic_vesting_account( &self, owner_address: &str, staking_address: Option, vesting_spec: Option, - amount: Coin, + amount: T, fee: Option, - ) -> Result { + ) -> Result + where + T: Into + Send, + { let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); let req = VestingExecuteMsg::CreateAccount { owner_address: owner_address.to_string(), @@ -370,7 +385,7 @@ impl VestingSigningClient for NymdClient &req, fee, "VestingContract::CreatePeriodicVestingAccount", - vec![cosmwasm_coin_to_cosmos_coin(amount)], + vec![amount.into()], ) .await }