Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
barnjamin committed Apr 22, 2022
1 parent c5815a4 commit c56b462
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
23 changes: 19 additions & 4 deletions pyteal/ast/abi/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
T = TypeVar("T", bound=BaseType)
N = TypeVar("N", bound=int)


class AddressTypeSpec(StaticArrayTypeSpec):
def __init__(self) -> None:
super().__init__(ByteTypeSpec(), ADDRESS_LENGTH)
Expand Down Expand Up @@ -40,16 +41,30 @@ def type_spec(self) -> AddressTypeSpec:
def get(self) -> Expr:
return self.stored_value.load()

def set(self, value: Union[Sequence[T], StaticArray[T, N], ComputedValue[StaticArray[T, N]], "Address", str, Expr]):

def set(
self,
value: Union[
Sequence[T],
StaticArray[T, N],
ComputedValue[StaticArray[T, N]],
"Address",
str,
Expr,
],
):

if isinstance(value, ComputedValue):
if value.produced_type_spec() is not AddressTypeSpec():
raise TealInputError(f"Got ComputedValue with type spec {value.produced_type_spec()}, expected AddressTypeSpec")
raise TealInputError(
f"Got ComputedValue with type spec {value.produced_type_spec()}, expected AddressTypeSpec"
)
return value.store_into(self)

if isinstance(value, BaseType):
if value.type_spec() is not AddressTypeSpec():
raise TealInputError(f"Got {value.__class__} with type spec {value.type_spec()}, expected AddressTypeSpec")
raise TealInputError(
f"Got {value.__class__} with type spec {value.type_spec()}, expected AddressTypeSpec"
)
return self.decode(self.encode())

if isinstance(value, str):
Expand Down
22 changes: 19 additions & 3 deletions pyteal/ast/abi/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
def encoded_string(s: Expr):
return Concat(Suffix(Itob(Len(s)), Int(6)), s)


T = TypeVar("T", bound=BaseType)


class StringTypeSpec(DynamicArrayTypeSpec):
def __init__(self) -> None:
super().__init__(ByteTypeSpec())
Expand Down Expand Up @@ -53,17 +55,31 @@ def get(self) -> Expr:
self.stored_value.load(), Int(Uint16TypeSpec().byte_length_static())
)

def set(self, value: Union[Sequence[T], DynamicArray[T], ComputedValue[DynamicArray[T]], "String", str, Expr]) -> Expr:
def set(
self,
value: Union[
Sequence[T],
DynamicArray[T],
ComputedValue[DynamicArray[T]],
"String",
str,
Expr,
],
) -> Expr:

# Assume length prefixed
if isinstance(value, ComputedValue):
if value.produced_type_spec() is not StringTypeSpec():
raise TealInputError(f"Got ComputedValue with type spec {value.produced_type_spec()}, expected StringTypeSpec")
raise TealInputError(
f"Got ComputedValue with type spec {value.produced_type_spec()}, expected StringTypeSpec"
)
return value.store_into(self)

if isinstance(value, BaseType):
if value.type_spec() is not StringTypeSpec():
raise TealInputError(f"Got {value.__class__} with type spec {value.type_spec()}, expected StringTypeSpec")
raise TealInputError(
f"Got {value.__class__} with type spec {value.type_spec()}, expected StringTypeSpec"
)
return value.decode(value.encode())

# Assume not length prefixed
Expand Down

0 comments on commit c56b462

Please sign in to comment.