Adding sample ExecuteMsg to DkgClient trait
This commit is contained in:
@@ -53,6 +53,9 @@ pub enum Operation {
|
||||
UpdateMixnetAddress,
|
||||
CheckpointMixnodes,
|
||||
ReconcileDelegations,
|
||||
|
||||
#[cfg(feature = "dkg")]
|
||||
CommitDkgDealing,
|
||||
}
|
||||
|
||||
pub(crate) fn calculate_fee(gas_price: &GasPrice, gas_limit: Gas) -> Coin {
|
||||
@@ -97,6 +100,9 @@ impl fmt::Display for Operation {
|
||||
Operation::CheckpointMixnodes => f.write_str("CheckpointMixnodes"),
|
||||
Operation::ReconcileDelegations => f.write_str("ReconcileDelegations"),
|
||||
Operation::AdvanceCurrentEpoch => f.write_str("AdvanceCurrentEpoch"),
|
||||
|
||||
#[cfg(feature = "dkg")]
|
||||
Operation::CommitDkgDealing => f.write_str("CommitDkgDealing"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,6 +110,7 @@ impl fmt::Display for Operation {
|
||||
impl Operation {
|
||||
// TODO: some value tweaking
|
||||
pub fn default_gas_limit(&self) -> Gas {
|
||||
let default_limit = 175_000u64.into();
|
||||
match self {
|
||||
Operation::Upload => 3_000_000u64.into(),
|
||||
Operation::Init => 500_000u64.into(),
|
||||
@@ -111,36 +118,14 @@ impl Operation {
|
||||
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(),
|
||||
|
||||
// all operations not explicitly listed default to `175_000`
|
||||
_ => default_limit,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -179,21 +179,6 @@ impl<C> NymdClient<C> {
|
||||
.ok_or(NymdError::NoContractAddressAvailable)
|
||||
}
|
||||
|
||||
#[cfg(feature = "dkg")]
|
||||
pub fn set_coconut_dkg_contract_address(
|
||||
&mut self,
|
||||
coconut_dkg_contract_address: Option<AccountId>,
|
||||
) {
|
||||
self.coconut_dkg_contract_address = coconut_dkg_contract_address;
|
||||
}
|
||||
|
||||
#[cfg(feature = "dkg")]
|
||||
pub fn coconut_dkg_contract_address(&self) -> Result<&AccountId, NymdError> {
|
||||
self.coconut_dkg_contract_address
|
||||
.as_ref()
|
||||
.ok_or(NymdError::NoContractAddressAvailable)
|
||||
}
|
||||
|
||||
pub fn set_simulated_gas_multiplier(&mut self, multiplier: f32) {
|
||||
self.simulated_gas_multiplier = multiplier;
|
||||
}
|
||||
@@ -1348,6 +1333,51 @@ impl<C> NymdClient<C> {
|
||||
}
|
||||
}
|
||||
|
||||
// dkg-related impl block
|
||||
#[cfg(feature = "dkg")]
|
||||
impl<C> NymdClient<C> {
|
||||
pub fn set_coconut_dkg_contract_address(
|
||||
&mut self,
|
||||
coconut_dkg_contract_address: Option<AccountId>,
|
||||
) {
|
||||
self.coconut_dkg_contract_address = coconut_dkg_contract_address;
|
||||
}
|
||||
|
||||
pub fn coconut_dkg_contract_address(&self) -> Result<&AccountId, NymdError> {
|
||||
self.coconut_dkg_contract_address
|
||||
.as_ref()
|
||||
.ok_or(NymdError::NoContractAddressAvailable)
|
||||
}
|
||||
|
||||
// pub async fn submit_dealing_commitment(
|
||||
// &self,
|
||||
// epoch_id: u32,
|
||||
// dealing_digest: [u8; 32],
|
||||
// receivers: u32,
|
||||
// ) -> Result<ExecuteResult, NymdError>
|
||||
// where
|
||||
// C: DkgClient,
|
||||
// {
|
||||
// let fee = self.operation_fee(Operation::CommitDkgDealing);
|
||||
//
|
||||
// let req = coconut_dkg_common::msg::ExecuteMsg::CommitDealing {
|
||||
// epoch_id,
|
||||
// dealing_digest,
|
||||
// receivers,
|
||||
// };
|
||||
// self.client
|
||||
// .execute(
|
||||
// self.address(),
|
||||
// self.coconut_dkg_contract_address()?,
|
||||
// &req,
|
||||
// fee,
|
||||
// "dealing commitment",
|
||||
// Vec::new(),
|
||||
// )
|
||||
// .await
|
||||
// }
|
||||
}
|
||||
|
||||
fn cosmwasm_coin_to_cosmos_coin(coin: Coin) -> CosmosCoin {
|
||||
CosmosCoin {
|
||||
denom: coin.denom.parse().unwrap(),
|
||||
|
||||
@@ -1,15 +1,24 @@
|
||||
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::nymd::cosmwasm_client::types::ExecuteResult;
|
||||
use crate::nymd::error::NymdError;
|
||||
use crate::nymd::{NymdClient, SigningCosmWasmClient};
|
||||
use crate::nymd::{Fee, NymdClient, SigningCosmWasmClient};
|
||||
use async_trait::async_trait;
|
||||
use coconut_dkg_common::msg::ExecuteMsg as DkgExecuteMsg;
|
||||
use coconut_dkg_common::msg::QueryMsg as DkgQueryMsg;
|
||||
use coconut_dkg_common::types::Epoch;
|
||||
|
||||
#[async_trait]
|
||||
pub trait DkgClient {
|
||||
async fn get_current_dkg_epoch(&self) -> Result<Epoch, NymdError>;
|
||||
async fn submit_dealing_commitment(
|
||||
&self,
|
||||
epoch_id: u32,
|
||||
dealing_digest: [u8; 32],
|
||||
receivers: u32,
|
||||
fee: Option<Fee>,
|
||||
) -> Result<ExecuteResult, NymdError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -23,4 +32,29 @@ where
|
||||
.query_contract_smart(self.coconut_dkg_contract_address()?, &request)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn submit_dealing_commitment(
|
||||
&self,
|
||||
epoch_id: u32,
|
||||
dealing_digest: [u8; 32],
|
||||
receivers: u32,
|
||||
fee: Option<Fee>,
|
||||
) -> Result<ExecuteResult, NymdError> {
|
||||
let req = DkgExecuteMsg::CommitDealing {
|
||||
epoch_id,
|
||||
dealing_digest,
|
||||
receivers,
|
||||
};
|
||||
|
||||
self.client
|
||||
.execute(
|
||||
self.address(),
|
||||
self.coconut_dkg_contract_address()?,
|
||||
&req,
|
||||
fee.unwrap_or_default(),
|
||||
"dealing commitment",
|
||||
Vec::new(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,13 @@ pub enum ExecuteMsg {
|
||||
bte_key_with_proof: EncodedBTEPublicKeyWithProof,
|
||||
owner_signature: String,
|
||||
},
|
||||
CommitDealing {
|
||||
epoch_id: u32,
|
||||
dealing_digest: [u8; 32],
|
||||
// todo: or maybe list them explicitly, produce digest, etc?
|
||||
receivers: u32,
|
||||
// need to think if anything else is required
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
|
||||
|
||||
@@ -165,3 +165,14 @@ pub fn try_add_dealer(
|
||||
|
||||
Ok(Response::new().set_data(node_index.to_be_bytes()))
|
||||
}
|
||||
|
||||
pub fn try_commit_dealing(
|
||||
mut deps: DepsMut<'_>,
|
||||
env: Env,
|
||||
info: MessageInfo,
|
||||
epoch_id: u32,
|
||||
dealing_digest: [u8; 32],
|
||||
receivers: u32,
|
||||
) -> Result<Response, ContractError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
@@ -62,6 +62,18 @@ pub fn execute(
|
||||
bte_key_with_proof,
|
||||
owner_signature,
|
||||
),
|
||||
ExecuteMsg::CommitDealing {
|
||||
epoch_id,
|
||||
dealing_digest,
|
||||
receivers,
|
||||
} => dealers::transactions::try_commit_dealing(
|
||||
deps,
|
||||
env,
|
||||
info,
|
||||
epoch_id,
|
||||
dealing_digest,
|
||||
receivers,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use tokio::sync::RwLock;
|
||||
use tokio::time::sleep;
|
||||
use validator_client::nymd::cosmwasm_client::types::ExecuteResult;
|
||||
use validator_client::nymd::error::NymdError;
|
||||
use validator_client::nymd::traits::DkgClient;
|
||||
use validator_client::nymd::{
|
||||
@@ -407,13 +408,6 @@ impl<C> Client<C> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_dkg_epoch(&self) -> Result<DkgEpoch, NymdError>
|
||||
where
|
||||
C: SigningCosmWasmClient + Send + Sync,
|
||||
{
|
||||
self.0.read().await.nymd.get_current_dkg_epoch().await
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -432,3 +426,27 @@ where
|
||||
Ok(self.0.read().await.nymd.get_tx(tx_hash).await?)
|
||||
}
|
||||
}
|
||||
|
||||
// dkg-related impl block
|
||||
impl<C> Client<C>
|
||||
where
|
||||
C: SigningCosmWasmClient + Sync + Send,
|
||||
{
|
||||
async fn get_dkg_epoch(&self) -> Result<DkgEpoch, NymdError> {
|
||||
self.0.read().await.nymd.get_current_dkg_epoch().await
|
||||
}
|
||||
|
||||
async fn submit_dealing_commitment(
|
||||
&self,
|
||||
epoch_id: u32,
|
||||
dealing_digest: [u8; 32],
|
||||
receivers: u32,
|
||||
) -> Result<ExecuteResult, NymdError> {
|
||||
self.0
|
||||
.write()
|
||||
.await
|
||||
.nymd
|
||||
.submit_dealing_commitment(epoch_id, dealing_digest, receivers, None)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user