-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
New syntax for contract method calls #859
New syntax for contract method calls #859
Conversation
efdf1f4
to
dd708a0
Compare
409de4c
to
5878ff8
Compare
5878ff8
to
fa23795
Compare
@adlerjohn @nfurfaro FYI - You can check out the new syntax in action in the updated tests :) |
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.
Cool! I noticed in the tests it's generally all or nothing with the contract args? If e.g., coins
was zero can you just leave it out of that map thing?
Actually, I'd like someone to confirm that what I did was correct in the default case. I assumed that the default values (that #298 talks about) are basically the contents of |
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.
The default value for a parameter is extracted from the appropriate special register (
$cgas
forgas
,$bal
forcoins
, and$fp
forasset_id
)
Wait no, those are more for receiving than sending. The defaults should be $cgas
, 0
, and ETH_ID
, in order.
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 think the new syntax looks great @mohammadfawaz ! |
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.
Wait, actually.
Instead of using tag
, can you use branch = "master"
and a Forc lockfile?
#876 should bulk change all the tests right? I'm not really adding any new tests here. |
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.
Oh right it's too early in the morning and I forget that wasn't actually changed yet
Could you update the PR description on how the new ABI syntax will look? Currently it still has the 4 parameters. |
Ha! Good catch. Fixed! |
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.
LGTM -- left one comment
} | ||
|
||
// evaluate the gas to forward to the contract. If no user-specified gas parameter is found, | ||
// simply load $cgas. |
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.
BTW, I think loading $zero
would also be valid here as 0 is shorthand for forwarding all remaining gas. CC @adlerjohn for a correctness check on that
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 merged for now while I can. Will follow up with John on Monday and change if necessary :)
Closes #298
Syntax
Old syntax:
New syntax:
()
when no arguments are required.gas
,coins
, andasset_id
are optional and they can be specified in any order. If a parameter is skipped, its default value is used in theCALL
instruction. The default values forgas
,coins
, andasset_id
are$cgas
,0
, andETH_ID
respectively.ETH_ID
is stored as a compiler constant.caller.send_funs{}(...)
orcaller.send_funds()
.gas
,coins
, orasset_id
is a compile error.Implementation
The implementation is simple:
CALL
instruction as before. Then, create a struct of all user arguments and follow the same flow that is used for user-defined struct.Testing
All contract tests were failing before this change because the hardcoded contract IDs in the calling scripts were outdated (+ some other minor issues). I updated all the required contract IDs here but there are 2 tests that continue to fail (even on
master
), namely:("context_testing_contract", "caller_context_test")
("contract_abi_impl", "contract_call")
Editi. Updated the default values for the parameters.
Generated assembly on the caller side in the default case:
Generated assembly on the caller side in the non-default case: