Definition: [
"autonomous agent",
{
"init": "{
$define = var[trigger.initial_unit] ? false : true;
$i = (var["i"] OTHERWISE 0) || "";
}",
"messages": {
"cases": [
{
"if": "{$define}",
"init": "{
if (trigger.data.cap)
require(is_valid_amount(trigger.data.cap), "Cap is not a valid amount");
}",
"messages": [
{
"app": "asset",
"payload": {
"cases": [
{
"if": "{trigger.data.cap}",
"payload": {
"cap": "{trigger.data.cap}",
"is_private": false,
"is_transferrable": true,
"auto_destroy": false,
"fixed_denominations": false,
"issued_by_definer_only": true,
"cosigned_by_definer": false,
"spender_attested": false
}
},
{
"payload": {
"is_private": false,
"is_transferrable": true,
"auto_destroy": false,
"fixed_denominations": false,
"issued_by_definer_only": true,
"cosigned_by_definer": false,
"spender_attested": false,
"issue_condition": [
"in data feed",
[
[
"{this_address}"
],
"{var[$i || "_" || trigger.address]}",
"=",
"true"
]
]
}
}
]
}
},
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "5L7YJI2SMM5QHLWA3YVRZUSCEOM7NRL7",
"amount": 1000
}
]
}
},
{
"app": "data",
"payload": {
"name": "{trigger.data.name}",
"decimals": "{trigger.data.decimals OTHERWISE 0}"
}
},
{
"app": "data_feed",
"payload": {
"{var[($i OTHERWISE 0) || "_" || trigger.address]}": "true",
"{var[($i OTHERWISE 0) || "_" || this_address]}": "true"
}
},
{
"app": "state",
"state": "{
var["i"]+=1;
var[trigger.unit || "_cap"] = trigger.data.cap;
var[trigger.initial_unit] = response_unit;
}"
}
]
},
{
"messages": [
{
"app": "payment",
"payload": {
"asset": "{var[trigger.initial_unit]}",
"outputs": [
{
"address": "{trigger.initial_address}",
"amount": "{var[trigger.initial_unit || "_cap"] OTHERWISE 1}"
}
]
}
},
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.initial_address}"
}
]
}
},
{
"app": "state",
"state": "{
var[trigger.initial_unit || "_cap"] = false;
}"
}
]
}
]
}
}
]