From 2097ee5fefab30cc540e827e5241083dbd03d225 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Tue, 21 May 2024 17:58:11 +0100 Subject: [PATCH] feat(precompile-utils): implement helper methods --- precompiles/src/solidity/codec/bytes.rs | 16 +++++++++++++++- precompiles/src/solidity/codec/native.rs | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/precompiles/src/solidity/codec/bytes.rs b/precompiles/src/solidity/codec/bytes.rs index d237a3b8b8..26566dea00 100644 --- a/precompiles/src/solidity/codec/bytes.rs +++ b/precompiles/src/solidity/codec/bytes.rs @@ -53,7 +53,7 @@ impl Kind for StringKind { /// The `bytes/string` type of Solidity. /// It is different from `Vec` which will be serialized with padding for each `u8` element /// of the array, while `Bytes` is tightly packed. -#[derive(Debug, Eq, PartialEq)] +#[derive(Debug)] pub struct BoundedBytesString { data: Vec, _phantom: PhantomData<(K, S)>, @@ -68,6 +68,20 @@ impl> Clone for BoundedBytesString { } } +impl PartialEq> for BoundedBytesString { + fn eq(&self, other: &BoundedBytesString) -> bool { + self.data.eq(&other.data) + } +} + +impl Eq for BoundedBytesString {} + +impl Default for BoundedBytesString { + fn default() -> Self { + Vec::default().into() + } +} + impl> BoundedBytesString { pub fn as_bytes(&self) -> &[u8] { &self.data diff --git a/precompiles/src/solidity/codec/native.rs b/precompiles/src/solidity/codec/native.rs index c83eed4d46..dd70874043 100644 --- a/precompiles/src/solidity/codec/native.rs +++ b/precompiles/src/solidity/codec/native.rs @@ -380,3 +380,18 @@ impl From> for Vec { value.inner } } + +impl Default for BoundedVec { + fn default() -> Self { + Self { + inner: Default::default(), + _phantom: PhantomData, + } + } +} + +impl BoundedVec { + pub fn len(&self) -> usize { + self.inner.len() + } +}