From adec3e57da37aeb883f8c067f64560285ced5cb0 Mon Sep 17 00:00:00 2001 From: Marcel Ebert Date: Wed, 22 Jan 2025 15:00:41 +0100 Subject: [PATCH] Fix vault client not able to connect due to type mismatch (#576) * Change camelCasing on CurrencyId types * rollback serde modification for Key enum --------- Co-authored-by: Gianfranco --- primitives/src/lib.rs | 55 +++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index fb6dec952..56282e38d 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -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), } @@ -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 { @@ -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") + }, } } @@ -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), } @@ -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 } } @@ -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 } } @@ -694,18 +693,21 @@ impl TryInto 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."), } } @@ -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 { @@ -973,8 +975,9 @@ impl TransactionEnvelopeExt for TransactionEnvelope { fn get_transaction(&self) -> Option { 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, }