[
"autonomous agent",
{
"init": "{
$banker = 'JBGMJI7XSKLKNHZF26BUBWHVUZSDV3P5';
$f = 1000;
if(trigger.data.account)
$acct_key = trigger.data.account;
else
$acct_key = '';
$base_key = 'balance_' || trigger.address || $acct_key;
$secret_key = 'secret_' || trigger.address || $acct_key;
$inp = trigger.output[[asset=base]];
}",
"messages": {
"cases": [
{
"if": "{
$secret = trigger.data.secret;
$secret AND trigger.data.receiver AND var[$secret_key] AND sha256($secret) == var[$secret_key]
}",
"messages": [
{
"init": "{
$total = var[$base_key] + $inp - $f;
}",
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.data.receiver}",
"amount": "{$total}"
}
]
}
},
{
"app": "state",
"state": "{
var['total'] = var['total'] - var[$base_key];
var[$base_key] = 0;
var[$secret_key] = false;
response['message'] = 'withdrawn from account ' || $acct_key || ': ' || $total || ' bytes';
}"
}
]
},
{
"if": "{trigger.data.set_proof AND !var[$secret_key]}",
"messages": [
{
"app": "state",
"state": "{
var[$secret_key] = trigger.data.set_proof;
response['sec'] = 'secret set for account' || $acct_key;
var['total'] = var['total'] + $inp;
var[$base_key] = var[$base_key] + $inp;
response['message'] = 'accepted on account ' || $acct_key || ': ' || $inp || ' bytes';
}"
}
]
},
{
"if": "{
$allowed = balance[base] - $inp - var['total'] - $f;
$banker == trigger.address AND trigger.data.withdraw AND $allowed > 0
}",
"messages": [
{
"init": "{
$total = $allowed + $inp;
}",
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{$total}"
}
]
}
}
]
},
{
"messages": [
{
"app": "state",
"state": "{
var['total'] += $inp;
var[$base_key] += $inp;
response['message'] = 'accepted on account '|| $acct_key || ': ' || $inp || ' bytes' ;
}"
}
]
}
]
}
}
]