merge
This commit is contained in:
@@ -4,7 +4,6 @@ use crate::error::BackendError;
|
||||
use crate::network::Network;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::convert::TryFrom;
|
||||
use std::ops::{Add, Sub};
|
||||
use std::str::FromStr;
|
||||
use strum::IntoEnumIterator;
|
||||
use validator_client::nymd::CosmosCoin;
|
||||
@@ -54,50 +53,6 @@ pub struct Coin {
|
||||
denom: Denom,
|
||||
}
|
||||
|
||||
// Allows adding minor and major denominations, output will have the LHS denom.
|
||||
impl Add for Coin {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self {
|
||||
let denom = self.denom.clone();
|
||||
let lhs = self.to_minor();
|
||||
let rhs = rhs.to_minor();
|
||||
let lhs_amount = lhs.amount.parse::<u128>().unwrap();
|
||||
let rhs_amount = rhs.amount.parse::<u128>().unwrap();
|
||||
let amount = lhs_amount + rhs_amount;
|
||||
let coin = Coin {
|
||||
amount: amount.to_string(),
|
||||
denom: Denom::Minor,
|
||||
};
|
||||
match denom {
|
||||
Denom::Major => coin.to_major(),
|
||||
Denom::Minor => coin,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Allows adding minor and major denominations, output will have the LHS denom.
|
||||
impl Sub for Coin {
|
||||
type Output = Self;
|
||||
|
||||
fn sub(self, rhs: Self) -> Self {
|
||||
let denom = self.denom.clone();
|
||||
let lhs = self.to_minor();
|
||||
let rhs = rhs.to_minor();
|
||||
let lhs_amount = lhs.amount.parse::<u128>().unwrap();
|
||||
let rhs_amount = rhs.amount.parse::<u128>().unwrap();
|
||||
let amount = lhs_amount - rhs_amount;
|
||||
let coin = Coin {
|
||||
amount: amount.to_string(),
|
||||
denom: Denom::Minor,
|
||||
};
|
||||
match denom {
|
||||
Denom::Major => coin.to_major(),
|
||||
Denom::Minor => coin,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Coin {
|
||||
#[allow(unused)]
|
||||
pub fn major<T: ToString>(amount: T) -> Coin {
|
||||
|
||||
@@ -77,6 +77,7 @@ fn main() {
|
||||
utils::owns_gateway,
|
||||
utils::owns_mixnode,
|
||||
utils::get_env,
|
||||
utils::get_old_and_incorrect_hardcoded_fee,
|
||||
validator_api::status::gateway_core_node_status,
|
||||
validator_api::status::mixnode_core_node_status,
|
||||
validator_api::status::mixnode_inclusion_probability,
|
||||
|
||||
@@ -8,6 +8,7 @@ use mixnet_contract_common::Delegation;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
use validator_client::nymd::{tx, CosmosCoin, Gas, GasPrice};
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[cfg_attr(test, derive(ts_rs::TS))]
|
||||
@@ -65,6 +66,118 @@ pub async fn owns_gateway(
|
||||
.is_some())
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
||||
pub enum Operation {
|
||||
Upload,
|
||||
Init,
|
||||
Migrate,
|
||||
ChangeAdmin,
|
||||
Send,
|
||||
|
||||
BondMixnode,
|
||||
BondMixnodeOnBehalf,
|
||||
UnbondMixnode,
|
||||
UnbondMixnodeOnBehalf,
|
||||
UpdateMixnodeConfig,
|
||||
DelegateToMixnode,
|
||||
DelegateToMixnodeOnBehalf,
|
||||
UndelegateFromMixnode,
|
||||
UndelegateFromMixnodeOnBehalf,
|
||||
|
||||
BondGateway,
|
||||
BondGatewayOnBehalf,
|
||||
UnbondGateway,
|
||||
UnbondGatewayOnBehalf,
|
||||
|
||||
UpdateContractSettings,
|
||||
|
||||
BeginMixnodeRewarding,
|
||||
FinishMixnodeRewarding,
|
||||
|
||||
TrackUnbondGateway,
|
||||
TrackUnbondMixnode,
|
||||
WithdrawVestedCoins,
|
||||
TrackUndelegation,
|
||||
CreatePeriodicVestingAccount,
|
||||
|
||||
AdvanceCurrentInterval,
|
||||
AdvanceCurrentEpoch,
|
||||
WriteRewardedSet,
|
||||
ClearRewardedSet,
|
||||
UpdateMixnetAddress,
|
||||
CheckpointMixnodes,
|
||||
ReconcileDelegations,
|
||||
}
|
||||
|
||||
impl Operation {
|
||||
fn default_gas_limit(&self) -> Gas {
|
||||
match self {
|
||||
Operation::Upload => 3_000_000u64.into(),
|
||||
Operation::Init => 500_000u64.into(),
|
||||
Operation::Migrate => 200_000u64.into(),
|
||||
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(),
|
||||
}
|
||||
}
|
||||
|
||||
fn calculate_fee(gas_price: &GasPrice, gas_limit: Gas) -> CosmosCoin {
|
||||
gas_price * gas_limit
|
||||
}
|
||||
|
||||
fn determine_custom_fee(gas_price: &GasPrice, gas_limit: Gas) -> tx::Fee {
|
||||
let fee = Self::calculate_fee(gas_price, gas_limit);
|
||||
tx::Fee::from_amount_and_gas(fee, gas_limit)
|
||||
}
|
||||
|
||||
fn default_fee(&self, gas_price: &GasPrice) -> tx::Fee {
|
||||
Self::determine_custom_fee(gas_price, self.default_gas_limit())
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_old_and_incorrect_hardcoded_fee(
|
||||
state: tauri::State<'_, Arc<RwLock<State>>>,
|
||||
operation: Operation,
|
||||
) -> Result<Coin, BackendError> {
|
||||
let mut approximate_fee = operation.default_fee(nymd_client!(state).gas_price());
|
||||
// on all our chains it should only ever contain a single type of currency
|
||||
assert_eq!(approximate_fee.amount.len(), 1);
|
||||
let coin: Coin = approximate_fee.amount.pop().unwrap().into();
|
||||
log::info!("hardcoded fee for {:?} is {:?}", operation, coin);
|
||||
Ok(coin.to_major())
|
||||
}
|
||||
|
||||
#[cfg_attr(test, derive(ts_rs::TS))]
|
||||
#[cfg_attr(test, ts(export, export_to = "../src/types/rust/delegationresult.ts"))]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
|
||||
@@ -60,10 +60,10 @@ export const checkGatewayOwnership = async (): Promise<boolean> => {
|
||||
// NOTE: this uses OUTDATED defaults that might have no resemblance with the reality
|
||||
// as for the actual transaction, the gas cost is being simulated beforehand
|
||||
export const getGasFee = async (operation: Operation): Promise<Coin> => {
|
||||
// THIS NO LONGER EXISTS : )
|
||||
// const res: Coin = await invoke('outdated_get_approximate_fee', { operation });
|
||||
// return res;
|
||||
return new Promise(((resolve, reject) => reject()))
|
||||
// current bandaid until `simulation` is properly implemented on the frontend.
|
||||
// This essentially moves the usage of hardcoded values closer to the point of use.
|
||||
const res: Coin = await invoke('get_old_and_incorrect_hardcoded_fee', { operation });
|
||||
return res;
|
||||
};
|
||||
|
||||
export const getInclusionProbability = async (identity: string): Promise<InclusionProbabilityResponse> => {
|
||||
|
||||
Reference in New Issue
Block a user