-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix error in getLogs method #805
Fix error in getLogs method #805
Conversation
When listening on an event filter with a null parameter followed by a non-null parameter, it would keep throwing the error: { code: -32600, message: "data types must start with 0x" }` Turns out params.topics were being encoded as e.g.: "topics": [ ["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b"], [null], [ "0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b", "0x0000000000000000000000000aff3454fce5edbc8cca8697c15331677e6ebccc" ] ] instead of: "topics": [ "0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b", null, [ "0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b", "0x0000000000000000000000000aff3454fce5edbc8cca8697c15331677e6ebccc" ] ] Fix this by flattening the array if there is only one topic in a position.
Thanks. Looking into this now. I'd have thought |
Can you provide an example of how you generated that first filter? |
When I try, I get: const abi = [ "event Transfer(address indexed from, address indexed to, uint value)" ];
const provider = ethers.getDefaultProvider();
const contract = new ethers.Contract("dai.tokens.ethers.eth", abi, provider);
const filter = contract.filters.Transfer(null, to);
console.log(filter);
// { address: 'dai.tokens.ethers.eth',
// topics:
// [ '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
// null,
// '0x000000000000000000000000a5407eae9ba41422680e2e00537571bcc53efbfd' ] } |
(oh wiat... You are finding it happens during serialization... one sec) |
Exactly, if you call |
Perfect. Yes, I've reproduced it and verified it isn't a problem in a. few other places you had me worried about. ;) |
I have merged the fix locally. I'm also pinging a few other people so I can convince myself why |
Thanks so much for looking at this so quickly! In my opinion the spec is too vague on the definition of topics. The best I can find is the note in https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1474.md#parameters-34 Otherwise, topics is only defined as a |
Yeah... I have the same page open now too. "Specification" might be too string a word. :) I'm going to assume null can't be inside a data for now, until I hear back. A few outstanding questions I have are:
But I'll commit these changes for now until I hear back. :) |
(also these are things I plan to address in the ethers docs, so after this research there is some place with the results ;)) |
Thanks again for such a quick turnaround! I see you've already published a new package with the fix included. |
Yes, thanks! Let me know if it works for you. :) Perfect PR, btw. You even named variables the exact same way I do. :) |
Already integrated the new release, works perfectly! |
After looking into the geth sources, I think the API weirdness comes down to how the data is represented by the backend, and the mechanics of JSON encoding in Go. I know very little about Go though, so I could be wrong. Topics are typed as a In Go, A The type
On the other hand, this should work:
|
Shall we close this now that it's fixed? |
Oh yes! Thanks. :) |
When listening on an event filter with a null parameter followed by
a non-null parameter, it would keep throwing the error:
{ code: -32600, message: "data types must start with 0x" }
Turns out params.topics were being encoded as e.g.:
instead of:
Fix this by flattening the array if there is only one topic in a
position.