Skip to content

Commit

Permalink
Modify DecimalsLookup trait, add PINK, HDX, vDOT to decimals list (#523)
Browse files Browse the repository at this point in the history
* Modify DecimalsLookup trait, add PINK to decimals list

* Add HDX and vDOT to decimals list, use Self on decimals function impls

* Fmt with nightly

* Nightly fmt
  • Loading branch information
bogdanS98 authored May 9, 2024
1 parent 1c3ea1c commit e7a672b
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ pub trait CurrencyInfo {
pub fn remove_trailing_non_alphanum_bytes(input: &[u8]) -> &[u8] {
for (idx, elem) in input.iter().enumerate().rev() {
if elem.is_ascii_alphanumeric() {
return &input[..=idx]
return &input[..=idx];
}
}
b""
Expand Down Expand Up @@ -498,9 +498,9 @@ pub enum CurrencyId {
pub trait DecimalsLookup {
type CurrencyId;

fn decimals(currency_id: CurrencyId) -> u32;
fn decimals(currency_id: Self::CurrencyId) -> u32;

fn one(currency_id: CurrencyId) -> Balance {
fn one(currency_id: Self::CurrencyId) -> Balance {
10u128.pow(Self::decimals(currency_id))
}
}
Expand All @@ -513,7 +513,7 @@ pub struct PendulumDecimalsLookup;
impl DecimalsLookup for PendulumDecimalsLookup {
type CurrencyId = CurrencyId;

fn decimals(currency_id: CurrencyId) -> u32 {
fn decimals(currency_id: Self::CurrencyId) -> u32 {
(match currency_id {
CurrencyId::Stellar(asset) => asset.decimals(),
CurrencyId::XCM(index) => match index {
Expand All @@ -531,6 +531,12 @@ impl DecimalsLookup for PendulumDecimalsLookup {
5 => 12,
// GLMR
6 => 18,
// PINK
7 => 10,
// HDX
8 => 12,
// vDOT
9 => 10,
_ => 12,
},
// We assume that all other assets have 12 decimals
Expand All @@ -544,7 +550,7 @@ pub struct AmplitudeDecimalsLookup;
impl DecimalsLookup for AmplitudeDecimalsLookup {
type CurrencyId = CurrencyId;

fn decimals(currency_id: CurrencyId) -> u32 {
fn decimals(currency_id: Self::CurrencyId) -> u32 {
(match currency_id {
CurrencyId::Stellar(asset) => asset.decimals(),
CurrencyId::XCM(index) => match index {
Expand Down Expand Up @@ -606,11 +612,11 @@ impl TryFrom<(&str, AssetIssuer)> for CurrencyId {
if slice.len() <= 4 {
let mut code: Bytes4 = [0; 4];
code[..slice.len()].copy_from_slice(slice.as_bytes());
return Ok(CurrencyId::AlphaNum4(code, issuer))
return Ok(CurrencyId::AlphaNum4(code, issuer));
} else if slice.len() <= 12 {
let mut code: Bytes12 = [0; 12];
code[..slice.len()].copy_from_slice(slice.as_bytes());
return Ok(CurrencyId::AlphaNum12(code, issuer))
return Ok(CurrencyId::AlphaNum12(code, issuer));
} else {
Err("More than 12 bytes not supported")
}
Expand Down Expand Up @@ -871,7 +877,7 @@ impl TransactionEnvelopeExt for TransactionEnvelope {
};

if tx_operations.len() == 0 {
return BalanceConversion::unlookup(transferred_amount)
return BalanceConversion::unlookup(transferred_amount);
}

transferred_amount = tx_operations.iter().fold(0i64, |acc, x| {
Expand Down

0 comments on commit e7a672b

Please sign in to comment.