From 3b8c33f50ec69d1b186705bf39cd0b95431f2ded Mon Sep 17 00:00:00 2001 From: "B. Yap" <2826165+b-yap@users.noreply.github.com> Date: Tue, 14 Feb 2023 20:26:39 +0800 Subject: [PATCH] TryFrom `CurrencyId` Implementations Contain Repeated Code (#249) --- primitives/src/lib.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index b3cae42fe..fa0c95e74 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -583,17 +583,8 @@ impl TryFrom<(&str, &str)> for CurrencyId { let issuer_pk = stellar::PublicKey::from_encoding(issuer_encoded) .map_err(|_| "Invalid issuer encoding")?; let issuer: AssetIssuer = *issuer_pk.as_binary(); - if slice.len() <= 4 { - let mut code: Bytes4 = [0; 4]; - code[..slice.len()].copy_from_slice(slice.as_bytes()); - Ok(CurrencyId::AlphaNum4(code, issuer)) - } else if slice.len() > 4 && slice.len() <= 12 { - let mut code: Bytes12 = [0; 12]; - code[..slice.len()].copy_from_slice(slice.as_bytes()); - Ok(CurrencyId::AlphaNum12(code, issuer)) - } else { - Err("More than 12 bytes not supported") - } + + CurrencyId::try_from((value.0, issuer)) } }