-
Notifications
You must be signed in to change notification settings - Fork 794
feat(ethers-core/abi): impl AbiArrayType for u8 #1140
Conversation
524ac3f
to
6ff5675
Compare
I am not entirely sure if this is breaking anything or any compat. I defer to experts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is not the right solution here, because now it won't encode fixed length arrays..need to think about this a bit more.
but the right way to fix this is to implement this manually for tuples of u8 impl AbiArrayType for Vec<(u8, u8)> impl AbiArrayType for Vec<(u8, u8, u8)> etc... |
@mattsse wouldn't it still fail when there's some tuple like |
yes this is a limitation and super ugly. we could generate all those variants, I believe there is already a macro for tuples |
Shouldn't ethers-rs/ethers-core/src/abi/mod.rs Lines 159 to 162 in 6ff5675
AbiArrayType for different variant of tuples and on top of that ethers-rs/ethers-core/src/abi/mod.rs Line 93 in 6ff5675
AbiArrayType for Vec<T> ?
which should mean we shouldn't need any of these? impl AbiArrayType for Vec<(u8, u8)> {}
impl AbiArrayType for Vec<(u8, u8, u8)> {} |
Pasting complete error for more context:
I couldn't find this exact trait bound( ethers-rs/ethers-core/src/abi/mod.rs Lines 88 to 92 in a43a9b8
would require for T i.e. (u8, u8) to be trait bounded by AbiArrayType .
which it should be because of this implementation ethers-rs/ethers-core/src/abi/mod.rs Lines 165 to 168 in a43a9b8
now, this implementation in turn bounds the tuple element type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this trait is required because of the special Vec<u8> => Bytes
condition so it's sole purpose is to not be implemented by u8
need some manual impls for u8 tuples unfortunately
} | ||
} | ||
impl<const N: usize> AbiArrayType for [u8; N] {} | ||
impl AbiArrayType for u8 {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this defeats the whole purpose of this trait.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The currently pushed code is certainly wrong. Can you check the comment #1140 (comment) regarding the manual impls for u8 tuples? Also, I don't think we need to implement AbiArrayType
for tuples for fixing this error, tuples already have AbiArrayType
implemented IIUC
ethers-rs/ethers-core/src/abi/mod.rs
Lines 165 to 168 in a43a9b8
impl<$($ty, )+> AbiArrayType for ($($ty,)+) where | |
$( | |
$ty: AbiType, | |
)+ {} |
For the broader issue and source of error #1140 (comment)
interesting, need to check this manually what's going on here |
@meetmangukiya you're of course right: #1143 can you share the whole struct and its derive macros that's causing the issue, perhaps we're generating wrong trait bounds somewhere |
#[derive(
Clone,
Debug,
Default,
Eq,
PartialEq,
ethers :: contract :: EthCall,
ethers :: contract :: EthDisplay,
)]
#[ethcall(
name = "getNextSwapInfo",
abi = "getNextSwapInfo(address[],(uint8,uint8)[])"
)]
pub struct GetNextSwapInfoCall {
pub tokens: ::std::vec::Vec<ethers::core::types::Address>,
pub pairs: ::std::vec::Vec<(u8, u8)>,
} #[derive(
Clone,
Debug,
Default,
Eq,
PartialEq,
ethers :: contract :: EthCall,
ethers :: contract :: EthDisplay,
)]
#[ethcall(
name = "swap",
abi = "swap(address[],(uint8,uint8)[],address,address,uint256[],bytes)"
)]
pub struct SwapCall {
pub tokens: ::std::vec::Vec<ethers::core::types::Address>,
pub pairs_to_swap: ::std::vec::Vec<(u8, u8)>,
pub reward_recipient: ethers::core::types::Address,
pub callback_handler: ethers::core::types::Address,
pub borrow: ::std::vec::Vec<ethers::core::types::U256>,
pub data: ethers::core::types::Bytes,
} |
Just rebased my abigen binary over latest ethers-rs and the generated code compiles fine 💀. I apologise for the wasted time @mattsse. New code looks like #[derive(
Clone,
Debug,
Default,
Eq,
PartialEq,
ethers :: contract :: EthCall,
ethers :: contract :: EthDisplay,
)]
#[ethcall(
name = "getNextSwapInfo",
abi = "getNextSwapInfo(address[],(uint8,uint8)[])"
)]
pub struct GetNextSwapInfoCall {
pub tokens: ::std::vec::Vec<ethers::core::types::Address>,
pub pairs: ::std::vec::Vec<PairIndexes>,
} |
great! |
Motivation
Had a compilation error earlier in abigen:
So implementing it.
Solution
PR Checklist