updated wallet bonding endpoints

This commit is contained in:
Jędrzej Stuczyński
2023-02-24 16:37:54 +00:00
parent 1216eb94c5
commit 440c1e5fa3
5 changed files with 67 additions and 19 deletions
@@ -43,7 +43,7 @@ pub trait VestingSigningClient {
async fn vesting_bond_gateway(
&self,
gateway: Gateway,
owner_signature: &str,
owner_signature: String,
pledge: Coin,
fee: Option<Fee>,
) -> Result<ExecuteResult, NyxdError>;
@@ -61,7 +61,7 @@ pub trait VestingSigningClient {
&self,
mix_node: MixNode,
cost_params: MixNodeCostParams,
owner_signature: &str,
owner_signature: String,
pledge: Coin,
fee: Option<Fee>,
) -> Result<ExecuteResult, NyxdError>;
@@ -208,14 +208,14 @@ impl<C: SigningCosmWasmClient + Sync + Send + Clone> VestingSigningClient for Ny
async fn vesting_bond_gateway(
&self,
gateway: Gateway,
owner_signature: &str,
owner_signature: String,
pledge: Coin,
fee: Option<Fee>,
) -> Result<ExecuteResult, NyxdError> {
let fee = fee.unwrap_or(Fee::Auto(Some(self.simulated_gas_multiplier)));
let req = VestingExecuteMsg::BondGateway {
gateway,
owner_signature: owner_signature.to_string(),
owner_signature,
amount: pledge.into(),
};
self.client
@@ -272,7 +272,7 @@ impl<C: SigningCosmWasmClient + Sync + Send + Clone> VestingSigningClient for Ny
&self,
mix_node: MixNode,
cost_params: MixNodeCostParams,
owner_signature: &str,
owner_signature: String,
pledge: Coin,
fee: Option<Fee>,
) -> Result<ExecuteResult, NyxdError> {
@@ -281,7 +281,7 @@ impl<C: SigningCosmWasmClient + Sync + Send + Clone> VestingSigningClient for Ny
VestingExecuteMsg::BondMixnode {
mix_node,
cost_params,
owner_signature: owner_signature.to_string(),
owner_signature,
amount: pledge.into(),
},
vec![],
+1 -2
View File
@@ -1,6 +1,5 @@
use nym_contracts_common::signing::SigningAlgorithm;
use nym_crypto::asymmetric::identity;
use nym_crypto::asymmetric::identity::{Ed25519RecoveryError, SignatureError};
use nym_crypto::asymmetric::identity::{self, Ed25519RecoveryError, SignatureError};
use nym_types::error::TypesError;
use nym_wallet_types::network::Network;
use serde::{Serialize, Serializer};
@@ -3,7 +3,6 @@
use crate::error::BackendError;
use async_trait::async_trait;
use cosmrs::AccountId;
use cosmwasm_std::Addr;
use nym_contracts_common::signing::{
ContractMessageContent, MessageSignature, Nonce, SignableMessage, SigningAlgorithm,
@@ -2,7 +2,9 @@
// SPDX-License-Identifier: Apache-2.0
use crate::error::BackendError;
use crate::operations::helpers::verify_mixnode_bonding_sign_payload;
use crate::operations::helpers::{
verify_gateway_bonding_sign_payload, verify_mixnode_bonding_sign_payload,
};
use crate::state::WalletState;
use crate::{nyxd_client, Gateway, MixNode};
use nym_contracts_common::signing::MessageSignature;
@@ -28,7 +30,7 @@ pub struct NodeDescription {
pub async fn bond_gateway(
gateway: Gateway,
pledge: DecCoin,
owner_signature: String,
msg_signature: MessageSignature,
fee: Option<Fee>,
state: tauri::State<'_, WalletState>,
) -> Result<TransactionExecuteResult, BackendError> {
@@ -43,10 +45,20 @@ pub async fn bond_gateway(
pledge_base,
fee,
);
let res = guard
.current_client()?
let client = guard.current_client()?;
// check the signature to make sure the user copied it correctly
if let Err(err) =
verify_gateway_bonding_sign_payload(client, &gateway, &pledge_base, false, &msg_signature)
.await
{
log::warn!("failed to verify provided gateway bonding signature: {err}");
return Err(err);
}
let res = client
.nyxd
.bond_gateway(gateway, owner_signature, pledge_base, fee)
.bond_gateway(gateway, msg_signature.as_bs58_string(), pledge_base, fee)
.await?;
log::info!("<<< tx hash = {}", res.transaction_hash);
log::trace!("<<< {:?}", res);
@@ -105,7 +117,8 @@ pub async fn bond_mixnode(
)
.await
{
todo!()
log::warn!("failed to verify provided mixnode bonding signature: {err}");
return Err(err);
}
let res = client
@@ -2,8 +2,12 @@ use crate::error::BackendError;
use crate::nyxd_client;
use crate::state::WalletState;
use crate::{Gateway, MixNode};
use nym_contracts_common::signing::MessageSignature;
use nym_mixnet_contract_common::MixNodeConfigUpdate;
use crate::operations::helpers::{
verify_gateway_bonding_sign_payload, verify_mixnode_bonding_sign_payload,
};
use nym_types::currency::DecCoin;
use nym_types::mixnode::MixNodeCostParams;
use nym_types::transaction::TransactionExecuteResult;
@@ -13,7 +17,7 @@ use validator_client::nyxd::{Fee, VestingSigningClient};
pub async fn vesting_bond_gateway(
gateway: Gateway,
pledge: DecCoin,
owner_signature: String,
msg_signature: MessageSignature,
fee: Option<Fee>,
state: tauri::State<'_, WalletState>,
) -> Result<TransactionExecuteResult, BackendError> {
@@ -28,10 +32,20 @@ pub async fn vesting_bond_gateway(
pledge_base,
fee,
);
let client = guard.current_client()?;
// check the signature to make sure the user copied it correctly
if let Err(err) =
verify_gateway_bonding_sign_payload(client, &gateway, &pledge_base, true, &msg_signature)
.await
{
log::warn!("failed to verify provided gateway bonding signature: {err}");
return Err(err);
}
let res = guard
.current_client()?
.nyxd
.vesting_bond_gateway(gateway, &owner_signature, pledge_base, fee)
.vesting_bond_gateway(gateway, msg_signature.as_bs58_string(), pledge_base, fee)
.await?;
log::info!("<<< tx hash = {}", res.transaction_hash);
log::trace!("<<< {:?}", res);
@@ -63,7 +77,7 @@ pub async fn vesting_unbond_gateway(
pub async fn vesting_bond_mixnode(
mixnode: MixNode,
cost_params: MixNodeCostParams,
owner_signature: String,
msg_signature: MessageSignature,
pledge: DecCoin,
fee: Option<Fee>,
state: tauri::State<'_, WalletState>,
@@ -81,10 +95,33 @@ pub async fn vesting_bond_mixnode(
pledge_base,
fee
);
let client = guard.current_client()?;
// check the signature to make sure the user copied it correctly
if let Err(err) = verify_mixnode_bonding_sign_payload(
client,
&mixnode,
&cost_params,
&pledge_base,
true,
&msg_signature,
)
.await
{
log::warn!("failed to verify provided mixnode bonding signature: {err}");
return Err(err);
}
let res = guard
.current_client()?
.nyxd
.vesting_bond_mixnode(mixnode, cost_params, &owner_signature, pledge_base, fee)
.vesting_bond_mixnode(
mixnode,
cost_params,
msg_signature.as_bs58_string(),
pledge_base,
fee,
)
.await?;
log::info!("<<< tx hash = {}", res.transaction_hash);
log::trace!("<<< {:?}", res);