exposed tauri operations for vesting migrations
This commit is contained in:
committed by
fmtabbara
parent
7d351029a4
commit
b76802e6eb
@@ -8,7 +8,7 @@ repository = ""
|
||||
default-run = "nym_wallet"
|
||||
edition = "2021"
|
||||
build = "src/build.rs"
|
||||
rust-version = "1.58"
|
||||
rust-version = "1.76"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
||||
@@ -155,6 +155,9 @@ pub enum BackendError {
|
||||
|
||||
#[error("This command ({name}) has been removed. Please try to use {alternative} instead.")]
|
||||
RemovedCommand { name: String, alternative: String },
|
||||
|
||||
#[error("there aren't any vesting delegations to migrate")]
|
||||
NoVestingDelegations,
|
||||
}
|
||||
|
||||
impl Serialize for BackendError {
|
||||
|
||||
@@ -129,6 +129,8 @@ fn main() {
|
||||
vesting::bond::withdraw_vested_coins,
|
||||
vesting::delegate::vesting_delegate_to_mixnode,
|
||||
vesting::delegate::vesting_undelegate_from_mixnode,
|
||||
vesting::migrate::migrate_vested_mixnode,
|
||||
vesting::migrate::migrate_vested_delegations,
|
||||
vesting::queries::get_account_info,
|
||||
vesting::queries::get_current_vesting_period,
|
||||
vesting::queries::locked_coins,
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::error::BackendError;
|
||||
use crate::nyxd_client;
|
||||
use crate::state::WalletState;
|
||||
use nym_mixnet_contract_common::ExecuteMsg;
|
||||
use nym_types::transaction::TransactionExecuteResult;
|
||||
use nym_validator_client::nyxd::contract_traits::{
|
||||
MixnetSigningClient, NymContractsProvider, PagedMixnetQueryClient,
|
||||
};
|
||||
use nym_validator_client::nyxd::Fee;
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn migrate_vested_mixnode(
|
||||
fee: Option<Fee>,
|
||||
state: tauri::State<'_, WalletState>,
|
||||
) -> Result<TransactionExecuteResult, BackendError> {
|
||||
let guard = state.read().await;
|
||||
let fee_amount = guard.convert_tx_fee(fee.as_ref());
|
||||
log::info!(">>> migrate vested mixnode, fee = {fee:?}");
|
||||
|
||||
let res = nyxd_client!(state).migrate_vested_mixnode(fee).await?;
|
||||
log::info!("<<< tx hash = {}", res.transaction_hash);
|
||||
log::trace!("<<< {:?}", res);
|
||||
Ok(TransactionExecuteResult::from_execute_result(
|
||||
res, fee_amount,
|
||||
)?)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn migrate_vested_delegations(
|
||||
state: tauri::State<'_, WalletState>,
|
||||
) -> Result<TransactionExecuteResult, BackendError> {
|
||||
log::info!(">>> migrate vested delegations");
|
||||
|
||||
let guard = state.read().await;
|
||||
let client = guard.current_client()?;
|
||||
|
||||
let address = client.nyxd.address();
|
||||
let mixnet_contract = client
|
||||
.nyxd
|
||||
.mixnet_contract_address()
|
||||
.expect("unavailable mixnet contract address");
|
||||
|
||||
log::info!(" >>> Get delegations");
|
||||
let delegations = client
|
||||
.nyxd
|
||||
.get_all_delegator_delegations(&address)
|
||||
.await
|
||||
.inspect_err(|err| {
|
||||
log::error!(" <<< Failed to get delegations. Error: {}", err);
|
||||
})?;
|
||||
log::info!(" <<< {} delegations", delegations.len());
|
||||
|
||||
let vesting_delegations = delegations
|
||||
.into_iter()
|
||||
.filter(|d| d.proxy.is_some())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
log::info!(" <<< {} vesting delegations", vesting_delegations.len());
|
||||
|
||||
if vesting_delegations.is_empty() {
|
||||
return Err(BackendError::NoVestingDelegations);
|
||||
}
|
||||
|
||||
let mut migrate_msgs = Vec::new();
|
||||
for delegation in &vesting_delegations {
|
||||
migrate_msgs.push((
|
||||
ExecuteMsg::MigrateVestedDelegation {
|
||||
mix_id: delegation.mix_id,
|
||||
},
|
||||
Vec::new(),
|
||||
));
|
||||
}
|
||||
|
||||
let res = client
|
||||
.nyxd
|
||||
.execute_multiple(
|
||||
mixnet_contract,
|
||||
migrate_msgs,
|
||||
None,
|
||||
format!(
|
||||
"migrating {} vesting delegations",
|
||||
vesting_delegations.len()
|
||||
),
|
||||
)
|
||||
.await?;
|
||||
|
||||
log::info!("<<< tx hash = {}", res.transaction_hash);
|
||||
log::trace!("<<< {:?}", res);
|
||||
Ok(TransactionExecuteResult::from_execute_result(res, None)?)
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
pub mod bond;
|
||||
pub mod delegate;
|
||||
pub mod migrate;
|
||||
pub mod queries;
|
||||
pub mod rewards;
|
||||
|
||||
Reference in New Issue
Block a user