From fe19c9d243a54115938bff80695a88e0b9755418 Mon Sep 17 00:00:00 2001 From: Arnon Hod Date: Fri, 24 Jan 2025 12:52:17 +0200 Subject: [PATCH] chore: code dedup in felt from bigint (#94) --- crates/starknet-types-core/src/felt/mod.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/crates/starknet-types-core/src/felt/mod.rs b/crates/starknet-types-core/src/felt/mod.rs index 11d99b9..3b8e6d8 100644 --- a/crates/starknet-types-core/src/felt/mod.rs +++ b/crates/starknet-types-core/src/felt/mod.rs @@ -549,15 +549,10 @@ impl From<&BigInt> for Felt { impl From for Felt { fn from(bigint: BigInt) -> Felt { - let (sign, bytes) = bigint.to_bytes_le(); - let felt = Felt::from_bytes_le_slice(&bytes); - if sign == Sign::Minus { - felt.neg() - } else { - felt - } + Self::from(&bigint) } } + impl From<&BigUint> for Felt { fn from(biguint: &BigUint) -> Felt { Felt::from_bytes_le_slice(&biguint.to_bytes_le()) @@ -566,7 +561,7 @@ impl From<&BigUint> for Felt { impl From for Felt { fn from(biguint: BigUint) -> Felt { - Felt::from_bytes_le_slice(&biguint.to_bytes_le()) + Self::from(&biguint) } }