[
"autonomous agent",
{
"init": "{
$release_fee = 1000;
$balance_key = 'balance_'||trigger.address;
$timestamp_key = 'timestamp_'||trigger.address;
}",
"messages": {
"cases": [
{
"if": "{trigger.data.keep}",
"init": "{
if(!trigger.data.seconds AND !var[$balance_key]) bounce("Please add 'seconds' data field with number of seconds to lock the bytes.");
if(trigger.data.seconds AND typeof(trigger.data.seconds) != "number") bounce("Only numbers are allowed in the 'seconds' field.");
}",
"messages": [
{
"app": "state",
"state": "{
if(trigger.data.seconds AND !var[$balance_key])
$release_timestamp = timestamp + trigger.data.seconds;
var[$balance_key] = (var[$balance_key]? var[$balance_key]:0) + trigger.output[[asset=base]];
response['message'] = "Total number of keeped bytes will be "|| var[$balance_key] || " bytes. The bytes will be locked for "|| trigger.data.seconds || " seconds. The release date is "|| timestamp_to_string($release_timestamp, 'datetime') || ". You can withdraw your bytes only from the address you made this deposit: " || trigger.address || ". Please make a wallet backup and store it in a safe place.";
var[$timestamp_key] = $release_timestamp;
}"
}
]
},
{
"if": "{trigger.data.release}",
"init": "{
if(!var[$balance_key]) bounce('No bytes to release for this address.');
if(var[$timestamp_key] > timestamp) bounce('The release date has not come yet. Bytes are locked till '||timestamp_to_string(var[$timestamp_key], 'datetime'));
if(var[$balance_key] <= $release_fee) bounce('Bytes amount is less than ' || $release_fee || ' bytes fee.');
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{ var[$balance_key] - $release_fee}"
}
]
}
},
{
"app": "state",
"state": "{
response['message'] = var[$balance_key] || ' bytes will be released. Transaction fee is ' || $release_fee || ' bytes. You will receive ' || var[$balance_key] - $release_fee || ' bytes to your account.';
var[$balance_key] = false;
var[$timestamp_key] = false;
}"
}
]
},
{
"messages": [
{
"app": "state",
"state": "{
bounce("Welcome user! If you want to store your bytes please add 'keep' data field with any value and 'seconds' data field with number of seconds the bytes will be locked. If you want to withdraw previously deposited bytes add 'release' data field. Otherwise the transaction will be bounced.");
}"
}
]
}
]
}
}
]
Response: {
"responseVars": {
"message": "Total number of keeped bytes will be 20000 bytes. The bytes will be locked for 1200 seconds. The release date is 2019-09-11T16:53:59Z. You can withdraw your bytes only from the address you made this deposit: IGCQMNDBDDP6626C4MZA6AM3V4RKVFUQ. Please make a wallet backup and store it in a safe place."
},
"error": "no messages after filtering"
}