-
Notifications
You must be signed in to change notification settings - Fork 16
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(internal): Add support for constant value default args in puya #347
base: main
Are you sure you want to change the base?
Conversation
@@ -681,6 +693,18 @@ def _get_abi_signature(subroutine: awst_nodes.ContractMethod, config: ARC4ABIMet | |||
return f"{config.name}({','.join(arg_types)}){return_type}" | |||
|
|||
|
|||
def _is_valid_client_literal_for_arc4_type(literal: str | int, arc4_type_alias: str) -> bool: |
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.
ARC-56 supports any ABI type, and I think ARC-32 did too, but the rules around encoding weren't clear.
So we should probably allow any constant value AVM / ABI value to be used in user code (which also means the default values should be part of AWST?). And then deal with how that value should be encoded into the spec within ARC-32 and ARC-56 code.
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 ARC32 spec only lists int or str (not even bytes) but it's possible the clients actually support more than 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.
Thats where its ambiguous in ARC-32, once encoded in to ARC-32/ ARC-56 it's only a str or int (i.e. it's encoded form in hex/base64 for ARC4 types), but the actual value in the program can be any high level type.
i.e. this should be valid (once python supports kwarg default values)
class MyStruct(arc4.String, frozen=True):
foo: arc4.String
bar: arc4.String
@arc4.abimethod
def foo(
self,
my_struct: MyStruct = MyStruct(arc4.String("foo"), arc4.String("bar")),
) -> None:
...
ARC-32
{
"source": "constant",
/* data is UTF-8 encoded bytes for constant (format not defined in ARC-32)*/
"data": "\\x00\\x04\\x00\\x09\\x03foo\\x03bar"
}
ARC-56 will be something like
{
"source": "literal",
/* data is base64 encoded bytes for constant*/
"data": "AAQACQNmb28DYmFy",
"type": "(string,string)"
}
Proposed Changes