You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was happy to find this crate, because I thought I can decode the response from the emitted events, but I encountered some problems.
First of all the from_reader function is removed in the 4th version of the library but the tutorial still contains it. It would be good to have an easy to read in ABI function. For example I created this for myself:
pub fn read_abi_from_file(p: &str) -> Result<Abi, anyhow::Error> {
// Open the file in read-only mode with buffer.
let path = Path::new(&p);
let file = File::open(path)?;
let reader = BufReader::new(file);
// Read the JSON contains the ABI
let abi = serde_json::from_reader(reader)?;
// Return the `User`.
Ok(abi)
}
But the bigger problem just came later. When I tried to use decode_log_from_slice function. I'm using web3 to listen for the event stream and it works great, but its getting a Vec and this library neads &[H256]. Okay I checked the compiler and told me I need primitive_types::H256. Still wrote me a weird error message:
Okay I checked the library's toml file and I found out it used ethereum_types, so I just copied and put into my toml. Did the weird type conversation like:
let topic0 = log.clone().unwrap().topics[0].to_fixed_bytes();
let topic1 = log.clone().unwrap().topics[1].to_fixed_bytes();
let topic2 = log.clone().unwrap().topics[2].to_fixed_bytes();
let topics: &[ethereum_types::H256] = &[
ethereum_types::H256::from_slice(&topic0),
ethereum_types::H256::from_slice(&topic1),
ethereum_types::H256::from_slice(&topic2),
];
And I got the error again:
= note: expected reference `&[primitive_types::H256]`
found reference `&[ethereum_types::H256]`
I can second all of this step by step. I faced the same issue of confusion of type H256 between ethereum_types and primitive_types. I am trying to use this library to listen to a stream of Event from a smart contract.
Was about to make an issue for the inexisten ABI::from_reader function and found this issue, so I am just dropping this small repo as reproduction for it: https://github.com/TAnas0/rust-ethereum-abi-bug
This question was asked 3 months ago, so I am not holding my breath.
Also got confused with inconsistency of ethereum-types and primitive-types version of U256.
Finally found that when using standard crate ethereum_abi version 0.4.0 then it is necessary to specify outdated version of ethereum-types 0.13.1:
[dependencies]
ethereum_abi = "0.4.0"ethereum-types = { version = "0.13.1", default-features = false, features = ["std"] }
Another option is to check out the latest not released version of ethereum_abi from git into separate folder and use local crate along with actual version of ethereum-types:
Hello!
I was happy to find this crate, because I thought I can decode the response from the emitted events, but I encountered some problems.
First of all the from_reader function is removed in the 4th version of the library but the tutorial still contains it. It would be good to have an easy to read in ABI function. For example I created this for myself:
But the bigger problem just came later. When I tried to use decode_log_from_slice function. I'm using web3 to listen for the event stream and it works great, but its getting a Vec and this library neads &[H256]. Okay I checked the compiler and told me I need primitive_types::H256. Still wrote me a weird error message:
Okay I checked the library's toml file and I found out it used ethereum_types, so I just copied and put into my toml. Did the weird type conversation like:
And I got the error again:
I would suggest to have a new function what can handle web3 types for the topics Vec and also the Bytes one
https://docs.rs/web3/0.18.0/web3/types/struct.Log.html
If that would be implemented decoding the events would be so easy. Thank you if you considering it.
The text was updated successfully, but these errors were encountered: