Hi Community,
I am trying to save space by creating a subroutine. I have the same logic applicable to many fields.
Here my subroutine:
@Subroutine(TealType.bytes)
def update_contracts_fields(field):
saved_field = App.globalGet(Bytes(field))
saved_seller_pub = App.globalGet(Bytes(SELLER_PUB))
saved_buyer_pub = App.globalGet(Bytes(BUYER_PUB))
logic = Seq(
Assert(App.globalGet(Bytes(COMMITMENT_STATE)) != Bytes(COMM_STATE_EFFECTIVE)),
# Cond(
#
# ),
Cond(
[ # if currently set to nothing
saved_field == Bytes(""),
Seq( # first input provided by buyer
Assert(Txn.sender() == saved_buyer_pub),
App.globalPut(Bytes(field), Txn.application_args[1]),
)
], # if same value as existing, skips
[saved_field == Txn.application_args[1], Approve()],
[ # if currently set to something the change must be attested
saved_field != Txn.application_args[1],
Seq(
Cond( # if sender is the seller we remove the signature of the buyer, and vice versa
[Txn.sender() == saved_seller_pub, App.globalPut(Bytes(SIGNED_BY_BUYER), Bytes(""))],
[Txn.sender() == saved_buyer_pub, App.globalPut(Bytes(SIGNED_BY_SELLER), Bytes(""))]
), # then we can update the value
App.globalPut(Bytes(field), Txn.application_args[1])
)
]
),
)
return logic
I am trying then o use it as follows:
FIELD_TO_UPDATE = "my_field"
def noop_update_field():
return Seq(update_contracts_fields(FIELD_TO_UPDATE))
And then I get the error in the title.
What am I doing wrong?
Thanks in advance