Skip to content

Commit

Permalink
feat: allow primitive String type to be used in arc4 methods
Browse files Browse the repository at this point in the history
  • Loading branch information
achidlow committed Mar 18, 2024
1 parent 262c679 commit 23fa701
Show file tree
Hide file tree
Showing 24 changed files with 2,233 additions and 1,745 deletions.
2 changes: 1 addition & 1 deletion examples/sizes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name O0 size O1 size O1 ⏷ O2 size O2 ⏷
abi_routing/Reference 1179 1019 160 1019 0
abi_routing/Reference 1237 1076 161 1076 0
amm/ConstantProductAMM 1213 1113 100 1113 0
application/Reference 175 168 7 168 0
arc-28/EventEmitter 117 77 40 77 0
Expand Down
1 change: 1 addition & 0 deletions src/puya/arc4_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def wtype_to_arc4(wtype: wtypes.WType, loc: SourceLocation | None = None) -> str
| wtypes.application_wtype
| wtypes.uint64_wtype
| wtypes.bool_wtype
| wtypes.string_wtype
):
return wtype.name
case wtypes.bytes_wtype:
Expand Down
6 changes: 4 additions & 2 deletions src/puya/awst/wtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def has_arc4_equivalent_type(wtype: WType) -> bool:
"""
Checks if a non-arc4 encoded type has an arc4 equivalent
"""
if wtype in (bool_wtype, uint64_wtype, bytes_wtype, biguint_wtype):
if wtype in (bool_wtype, uint64_wtype, bytes_wtype, biguint_wtype, string_wtype):
return True

match wtype:
Expand All @@ -535,6 +535,8 @@ def avm_to_arc4_equivalent_type(wtype: WType) -> WType:
return ARC4UIntN.from_scale(512)
if wtype is bytes_wtype:
return arc4_dynamic_bytes
if wtype is string_wtype:
return arc4_string_wtype
if isinstance(wtype, WTuple):
return ARC4Tuple.from_types(types=[avm_to_arc4_equivalent_type(t) for t in wtype.types])
raise InternalError(f"{wtype} does not have an arc4 equivalent type")
Expand All @@ -549,7 +551,7 @@ def arc4_to_avm_equivalent_wtype(arc4_wtype: WType) -> WType:
case ARC4DynamicArray(element_type=ARC4UIntN(n=8)):
return bytes_wtype
if arc4_wtype is arc4_string_wtype:
return bytes_wtype
return bytes_wtype # TODO: this should be string_wtype now
elif arc4_wtype is arc4_bool_wtype:
return bool_wtype

Expand Down
5 changes: 5 additions & 0 deletions test_cases/abi_routing/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Asset,
Bytes,
OnCompleteAction,
String,
TransactionType,
UInt64,
arc4,
Expand Down Expand Up @@ -227,3 +228,7 @@ def method_with_more_than_15_args(
+ u.decode()
+ v.decode()
)

@arc4.abimethod
def hello_with_puyapy_string(self, name: String) -> String:
return "Hello " + name + "!"
2,112 changes: 1,086 additions & 1,026 deletions test_cases/abi_routing/out/Reference.approval.mir

Large diffs are not rendered by default.

Loading

0 comments on commit 23fa701

Please sign in to comment.