feat(abi): add missing str abi trait impls (#1554)
This commit is contained in:
parent
8026904c3d
commit
71933f0d33
|
@ -77,6 +77,12 @@ impl_abi_codec!(
|
|||
i128
|
||||
);
|
||||
|
||||
impl<'a> AbiEncode for &'a str {
|
||||
fn encode(self) -> Vec<u8> {
|
||||
self.to_string().encode()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: TokenizableItem + Clone, const N: usize> AbiEncode for [T; N] {
|
||||
fn encode(self) -> Vec<u8> {
|
||||
let token = self.into_token();
|
||||
|
@ -266,4 +272,11 @@ mod tests {
|
|||
let tuple: Vec<(Address, u8, Vec<[u8; 4]>)> = vec![(Address::random(), 0, nested)];
|
||||
assert_codec(tuple);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn str_encoding() {
|
||||
let value = "str value";
|
||||
let encoded = value.encode();
|
||||
assert_eq!(value, String::decode(encoded).unwrap());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,6 +163,7 @@ impl_abi_type!(
|
|||
Address => Address,
|
||||
bool => Bool,
|
||||
String => String,
|
||||
str => String,
|
||||
H256 => FixedBytes(32),
|
||||
H512 => FixedBytes(64),
|
||||
U64 => Uint(64),
|
||||
|
@ -180,6 +181,14 @@ impl_abi_type!(
|
|||
I256 => Int(256)
|
||||
);
|
||||
|
||||
impl<'a> AbiType for &'a str {
|
||||
fn param_type() -> ParamType {
|
||||
ParamType::String
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AbiArrayType for &'a str {}
|
||||
|
||||
macro_rules! impl_abi_type_tuple {
|
||||
($num: expr, $( $ty: ident),+) => {
|
||||
impl<$($ty, )+> AbiType for ($($ty,)+) where
|
||||
|
@ -310,6 +319,9 @@ mod tests {
|
|||
ParamType::FixedArray(Box::new(ParamType::Uint(16)), 32),
|
||||
<[u16; 32]>::param_type()
|
||||
);
|
||||
|
||||
assert_eq!(ParamType::String, str::param_type());
|
||||
assert_eq!(ParamType::String, <&str>::param_type());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue