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 da8a4ff6ad..aa668676c6 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; @@ -294,38 +294,17 @@ pub trait SigningCosmWasmClient: CosmWasmClient { }) } - // 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( + async fn 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, - { - 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(), @@ -351,7 +330,7 @@ pub trait SigningCosmWasmClient: CosmWasmClient { }) } - async fn execute_multiple( + async fn execute_multiple( &self, sender_address: &AccountId, contract_address: &AccountId, @@ -360,9 +339,7 @@ pub trait SigningCosmWasmClient: CosmWasmClient { memo: impl Into + Send + 'static, ) -> Result where - // this allows you to use both CosmosCoin and Coin - T: Into + Send, - I: IntoIterator)> + Send, + I: IntoIterator)> + Send, M: Serialize, { let messages = msgs @@ -394,18 +371,14 @@ 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 - where - // this allows you to use both CosmosCoin and Coin - T: Into + Send, - { + ) -> Result { let send_msg = MsgSend { from_address: sender_address.clone(), to_address: recipient_address.clone(), @@ -419,7 +392,7 @@ pub trait SigningCosmWasmClient: CosmWasmClient { .check_response() } - async fn send_tokens_multiple( + async fn send_tokens_multiple( &self, sender_address: &AccountId, msgs: I, @@ -427,9 +400,7 @@ pub trait SigningCosmWasmClient: CosmWasmClient { memo: impl Into + Send + 'static, ) -> Result where - // this allows you to use both CosmosCoin and Coin - T: Into + Send, - I: IntoIterator)> + Send, + I: IntoIterator)> + Send, { let messages = msgs .into_iter() diff --git a/common/client-libs/validator-client/src/nymd/mod.rs b/common/client-libs/validator-client/src/nymd/mod.rs index c1bf428e40..fe038c0406 100644 --- a/common/client-libs/validator-client/src/nymd/mod.rs +++ b/common/client-libs/validator-client/src/nymd/mod.rs @@ -654,17 +654,15 @@ impl NymdClient { } /// Send funds from one address to another - pub async fn send( + pub async fn send( &self, recipient: &AccountId, - amount: Vec, + amount: Vec, memo: impl Into + Send + 'static, fee: Option, ) -> Result where C: SigningCosmWasmClient + Sync, - // this allows you to use both CosmosCoin and Coin - T: Into + Send, { let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); self.client @@ -673,16 +671,14 @@ impl NymdClient { } /// Send funds from one address to multiple others - pub async fn send_multiple( + pub async fn send_multiple( &self, - msgs: Vec<(AccountId, Vec)>, + msgs: Vec<(AccountId, Vec)>, memo: impl Into + Send + 'static, fee: Option, ) -> Result where C: SigningCosmWasmClient + Sync, - // this allows you to use both CosmosCoin and Coin - T: Into + Send, { let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); self.client @@ -690,18 +686,16 @@ impl NymdClient { .await } - pub async fn execute( + pub async fn execute( &self, contract_address: &AccountId, msg: &M, fee: Fee, memo: impl Into + Send + 'static, - funds: Vec, + funds: Vec, ) -> Result where C: SigningCosmWasmClient + Sync, - // this allows you to use both CosmosCoin and Coin - T: Into + Send, M: ?Sized + Serialize + Sync, { self.client @@ -709,7 +703,7 @@ impl NymdClient { .await } - pub async fn execute_multiple( + pub async fn execute_multiple( &self, contract_address: &AccountId, msgs: I, @@ -718,9 +712,7 @@ impl NymdClient { ) -> Result where C: SigningCosmWasmClient + Sync, - // this allows you to use both CosmosCoin and Coin - T: Into + Send, - I: IntoIterator)> + Send, + I: IntoIterator)> + Send, M: Serialize, { self.client @@ -916,12 +908,13 @@ impl NymdClient { let req = ExecuteMsg::UnbondMixnode {}; self.client - .fundless_execute( + .execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Unbonding mixnode from rust!", + vec![], ) .await } @@ -939,12 +932,13 @@ impl NymdClient { let req = ExecuteMsg::UnbondMixnodeOnBehalf { owner }; self.client - .fundless_execute( + .execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Unbonding mixnode on behalf from rust!", + vec![], ) .await } @@ -964,12 +958,13 @@ impl NymdClient { profit_margin_percent, }; self.client - .fundless_execute( + .execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Updating mixnode configuration from rust!", + vec![], ) .await } @@ -1081,12 +1076,13 @@ impl NymdClient { mix_identity: mix_identity.to_string(), }; self.client - .fundless_execute( + .execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Removing mixnode delegation from rust!", + vec![], ) .await } @@ -1108,12 +1104,13 @@ impl NymdClient { delegate: delegate.to_string(), }; self.client - .fundless_execute( + .execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Removing mixnode delegation on behalf from rust!", + vec![], ) .await } @@ -1223,12 +1220,13 @@ impl NymdClient { let req = ExecuteMsg::UnbondGateway {}; self.client - .fundless_execute( + .execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Unbonding gateway from rust!", + vec![], ) .await } @@ -1247,12 +1245,13 @@ impl NymdClient { let req = ExecuteMsg::UnbondGatewayOnBehalf { owner }; self.client - .fundless_execute( + .execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Unbonding gateway on behalf from rust!", + vec![], ) .await } @@ -1269,12 +1268,13 @@ impl NymdClient { let req = ExecuteMsg::UpdateContractStateParams(new_params); self.client - .fundless_execute( + .execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Updating contract state from rust!", + vec![], ) .await } @@ -1287,12 +1287,13 @@ impl NymdClient { let req = ExecuteMsg::AdvanceCurrentEpoch {}; self.client - .fundless_execute( + .execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Advance current epoch", + vec![], ) .await } @@ -1305,12 +1306,13 @@ impl NymdClient { let req = ExecuteMsg::ReconcileDelegations {}; self.client - .fundless_execute( + .execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Reconciling delegation events", + vec![], ) .await } @@ -1323,12 +1325,13 @@ impl NymdClient { let req = ExecuteMsg::CheckpointMixnodes {}; self.client - .fundless_execute( + .execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Snapshotting mixnodes", + vec![], ) .await } @@ -1349,12 +1352,13 @@ impl NymdClient { expected_active_set_size, }; self.client - .fundless_execute( + .execute( self.address(), self.mixnet_contract_address()?, &req, fee, "Writing rewarded set", + vec![], ) .await } 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 b38b53b408..a60f5bea94 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,10 +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::{Fee, NymdClient}; +use crate::nymd::{Coin, Fee, NymdClient}; use async_trait::async_trait; -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}; @@ -25,57 +23,57 @@ pub trait VestingSigningClient { fee: Option, ) -> Result; - async fn vesting_bond_gateway + Send>( + async fn vesting_bond_gateway( &self, gateway: Gateway, owner_signature: &str, - pledge: T, + pledge: Coin, fee: Option, ) -> Result; async fn vesting_unbond_gateway(&self, fee: Option) -> Result; - async fn vesting_track_unbond_gateway + Send>( + async fn vesting_track_unbond_gateway( &self, owner: &str, - amount: T, + amount: Coin, fee: Option, ) -> Result; - async fn vesting_bond_mixnode + Send>( + async fn vesting_bond_mixnode( &self, mix_node: MixNode, owner_signature: &str, - pledge: T, + pledge: Coin, fee: Option, ) -> Result; async fn vesting_unbond_mixnode(&self, fee: Option) -> Result; - async fn vesting_track_unbond_mixnode + Send>( + async fn vesting_track_unbond_mixnode( &self, owner: &str, - amount: T, + amount: Coin, fee: Option, ) -> Result; - async fn withdraw_vested_coins + Send>( + async fn withdraw_vested_coins( &self, - amount: T, + amount: Coin, fee: Option, ) -> Result; - async fn vesting_track_undelegation + Send>( + async fn vesting_track_undelegation( &self, address: &str, mix_identity: IdentityKey, - amount: T, + amount: Coin, fee: Option, ) -> Result; - async fn vesting_delegate_to_mixnode<'a, T: Into + Send>( + async fn vesting_delegate_to_mixnode<'a>( &self, mix_identity: IdentityKeyRef<'a>, - amount: T, + amount: Coin, fee: Option, ) -> Result; @@ -85,12 +83,12 @@ pub trait VestingSigningClient { fee: Option, ) -> Result; - async fn create_periodic_vesting_account + Send>( + async fn create_periodic_vesting_account( &self, owner_address: &str, staking_address: Option, vesting_spec: Option, - amount: T, + amount: Coin, fee: Option, ) -> Result; } @@ -107,12 +105,13 @@ impl VestingSigningClient for NymdClient profit_margin_percent, }; self.client - .fundless_execute( + .execute( self.address(), self.vesting_contract_address()?, &req, fee, "VestingContract::UpdateMixnetConfig", + vec![], ) .await } @@ -127,26 +126,24 @@ impl VestingSigningClient for NymdClient address: address.to_string(), }; self.client - .fundless_execute( + .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: T, + pledge: Coin, fee: Option, - ) -> Result - where - T: Into + Send, - { + ) -> Result { let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); let req = VestingExecuteMsg::BondGateway { gateway, @@ -154,12 +151,13 @@ impl VestingSigningClient for NymdClient amount: pledge.into(), }; self.client - .fundless_execute( + .execute( self.address(), self.vesting_contract_address()?, &req, fee, "VestingContract::BondGateway", + vec![], ) .await } @@ -168,51 +166,47 @@ impl VestingSigningClient for NymdClient let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); let req = VestingExecuteMsg::UnbondGateway {}; self.client - .fundless_execute( + .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: T, + amount: Coin, fee: Option, - ) -> Result - where - T: Into + Send, - { + ) -> Result { let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); let req = VestingExecuteMsg::TrackUnbondGateway { owner: owner.to_string(), amount: amount.into(), }; self.client - .fundless_execute( + .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: T, + pledge: Coin, fee: Option, - ) -> Result - where - T: Into + Send, - { + ) -> Result { let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); let req = VestingExecuteMsg::BondMixnode { mix_node, @@ -220,12 +214,13 @@ impl VestingSigningClient for NymdClient amount: pledge.into(), }; self.client - .fundless_execute( + .execute( self.address(), self.vesting_contract_address()?, &req, fee, "VestingContract::BondMixnode", + vec![], ) .await } @@ -234,72 +229,66 @@ impl VestingSigningClient for NymdClient let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); let req = VestingExecuteMsg::UnbondMixnode {}; self.client - .fundless_execute( + .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: T, + amount: Coin, fee: Option, - ) -> Result - where - T: Into + Send, - { + ) -> Result { let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); let req = VestingExecuteMsg::TrackUnbondMixnode { owner: owner.to_string(), amount: amount.into(), }; self.client - .fundless_execute( + .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: T, + amount: Coin, fee: Option, - ) -> Result - where - T: Into + Send, - { + ) -> Result { let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); let req = VestingExecuteMsg::WithdrawVestedCoins { amount: amount.into(), }; self.client - .fundless_execute( + .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: T, + amount: Coin, fee: Option, - ) -> Result - where - T: Into + Send, - { + ) -> Result { let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); let req = VestingExecuteMsg::TrackUndelegation { owner: address.to_string(), @@ -307,36 +296,35 @@ impl VestingSigningClient for NymdClient amount: amount.into(), }; self.client - .fundless_execute( + .execute( self.address(), self.vesting_contract_address()?, &req, fee, "VestingContract::TrackUndelegation", + vec![], ) .await } - async fn vesting_delegate_to_mixnode<'a, T>( + async fn vesting_delegate_to_mixnode<'a>( &self, mix_identity: IdentityKeyRef<'a>, - amount: T, + amount: Coin, fee: Option, - ) -> Result - where - T: Into + Send, - { + ) -> Result { let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); let req = VestingExecuteMsg::DelegateToMixnode { mix_identity: mix_identity.into(), amount: amount.into(), }; self.client - .fundless_execute( + .execute( self.address(), self.vesting_contract_address()?, &req, fee, "VestingContract::DelegateToMixnode", + vec![], ) .await } @@ -351,27 +339,25 @@ impl VestingSigningClient for NymdClient mix_identity: mix_identity.into(), }; self.client - .fundless_execute( + .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: T, + amount: Coin, fee: Option, - ) -> Result - where - T: Into + Send, - { + ) -> Result { let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier))); let req = VestingExecuteMsg::CreateAccount { owner_address: owner_address.to_string(),