I am trying to develop a toy contract akin to the one described here:
I would like the contract to allow the dispersal of funds to one of several addresses, where the number of addresses that are allowed is variable. For example, if the contract was created with 2 arguments, where both of the 2 arguments are account addresses, then either of those addresses would be able to withdraw funds from the account. The PyTeal code looks like:
def contract_prog():
safety_cond = And(
Txn.type_enum() == TxnType.Payment,
Txn.close_remainder_to() == Global.zero_address(),
Txn.rekey_to() == Global.zero_address(),
)
one_receiver = If(
Txn.application_args.length() == Int(1),
Txn.receiver() == Arg(0),
Int(0),
)
two_receivers = If(
Txn.application_args.length() == Int(2),
Or(
Txn.receiver() == Arg(0),
Txn.receiver() == Arg(1),
),
Int(0),
)
three_receivers = If(
Txn.application_args.length() == Int(3),
Or(
Txn.receiver() == Arg(0),
Txn.receiver() == Arg(1),
Txn.receiver() == Arg(2),
),
Int(0),
)
return And(safety_cond, Or(one_receiver, two_receivers, three_receivers))
However, this does not seem to work with the following transaction because the Txn.application_args.length()
appears to always be 0:
{
"lsig": {
"arg": [
"U1BSSElEVDRTRlBXNkJEQVg2UlNHUDRUSVBKQktSNklSNFBLV0dTRlVHNlQ0R1pXVUFJUVhUREJGSQ==",
"VFBVRzc2N0xLUDU2V1VMVFFWVk5HMklFTEw1SU5JQ1AzSkNIWFVYSkwyVVlPUU1aWDVDTlVBVVI1UQ=="
],
"l": "// version 2\nintcblock 1 0\ntxn TypeEnum\nintc_0\n==\ntxn CloseRemainderTo\nglobal ZeroAddress\n==\n&&\ntxn RekeyTo\nglobal ZeroAddress\n==\n&&\ntxn NumAppArgs\nintc_1\n==\n&&\n"
},
"txn": {
"amt": 199999,
"fee": 1000,
"fv": 180,
"gen": "sandnet-v1",
"gh": "oraQ+Ev9huLz3SO+aJquqUSsmM05JFD9YTy/QKzhtcg=",
"lv": 1180,
"rcv": "PG5NPXZNXI52RH5TTVDC4C7EXMMKZ5ERAM2CI75K25GYIUPUPISIWNVJ4E",
"snd": "DHJXPUZXP4RU4E7UUXKTJCWISMPE3FEP5JSLGYH257N5EOH5LOHM3Q2FUQ",
"type": "pay"
}
}
Digging further, it appears that pyteal.Arg
, used by signature contracts, is different than Txn.application_args
, which is only usable by applications. Is there a similar field for signature contracts that allows me to determine the number of arguments being provided? Or is it assumed that signature contracts always have a predefined number of arguments with pyteal.Arg
being used to access them?
Thank you for your time and help.
Best,
Joshua