bigdecimal_ethers_ext/
lib.rs

1mod from_ethers;
2mod to_ethers;
3use crate::from_ethers::{from_ethers_i256, from_ethers_u256, to_big_decimal};
4use crate::to_ethers::{to_ethers_i256, to_ethers_u256};
5use bigdecimal::BigDecimal;
6use ethers::types::{I256, U256};
7
8pub trait BigDecimalEthersExt
9where
10    Self: Sized,
11{
12    fn to_ethers_u256(&self, decimals: u8) -> Option<U256>;
13    fn to_ethers_i256(&self, decimals: u8) -> Option<I256>;
14    fn from_ethers_u256(bn: &U256, decimals: u8) -> Option<Self>;
15    fn from_ethers_i256(bn: &I256, decimals: u8) -> Option<Self>;
16    fn from_bn_string(bn: String, decimals: u8) -> Option<Self>;
17}
18
19impl BigDecimalEthersExt for BigDecimal {
20    fn to_ethers_u256(&self, decimals: u8) -> Option<U256> {
21        to_ethers_u256(self, decimals)
22    }
23
24    fn to_ethers_i256(&self, decimals: u8) -> Option<I256> {
25        to_ethers_i256(self, decimals)
26    }
27
28    fn from_ethers_u256(bn: &U256, decimals: u8) -> Option<Self> {
29        from_ethers_u256(bn, decimals)
30    }
31
32    fn from_ethers_i256(bn: &I256, decimals: u8) -> Option<Self> {
33        from_ethers_i256(bn, decimals)
34    }
35
36    fn from_bn_string(bn: String, decimals: u8) -> Option<Self> {
37        to_big_decimal(bn, decimals)
38    }
39}