[
"autonomous agent",
{
"init": "{
// Attest
$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.public!='allow') bounce("This address attestation is not private. Anybody can see account associated with your balance. If you still want to continue please add 'public' data field with value 'allow'");
}",
"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 numbers of bytes you want to withdraw from your account");
if (var[$balance] + trigger.output[[asset=base]] < trigger.data.withdraw + $return_fee) bounce('Not enough funds. The maximum amount you can withdraw for this user_id is ' || var[$balance] - $return_fee || 'bytes');
}",
"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 will be released - '|| $return_fee || ' bytes transaction fee + ' || trigger.output[[asset=base]] || ' bytes bounced back)';
var[$balance] = var[$balance] - trigger.data.withdraw - $return_fee;
}"
}
]
}
]
}
}
]