Skip to content
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 calling contracts with structs #80

Merged
merged 2 commits into from
Jan 20, 2022
Merged

Fix calling contracts with structs #80

merged 2 commits into from
Jan 20, 2022

Conversation

AlicanC
Copy link
Contributor

@AlicanC AlicanC commented Dec 14, 2021

No description provided.

@AlicanC AlicanC self-assigned this Dec 14, 2021
@AlicanC AlicanC marked this pull request as ready for review January 20, 2022 20:21
Copy link
Contributor

@QuinnLee QuinnLee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Member

@digorithm digorithm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff! 🔥

Just one clarification comment, but feel free to merge whenever.

@@ -258,19 +310,31 @@ export default class Provider {
request: TransactionRequest;
wait: () => Promise<TransactionResult & { data: Uint8Array }>;
}> {
const dataArray = arrayify(data);
const functionSelector = dataArray.slice(0, 8);
const isStructArg = dataArray.slice(8, 16).some((b) => b === 0x01);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just curious and a bit confused: how come we're confirming it's a struct arg by checking b === 0x01?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an ABI-encoded boolean and we are checking if it has any bytes matching 0x01 in it to see if we should interpret it as true or false.

I was going to make these lines prettier, but I decided to leave a comment instead (and forgot the comment).

I have identified multiple ways to implement this and each one was uglier than the other. Then I realized we only support exactly one argument and when we add support for 0 and 1+ I will have to go over this again. So I just left it like this and will get back to it when it's clear how non-1 args are going to work.

@AlicanC AlicanC merged commit 91ceb6c into master Jan 20, 2022
@AlicanC AlicanC deleted the structs-in-contracts branch January 20, 2022 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants