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
Contract calls and abigen integration #11
Conversation
// This is a (likely) temporary workaround the fact that | ||
// Sway ABI functions require gas, coin amount, and color arguments | ||
// pre-pending the user-defined function arguments. | ||
// Since these values (gas, coin, color) are configured elsewhere when | ||
// creating a contract instance in the SDK, it would be noisy to keep them | ||
// in the signature of the function that we're expanding here. | ||
// It's the difference between being forced to write: | ||
// contract_instance.increment_counter($gas, $coin, $color, 42) | ||
// versus simply writing: | ||
// contract_instance.increment_counter(42) | ||
// Note that _any_ significant change in the way the JSON ABI is generated | ||
// could affect this function expansion. | ||
if param.name == "gas" || param.name == "coin" || param.name == "color" { | ||
continue; | ||
} |
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.
I removed gas/coin/color from the ABI JSON and hardcoded them in our function selector generator for this. Your solution looks better but we are going to remove these anyways so I'm going to keep my dirty solution 😄
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.
Hahaha, yeah, seems like we both had to come up with dirty solutions for this. It bothers me a little bit, but this (and your approach too) is the simplest one to "revert" once these are removed from the ABI JSON.
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.
Can you guys file issues to go back and remove the hack once the Sway compiler fixes this?
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.
Done #13 and FuelLabs/fuels-ts#71
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 PR introduces the integration of contract calls and the previous
abigen!
functionality.Meaning that, now, the Rust bindings generated from the JSON ABI can build a
script
andscript_data
on the fly and call an ABI method from a deployed contract.This is part of a larger work documented at FuelLabs/sway#124.
Example: