Skip to content

Commit

Permalink
Fix vault client not able to connect due to type mismatch (#576)
Browse files Browse the repository at this point in the history
* Change camelCasing on CurrencyId types

* rollback serde modification for Key enum

---------

Co-authored-by: Gianfranco <[email protected]>
  • Loading branch information
ebma and gianfra-t authored Jan 22, 2025
1 parent 1df6677 commit adec3e5
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ pub mod oracle {
#[derive(
Encode, Decode, Clone, Eq, PartialEq, Debug, TypeInfo, MaxEncodedLen, Serialize, Deserialize,
)]
//#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
pub enum Key {
ExchangeRate(CurrencyId),
}
Expand Down Expand Up @@ -465,7 +465,7 @@ pub fn remove_trailing_non_alphanum_bytes(input: &[u8]) -> &[u8] {
scale_decode::DecodeAsType,
scale_encode::EncodeAsType,
)]
//#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
#[repr(u8)]
#[allow(clippy::unnecessary_cast)]
pub enum Asset {
Expand All @@ -478,10 +478,12 @@ impl CurrencyInfo for Asset {
fn name(&self) -> &str {
match self {
Asset::StellarNative => "Stellar",
Asset::AlphaNum4 { code, issuer: _ } =>
from_utf8(remove_trailing_non_alphanum_bytes(code)).unwrap_or("unspecified"),
Asset::AlphaNum12 { code, issuer: _ } =>
from_utf8(remove_trailing_non_alphanum_bytes(code)).unwrap_or("unspecified"),
Asset::AlphaNum4 { code, issuer: _ } => {
from_utf8(remove_trailing_non_alphanum_bytes(code)).unwrap_or("unspecified")
},
Asset::AlphaNum12 { code, issuer: _ } => {
from_utf8(remove_trailing_non_alphanum_bytes(code)).unwrap_or("unspecified")
},
}
}

Expand Down Expand Up @@ -529,15 +531,10 @@ impl Asset {
#[allow(clippy::unnecessary_cast)]
pub enum CurrencyId {
#[default]
#[serde(rename = "Native")]
Native = 0_u8,
#[serde(rename = "XCM")]
XCM(u8),
#[serde(rename = "Stellar")]
Stellar(Asset),
#[serde(rename = "ZenlinkLPToken")]
ZenlinkLPToken(u8, u8, u8, u8),
#[serde(rename = "Token")]
Token(u64),
}

Expand Down Expand Up @@ -586,8 +583,9 @@ impl DecimalsLookup for PendulumDecimalsLookup {
_ => 12,
},
// We assume that all other assets have 12 decimals
CurrencyId::Native | CurrencyId::ZenlinkLPToken(_, _, _, _) | CurrencyId::Token(_) =>
12,
CurrencyId::Native | CurrencyId::ZenlinkLPToken(_, _, _, _) | CurrencyId::Token(_) => {
12
},
}) as u32
}
}
Expand All @@ -607,8 +605,9 @@ impl DecimalsLookup for AmplitudeDecimalsLookup {
_ => 12,
},
// We assume that all other assets have 12 decimals
CurrencyId::Native | CurrencyId::ZenlinkLPToken(_, _, _, _) | CurrencyId::Token(_) =>
12,
CurrencyId::Native | CurrencyId::ZenlinkLPToken(_, _, _, _) | CurrencyId::Token(_) => {
12
},
}) as u32
}
}
Expand Down Expand Up @@ -694,18 +693,21 @@ impl TryInto<stellar::Asset> for CurrencyId {
Self::XCM(_currency_id) => Err("XCM Foreign Asset not defined in the Stellar world."),
Self::Native => Err("PEN token not defined in the Stellar world."),
Self::StellarNative => Ok(stellar::Asset::native()),
Self::Stellar(Asset::AlphaNum4 { code, issuer }) =>
Self::Stellar(Asset::AlphaNum4 { code, issuer }) => {
Ok(stellar::Asset::AssetTypeCreditAlphanum4(AlphaNum4 {
asset_code: code,
issuer: PublicKey::PublicKeyTypeEd25519(issuer),
})),
Self::Stellar(Asset::AlphaNum12 { code, issuer }) =>
}))
},
Self::Stellar(Asset::AlphaNum12 { code, issuer }) => {
Ok(stellar::Asset::AssetTypeCreditAlphanum12(AlphaNum12 {
asset_code: code,
issuer: PublicKey::PublicKeyTypeEd25519(issuer),
})),
Self::ZenlinkLPToken(_, _, _, _) =>
Err("Zenlink LP Token not defined in the Stellar world."),
}))
},
Self::ZenlinkLPToken(_, _, _, _) => {
Err("Zenlink LP Token not defined in the Stellar world.")
},
Self::Token(_) => Err("Token not defined in the Stellar world."),
}
}
Expand Down Expand Up @@ -943,9 +945,9 @@ impl TransactionEnvelopeExt for TransactionEnvelope {
if payment.claimants.len() == 1 {
let Claimant::ClaimantTypeV0(claimant) = &payment.claimants.get_vec()[0];

if claimant.destination.eq(&recipient_account_pk) &&
payment.asset == asset && claimant.predicate ==
ClaimPredicate::ClaimPredicateUnconditional
if claimant.destination.eq(&recipient_account_pk)
&& payment.asset == asset && claimant.predicate
== ClaimPredicate::ClaimPredicateUnconditional
{
acc.saturating_add(payment.amount)
} else {
Expand Down Expand Up @@ -973,8 +975,9 @@ impl TransactionEnvelopeExt for TransactionEnvelope {

fn get_transaction(&self) -> Option<Transaction> {
match self {
TransactionEnvelope::EnvelopeTypeTxV0(transaction) =>
Some(transaction.tx.clone().into()),
TransactionEnvelope::EnvelopeTypeTxV0(transaction) => {
Some(transaction.tx.clone().into())
},
TransactionEnvelope::EnvelopeTypeTx(transaction) => Some(transaction.tx.clone()),
_ => None,
}
Expand Down

0 comments on commit adec3e5

Please sign in to comment.