-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat: add Into
for Address
and ContractId
fn arguments
#967
Conversation
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.
A question on design
packages/fuels-code-gen/src/program_bindings/abigen/bindings/function_generator.rs
Outdated
Show resolved
Hide resolved
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 feel like this would enable the user to pass in an Address
to a method that normally only accepts ContractId
without being explicit about it, and this is not something we want. It needs to be explicit, because the difference between Address
and ContractId
is fundamental and can lead to a loss of fund IIUC. Am I getting this wrong?
You are right. Normally it would not be a problem to have a The only other thing that comes to mind is to have methods accept @FuelLabs/sdk-rust what are you thoughts on this? I am leaning towards leaving it as is and closing this PR. |
What about replacing the usages of So you can then give both an You'd retain type safety since neither You'd still have pure addresses nested in generated structs and enums, since using |
I would like the |
This is a great idea! ❤️ I did a quick first implementation and it works as expected. We retain the type safety as you said. @iqdecay you said:
We turn it back to an |
packages/fuels-code-gen/src/program_bindings/abigen/bindings/function_generator.rs
Outdated
Show resolved
Hide resolved
What I meant is I think that rather than changing this implementation detail, we should re-explore why we are exposing two types of addresses at all. Fixing this seems like a bandaid to the more general problem of exposing two types of addresses instead of handling them both under the hood. This particular fix is moreover not the one requested by user (because the one requested by users is a gateway to a footgun), so we don't actuallly need to do it IMO. |
I agree but what you say is above this request. The user wanted a nice UI where he can give either |
Ah yes you're right mb |
I'm sorry but I really don't want to merge anything before the |
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.
Good stuff.
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.
👍
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.
nice!
Thank you hal3e, very cool |
Could we not determine if it's a contract or address at run-time and avoid casting it altogether? Casting it only at runtime for the pieces that must know |
If I give you an address 0x123....789, and I say to send it 10 ETH, is it fair to say you could get an error depending on if it's a contractId or an address, so you would need to ask me a follow-up, is it an address or a contract. Well a multisig is a contract, but I could see someone making that mistake. It seems like we're building a 'gotcha' into the sway stack that could be avoided entirely if we just abstract all of this into a run-time check (if possible, if not possible currently then add a flag to each address?) |
This is a good argument I agree, but this is not the right place to discuss it, this issue is. This design decision is not ours, and even if we wanted we cannot change it, it's in Sway. |
closes: #962
Our
FunctionGenerator
now generatesimpl Into<Bech32Address>
andimpl Into<Bech32ContractId>
instead ofAddress
andContractId
.This is reflected on all
contract
methods,predicate
encode functions, andscript
main functions.Checklist