Changed client API to use the new coin type

This commit is contained in:
Jędrzej Stuczyński
2022-05-30 14:46:05 +01:00
parent 5925e85684
commit 84a42f6ed9
7 changed files with 223 additions and 186 deletions
@@ -1,6 +1,7 @@
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
// 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::<Result<_, _>>()
.map_err(|_| NymdError::SerializationError("Coins".to_owned()))
}
// this is annoyingly and inconsistently returning `Vec<CosmWasmCoin>` rather than
// Vec<Coin>, 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<Vec<CosmWasmCoin>, NymdError> {
async fn get_total_supply(&self) -> Result<Vec<Coin>, 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::<Result<_, _>>()
.map_err(|_| NymdError::SerializationError("Coins".to_owned()))
}
@@ -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<M>(
// 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<M>(
&self,
sender_address: &AccountId,
contract_address: &AccountId,
msg: &M,
fee: Fee,
memo: impl Into<String> + Send + 'static,
funds: Vec<Coin>,
) -> Result<ExecuteResult, NymdError>
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<M, T, S>(
&self,
sender_address: &AccountId,
contract_address: &AccountId,
msg: &M,
fee: Fee,
memo: S,
funds: Vec<T>,
) -> Result<ExecuteResult, NymdError>
where
M: ?Sized + Serialize + Sync,
// this allows you to use both CosmosCoin and Coin
T: Into<CosmosCoin> + Send,
S: Into<String> + 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<I, M>(
async fn execute_multiple<I, M, T>(
&self,
sender_address: &AccountId,
contract_address: &AccountId,
@@ -339,7 +361,9 @@ pub trait SigningCosmWasmClient: CosmWasmClient {
memo: impl Into<String> + Send + 'static,
) -> Result<ExecuteResult, NymdError>
where
I: IntoIterator<Item = (M, Vec<Coin>)> + Send,
// this allows you to use both CosmosCoin and Coin
T: Into<CosmosCoin> + Send,
I: IntoIterator<Item = (M, Vec<T>)> + 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<T>(
&self,
sender_address: &AccountId,
recipient_address: &AccountId,
amount: Vec<Coin>,
amount: Vec<T>,
fee: Fee,
memo: impl Into<String> + Send + 'static,
) -> Result<TxResponse, NymdError> {
) -> Result<TxResponse, NymdError>
where
// this allows you to use both CosmosCoin and Coin
T: Into<CosmosCoin> + 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<I>(
async fn send_tokens_multiple<I, T>(
&self,
sender_address: &AccountId,
msgs: I,
@@ -400,7 +428,9 @@ pub trait SigningCosmWasmClient: CosmWasmClient {
memo: impl Into<String> + Send + 'static,
) -> Result<TxResponse, NymdError>
where
I: IntoIterator<Item = (AccountId, Vec<Coin>)> + Send,
// this allows you to use both CosmosCoin and Coin
T: Into<CosmosCoin> + Send,
I: IntoIterator<Item = (AccountId, Vec<T>)> + 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<T>(
&self,
delegator_address: &AccountId,
validator_address: &AccountId,
amount: Coin,
amount: T,
fee: Fee,
memo: impl Into<String> + Send + 'static,
) -> Result<TxResponse, NymdError> {
) -> Result<TxResponse, NymdError>
where
// this allows you to use both CosmosCoin and Coin
T: Into<CosmosCoin> + 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<T>(
&self,
delegator_address: &AccountId,
validator_address: &AccountId,
amount: Coin,
amount: T,
fee: Fee,
memo: impl Into<String> + Send + 'static,
) -> Result<TxResponse, NymdError> {
) -> Result<TxResponse, NymdError>
where
// this allows you to use both CosmosCoin and Coin
T: Into<CosmosCoin> + 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()))?;
@@ -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<ProtoModuleAccount> for ModuleAccount {
#[derive(Debug)]
pub struct BaseVestingAccount {
pub base_account: Option<BaseAccount>,
pub original_vesting: Vec<Coin>,
pub delegated_free: Vec<Coin>,
pub delegated_vesting: Vec<Coin>,
pub original_vesting: Vec<CosmosCoin>,
pub delegated_free: Vec<CosmosCoin>,
pub delegated_vesting: Vec<CosmosCoin>,
pub end_time: i64,
}
@@ -184,7 +184,7 @@ impl TryFrom<ProtoDelayedVestingAccount> for DelayedVestingAccount {
#[derive(Debug)]
pub struct Period {
pub length: i64,
pub amount: Vec<Coin>,
pub amount: Vec<CosmosCoin>,
}
impl TryFrom<ProtoPeriod> 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<Coin>,
pub funds: Vec<CosmosCoin>,
/// 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<AccountId>,
}
impl InstantiateOptions {
pub fn new<T: Into<CosmosCoin>>(funds: Vec<T>, admin: Option<AccountId>) -> Self {
InstantiateOptions {
funds: funds.into_iter().map(Into::into).collect(),
admin,
}
}
}
#[derive(Debug)]
pub struct InstantiateResult {
/// The address of the newly instantiated contract
@@ -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<Gas> for &'a GasPrice {
@@ -44,7 +45,10 @@ impl<'a> Mul<Gas> 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(),
}
}
@@ -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<C> NymdClient<C> {
&self,
address: &AccountId,
denom: Denom,
) -> Result<Option<CosmosCoin>, NymdError>
) -> Result<Option<Coin>, NymdError>
where
C: CosmWasmClient + Sync,
{
@@ -811,7 +812,7 @@ impl<C> NymdClient<C> {
&req,
fee,
"Bonding mixnode from rust!",
vec![cosmwasm_coin_to_cosmos_coin(pledge)],
vec![pledge],
)
.await
}
@@ -842,7 +843,7 @@ impl<C> NymdClient<C> {
&req,
fee,
"Bonding mixnode on behalf from rust!",
vec![cosmwasm_coin_to_cosmos_coin(pledge)],
vec![pledge],
)
.await
}
@@ -858,7 +859,7 @@ impl<C> NymdClient<C> {
{
let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier)));
let reqs: Vec<(ExecuteMsg, Vec<CosmosCoin>)> = mixnode_bonds_with_sigs
let reqs: Vec<(ExecuteMsg, Vec<Coin>)> = mixnode_bonds_with_sigs
.into_iter()
.map(|(bond, owner_signature)| {
(
@@ -867,7 +868,7 @@ impl<C> NymdClient<C> {
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<C> NymdClient<C> {
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<C> NymdClient<C> {
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<C> NymdClient<C> {
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<C> NymdClient<C> {
pub async fn delegate_to_mixnode(
&self,
mix_identity: &str,
amount: &Coin,
amount: Coin,
fee: Option<Fee>,
) -> Result<ExecuteResult, NymdError>
where
@@ -975,7 +973,7 @@ impl<C> NymdClient<C> {
&req,
fee,
"Delegating to mixnode from rust!",
vec![cosmwasm_coin_ptr_to_cosmos_coin(amount)],
vec![amount],
)
.await
}
@@ -986,7 +984,7 @@ impl<C> NymdClient<C> {
&self,
mix_identity: &str,
delegate: &str,
amount: &Coin,
amount: Coin,
fee: Option<Fee>,
) -> Result<ExecuteResult, NymdError>
where
@@ -1005,7 +1003,7 @@ impl<C> NymdClient<C> {
&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<C> NymdClient<C> {
{
let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier)));
let reqs: Vec<(ExecuteMsg, Vec<CosmosCoin>)> = mixnode_delegations
let reqs: Vec<(ExecuteMsg, Vec<Coin>)> = mixnode_delegations
.into_iter()
.map(|delegation| {
(
@@ -1029,7 +1027,7 @@ impl<C> NymdClient<C> {
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<C> NymdClient<C> {
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<C> NymdClient<C> {
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<C> NymdClient<C> {
&req,
fee,
"Bonding gateway from rust!",
vec![cosmwasm_coin_to_cosmos_coin(pledge)],
vec![pledge],
)
.await
}
@@ -1154,7 +1150,7 @@ impl<C> NymdClient<C> {
&req,
fee,
"Bonding gateway on behalf from rust!",
vec![cosmwasm_coin_to_cosmos_coin(pledge)],
vec![pledge],
)
.await
}
@@ -1170,7 +1166,7 @@ impl<C> NymdClient<C> {
{
let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier)));
let reqs: Vec<(ExecuteMsg, Vec<CosmosCoin>)> = gateway_bonds_with_sigs
let reqs: Vec<(ExecuteMsg, Vec<Coin>)> = gateway_bonds_with_sigs
.into_iter()
.map(|(bond, owner_signature)| {
(
@@ -1179,7 +1175,7 @@ impl<C> NymdClient<C> {
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<C> NymdClient<C> {
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<C> NymdClient<C> {
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<C> NymdClient<C> {
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<C> NymdClient<C> {
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<C> NymdClient<C> {
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<C> NymdClient<C> {
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<C> NymdClient<C> {
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(),
}
}
@@ -1,11 +1,12 @@
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
// 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<C: CosmWasmClient + Sync + Send> VestingQueryClient for NymdClient<C> {
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<C: CosmWasmClient + Sync + Send> VestingQueryClient for NymdClient<C> {
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<C: CosmWasmClient + Sync + Send> VestingQueryClient for NymdClient<C> {
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<C: CosmWasmClient + Sync + Send> VestingQueryClient for NymdClient<C> {
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<C: CosmWasmClient + Sync + Send> VestingQueryClient for NymdClient<C> {
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<C: CosmWasmClient + Sync + Send> VestingQueryClient for NymdClient<C> {
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<Account, NymdError> {
@@ -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<Fee>,
) -> Result<ExecuteResult, NymdError>;
async fn vesting_bond_gateway(
async fn vesting_bond_gateway<T: Into<CosmWasmCoin> + Send>(
&self,
gateway: Gateway,
owner_signature: &str,
pledge: Coin,
pledge: T,
fee: Option<Fee>,
) -> Result<ExecuteResult, NymdError>;
async fn vesting_unbond_gateway(&self, fee: Option<Fee>) -> Result<ExecuteResult, NymdError>;
async fn vesting_track_unbond_gateway(
async fn vesting_track_unbond_gateway<T: Into<CosmWasmCoin> + Send>(
&self,
owner: &str,
amount: Coin,
amount: T,
fee: Option<Fee>,
) -> Result<ExecuteResult, NymdError>;
async fn vesting_bond_mixnode(
async fn vesting_bond_mixnode<T: Into<CosmWasmCoin> + Send>(
&self,
mix_node: MixNode,
owner_signature: &str,
pledge: Coin,
pledge: T,
fee: Option<Fee>,
) -> Result<ExecuteResult, NymdError>;
async fn vesting_unbond_mixnode(&self, fee: Option<Fee>) -> Result<ExecuteResult, NymdError>;
async fn vesting_track_unbond_mixnode(
async fn vesting_track_unbond_mixnode<T: Into<CosmWasmCoin> + Send>(
&self,
owner: &str,
amount: Coin,
amount: T,
fee: Option<Fee>,
) -> Result<ExecuteResult, NymdError>;
async fn withdraw_vested_coins(
async fn withdraw_vested_coins<T: Into<CosmWasmCoin> + Send>(
&self,
amount: Coin,
amount: T,
fee: Option<Fee>,
) -> Result<ExecuteResult, NymdError>;
async fn vesting_track_undelegation(
async fn vesting_track_undelegation<T: Into<CosmWasmCoin> + Send>(
&self,
address: &str,
mix_identity: IdentityKey,
amount: Coin,
amount: T,
fee: Option<Fee>,
) -> Result<ExecuteResult, NymdError>;
async fn vesting_delegate_to_mixnode<'a>(
async fn vesting_delegate_to_mixnode<'a, T: Into<CosmWasmCoin> + Send>(
&self,
mix_identity: IdentityKeyRef<'a>,
amount: &Coin,
amount: T,
fee: Option<Fee>,
) -> Result<ExecuteResult, NymdError>;
@@ -84,12 +85,12 @@ pub trait VestingSigningClient {
fee: Option<Fee>,
) -> Result<ExecuteResult, NymdError>;
async fn create_periodic_vesting_account(
async fn create_periodic_vesting_account<T: Into<CosmosCoin> + Send>(
&self,
owner_address: &str,
staking_address: Option<String>,
vesting_spec: Option<VestingSpecification>,
amount: Coin,
amount: T,
fee: Option<Fee>,
) -> Result<ExecuteResult, NymdError>;
}
@@ -106,13 +107,12 @@ impl<C: SigningCosmWasmClient + Sync + Send> 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<C: SigningCosmWasmClient + Sync + Send> 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<T>(
&self,
gateway: Gateway,
owner_signature: &str,
pledge: Coin,
pledge: T,
fee: Option<Fee>,
) -> Result<ExecuteResult, NymdError> {
) -> Result<ExecuteResult, NymdError>
where
T: Into<CosmWasmCoin> + 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<C: SigningCosmWasmClient + Sync + Send> 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<T>(
&self,
owner: &str,
amount: Coin,
amount: T,
fee: Option<Fee>,
) -> Result<ExecuteResult, NymdError> {
) -> Result<ExecuteResult, NymdError>
where
T: Into<CosmWasmCoin> + 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<T>(
&self,
mix_node: MixNode,
owner_signature: &str,
pledge: Coin,
pledge: T,
fee: Option<Fee>,
) -> Result<ExecuteResult, NymdError> {
) -> Result<ExecuteResult, NymdError>
where
T: Into<CosmWasmCoin> + 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<C: SigningCosmWasmClient + Sync + Send> 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<T>(
&self,
owner: &str,
amount: Coin,
amount: T,
fee: Option<Fee>,
) -> Result<ExecuteResult, NymdError> {
) -> Result<ExecuteResult, NymdError>
where
T: Into<CosmWasmCoin> + 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<T>(
&self,
amount: Coin,
amount: T,
fee: Option<Fee>,
) -> Result<ExecuteResult, NymdError> {
) -> Result<ExecuteResult, NymdError>
where
T: Into<CosmWasmCoin> + 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<T>(
&self,
address: &str,
mix_identity: IdentityKey,
amount: Coin,
amount: T,
fee: Option<Fee>,
) -> Result<ExecuteResult, NymdError> {
) -> Result<ExecuteResult, NymdError>
where
T: Into<CosmWasmCoin> + 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<Fee>,
) -> Result<ExecuteResult, NymdError> {
) -> Result<ExecuteResult, NymdError>
where
T: Into<CosmWasmCoin> + 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<C: SigningCosmWasmClient + Sync + Send> 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<T>(
&self,
owner_address: &str,
staking_address: Option<String>,
vesting_spec: Option<VestingSpecification>,
amount: Coin,
amount: T,
fee: Option<Fee>,
) -> Result<ExecuteResult, NymdError> {
) -> Result<ExecuteResult, NymdError>
where
T: Into<CosmosCoin> + 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<C: SigningCosmWasmClient + Sync + Send> VestingSigningClient for NymdClient
&req,
fee,
"VestingContract::CreatePeriodicVestingAccount",
vec![cosmwasm_coin_to_cosmos_coin(amount)],
vec![amount.into()],
)
.await
}