don't use bigdecimal

This commit is contained in:
Sachin Kamath
2024-03-18 20:26:56 +05:30
parent 377e06daab
commit 1ebb0c7daa
3 changed files with 8 additions and 32 deletions
Generated
-14
View File
@@ -646,19 +646,6 @@ version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b"
[[package]]
name = "bigdecimal"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c06619be423ea5bb86c95f087d5707942791a08a85530df0db2209a3ecfb8bc9"
dependencies = [
"autocfg 1.1.0",
"libm",
"num-bigint",
"num-integer",
"num-traits",
]
[[package]]
name = "binascii"
version = "0.1.4"
@@ -5114,7 +5101,6 @@ version = "1.0.0"
dependencies = [
"anyhow",
"base64 0.13.1",
"bigdecimal",
"bip39",
"bs58 0.5.0",
"cfg-if",
-1
View File
@@ -8,7 +8,6 @@ license.workspace = true
[dependencies]
anyhow = { workspace = true }
base64 = "0.13.0"
bigdecimal = "0.4.2"
bip39 = { workspace = true }
bs58 = { workspace = true }
comfy-table = "6.0.0"
@@ -1,7 +1,6 @@
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use bigdecimal::{BigDecimal, FromPrimitive, ToPrimitive};
use std::cmp::Ordering;
use std::collections::{HashMap, HashSet};
use std::fs;
@@ -10,7 +9,7 @@ use std::fs::OpenOptions;
use clap::Parser;
use comfy_table::Table;
use csv::WriterBuilder;
use log::{info, warn};
use log::info;
use nym_mixnet_contract_common::ExecuteMsg;
use nym_mixnet_contract_common::ExecuteMsg::{DelegateToMixnode, UndelegateFromMixnode};
@@ -65,20 +64,12 @@ impl InputFileReader {
anyhow::bail!("Incorrect format: {}", line);
}
let mix_id = tokens[0].trim().to_string();
let input_amount = BigDecimal::parse_bytes(tokens[1].trim().as_bytes(), 10)
.ok_or_else(|| anyhow::anyhow!("Invalid number format"))?;
let scaled_amount = input_amount.with_scale(6);
let input_amount = tokens[1]
.trim()
.parse::<u128>()
.map_err(|_| anyhow::anyhow!("'{}' has an invalid amount", line))?;
if scaled_amount > BigDecimal::from(1_000_000) {
warn!("Delegation amount is high. Please make sure your input is in NYM and not unym denomination");
}
let smallest_unit_multiplier = BigDecimal::from_u64(1_000_000).unwrap(); // For 6 decimal places
let amount_in_smallest_unit = scaled_amount * smallest_unit_multiplier;
let amount = amount_in_smallest_unit.to_u128().ok_or_else(|| {
anyhow::anyhow!("Amount after scaling cannot be represented in u128")
})?;
let micro_nym_amount = input_amount * 1_000_000;
if !mix_id_set.insert(mix_id.clone()) {
anyhow::bail!("Duplicate mix_id found: {}", mix_id);
@@ -87,7 +78,7 @@ impl InputFileReader {
rows.push(InputFileRow {
mix_id,
amount: Coin {
amount,
amount: micro_nym_amount,
denom: "unym".to_string(),
},
});
@@ -337,7 +328,7 @@ pub async fn delegate_to_multiple_mixnodes(args: Args, client: SigningClient) {
delegation_msgs,
None,
format!(
"Delegatations to {} nodes via nym-cli",
"Delegatation to {} nodes via nym-cli",
undelegation_msgs.len()
),
)