Skip to content

Commit 14f11b0

Browse files
committed
more explicit uint8ify, add comments
1 parent 765ecb0 commit 14f11b0

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pyteal/ast/abi/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ def type_spec_from_algosdk(t: Union[algosdk.abi.ABIType, str]) -> TypeSpec:
411411
)
412412

413413
match t:
414+
# Currently reference and transaction types are only strings
414415
case str():
415416
if algosdk.abi.is_abi_reference_type(t):
416417
ref_dict: dict[str, TypeSpec] = {

pyteal/ast/itxn.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ def MethodCall(
235235
apps: List[Expr] = []
236236
assets: List[Expr] = []
237237

238+
# Reference types are encoded as a uint8 index into their respective arrays
239+
def get_uint8(i):
240+
return Suffix(Itob(Int(i)), Int(7))
241+
238242
for idx, arg_ts in enumerate(arg_type_specs):
239243
arg = args[idx]
240244

@@ -256,7 +260,7 @@ def MethodCall(
256260
else:
257261
raise TealTypeError(arg, Union[abi.Account, Expr])
258262

259-
app_args.append(Suffix(Itob(Int(len(accts))), Int(7)))
263+
app_args.append(get_uint8(len(accts)))
260264

261265
case abi.ApplicationTypeSpec():
262266
if isinstance(arg, Expr):
@@ -266,11 +270,12 @@ def MethodCall(
266270
else:
267271
raise TealTypeError(arg, Union[abi.Application, Expr])
268272

269-
app_args.append(Suffix(Itob(Int(len(apps))), Int(7)))
273+
app_args.append(get_uint8(len(apps)))
270274

271275
# For assets, add to app_args prior to appending to assets array
272276
case abi.AssetTypeSpec():
273-
app_args.append(Suffix(Itob(Int(len(assets))), Int(7)))
277+
app_args.append(get_uint8(len(assets)))
278+
274279
if isinstance(arg, Expr):
275280
assets.append(arg)
276281
elif isinstance(arg, abi.Asset):

0 commit comments

Comments
 (0)