[
"autonomous agent",
{
"bounce_fees": {
"base": 10000
},
"init": "{
$BOUNCE_FEE = 10000;
$TYPICAL_FEE = 1000;
$REIMBURSEMENT = $BOUNCE_FEE - $TYPICAL_FEE;
}",
"messages": {
"cases": [
{
"if": "{ trigger.data.owner }",
"init": "{
$owner = trigger.data.owner otherwise bounce("owner field is missing");
$period = trigger.data.period otherwise bounce("period field is missing");
$reference = sha256($owner || $period );
if (var[$reference]) bounce("pension plan already exists");
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{$REIMBURSEMENT}"
}
]
}
},
{
"app": "state",
"state": "{
var[$reference] = 'requested';
var[$reference||'.owner'] = $owner;
var[$reference||'.period'] = $period;
response['reference'] = $reference;
response['status'] = var[$reference];
response['message'] = 'pension plan created';
}"
}
]
},
{
"if": "{
$account = trigger.address;
$deposit = trigger.output[[asset = base]];
$deposit > $BOUNCE_FEE
}",
"messages": [
{
"app": "state",
"state": "{
var[$account] += $deposit;
response['balance'] = var[$account];
response['message'] = 'Added ' || $deposit || ' bytes to the private pension plan';
}"
}
]
},
{
"if": "{ trigger.data.action AND trigger.data.action == 'withdraw' }",
"init": "{
$account = trigger.address;
$balance = var[$account] otherwise bounce("No such account");
$amount = trigger.data.amount otherwise $balance;
if ($amount > $balance) bounce("Invalid withdrawal amount. Maximum balance is " || $balance);
if ($amount <= 0) bounce("Invalid withdrawal amount. Enter a number greater than zero.");
}",
"messages": [
{
"app": "payment",
"payload": {
"outputs": [
{
"address": "{$account}",
"amount": "{$amount}"
},
{
"address": "{$account}",
"amount": "{$REIMBURSEMENT}"
}
]
}
},
{
"app": "state",
"state": "{
var[$account] -= $amount;
}"
}
]
},
{
"init": "{
bounce("Enter a data field: payer, payee, reference or action");
}",
"messages": [
{
"app": "state",
"state": "{
response['usage'] = 'Enter a data field: payer, payee, reference or action';
}"
}
]
}
]
}
}
]