[
"autonomous agent",
{
"init": "{
$return_fee = 1000;
$attestor = 'BK54UAWZ6KTI3K7PWH7PRPHVYWTIZZXH';
$attested_user_id = attestation[[attestors=$attestor, address=trigger.address]].user_id;
if (!$attested_user_id) bounce('Your address is not attested by attestor ' || $attestor);
$balance = 'user_id_'||$attested_user_id||'_balance';
}",
"messages": {
"cases": [
{
"if": "{!trigger.data.withdraw}",
"init": "{
if (!attestation[[attestors=$attestor, address=trigger.address]].profile_hash AND !trigger.data.allow_public_attestation) bounce("This address attestation is not private. Anybody can see account associated with your balance. If you still want to continue please add 'allow_public_attestation' data field with any value");
}",
"messages": [
{
"app": "state",
"state": "{
var[$balance] = var[$balance] + trigger.output[[asset=base]];
response['message'] = "Total balance for your account will be " || var[$balance] || " bytes.";
}"
}
]
},
{
"init": "{
if (!var[$balance]) bounce("Your address is attested but the balance for your account is not found");
if (typeof(trigger.data.withdraw)!='number') bounce("Please enter number of bytes in the 'withdraw' data field. The account balance is " || var[$balance] || " bytes");
if (var[$balance] < trigger.data.withdraw) bounce('Not enough funds. The maximum amount you can withdraw for this user_id is ' || var[$balance] || ' bytes');
if (var[$balance] < $return_fee) bounce('Your balance is less than transaction fees. Nothing to return.');
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{trigger.data.withdraw - $return_fee + trigger.output[[asset=base]]}"
}
]
}
},
{
"app": "state",
"state": "{
response['message'] = 'You will receive ' || (trigger.data.withdraw - $return_fee + trigger.output[[asset=base]]) || ' bytes to your account (' || trigger.data.withdraw || ' bytes from your account + '|| trigger.output[[asset=base]] || ' bytes bounced back - '|| $return_fee || ' bytes transaction fee)';
var[$balance] = var[$balance] - trigger.data.withdraw - $return_fee;
}"
}
]
}
]
}
}
]