Skip to content

Commit

Permalink
call crate BigDecimal method is_positive
Browse files Browse the repository at this point in the history
  • Loading branch information
laruh committed Sep 25, 2024
1 parent 638afd2 commit be1eab0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
7 changes: 2 additions & 5 deletions mm2src/coins/eth/eth_swap_v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use ethereum_types::{Address, U256};
use futures::compat::Future01CompatExt;
use mm2_err_handle::mm_error::MmError;
use mm2_number::BigDecimal;
use num_traits::Signed;
use web3::types::Transaction as Web3Tx;

pub(crate) mod eth_maker_swap_v2;
Expand Down Expand Up @@ -137,17 +138,13 @@ pub(crate) fn validate_from_to_and_status(
Ok(())
}

/// function to check if BigDecimal is a positive value
#[inline(always)]
fn is_positive(amount: &BigDecimal) -> bool { amount > &BigDecimal::from(0) }

// TODO validate premium when add its support in swap_v2
fn validate_payment_args<'a>(
taker_secret_hash: &'a [u8],
maker_secret_hash: &'a [u8],
trading_amount: &BigDecimal,
) -> Result<(), String> {
if !is_positive(trading_amount) {
if !trading_amount.is_positive() {
return Err("trading_amount must be a positive value".to_string());
}
if taker_secret_hash.len() != 32 {
Expand Down
3 changes: 2 additions & 1 deletion mm2src/coins/eth/nft_swap_v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use ethkey::public_to_address;
use futures::compat::Future01CompatExt;
use mm2_err_handle::prelude::{MapToMmResult, MmError, MmResult};
use mm2_number::BigDecimal;
use num_traits::Signed;
use web3::types::TransactionId;

pub(crate) mod errors;
Expand Down Expand Up @@ -580,7 +581,7 @@ fn htlc_params() -> &'static [ethabi::ParamType] {

/// function to check if BigDecimal is a positive integer
#[inline(always)]
fn is_positive_integer(amount: &BigDecimal) -> bool { amount == &amount.with_scale(0) && amount > &BigDecimal::from(0) }
fn is_positive_integer(amount: &BigDecimal) -> bool { amount == &amount.with_scale(0) && amount.is_positive() }

fn validate_payment_args<'a>(
taker_secret_hash: &'a [u8],
Expand Down

0 comments on commit be1eab0

Please sign in to comment.