[
"autonomous agent",
{
"init": "{
$return_fee = 1000;
$balance_key = 'balance_'||trigger.address;
$timestamp_key = 'timestamp_'||trigger.address;
}",
"messages": {
"cases": [
{
"if": "{!trigger.data.return}",
"init": "{
if (!trigger.data.lock_till) bounce("Please add 'lock_till' data field with date format YYYY-MM-DD to deposit bytes or 'return' field with any value to get them back.");
if (typeof(parse_date(trigger.data.lock_till)) != "number") bounce("The format of the 'lock_till' field is YYYY-MM-DD.");
if (var[$balance_key] AND parse_date(trigger.data.lock_till) != var[$timestamp_key]) bounce("This address have been already deposited before with 'lock_till' date set to " || timestamp_to_string(var[$timestamp_key], 'date') || ". You can't change the date. To increase the balance of this address make 'lock_till' date the same as before.");
}",
"messages": [
{
"app": "state",
"state": "{
if (!var[$balance_key])
var[$timestamp_key] = parse_date(trigger.data.lock_till);
var[$balance_key] = var[$balance_key] + trigger.output[[asset=base]];
if (var[$timestamp_key] < timestamp)
response['info'] = "You set 'lock_till' date from the past. You can withdraw at any time.";
if (var[$timestamp_key] > timestamp + 1576800000)
response['info'] = "Your 'lock_till' date is set for more than 50 years!";
response['message'] = "Total balance will be " || var[$balance_key] || " bytes. The bytes will be locked till "|| timestamp_to_string(var[$timestamp_key], 'date') || " 0:00 UTC. 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.";
}"
}
]
},
{
"init": "{
if (!var[$balance_key]) bounce('No bytes to return for this address.');
if (var[$timestamp_key] > timestamp) bounce('The unlock date has not come yet. Bytes are locked till '|| timestamp_to_string(var[$timestamp_key], 'date') || ' 0:00 UTC.');
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{trigger.address}",
"amount": "{ var[$balance_key] - $return_fee + trigger.output[[asset=base]]}"
}
]
}
},
{
"app": "state",
"state": "{
response['message'] = 'You will receive ' || (var[$balance_key] - $return_fee + trigger.output[[asset=base]]) || ' bytes to your account (' || var[$balance_key] || ' bytes will be released - '|| $return_fee || ' bytes transaction fee + ' || trigger.output[[asset=base]] || ' bytes bounced back)';
var[$balance_key] = false;
var[$timestamp_key] = false;
}"
}
]
}
]
}
}
]
Response: {
"responseVars": {
"message": "You will receive 129000 bytes to your account (120000 bytes will be released - 1000 bytes transaction fee + 10000 bytes bounced back)"
}
}
Response: {
"responseVars": {
"message": "Total balance will be 5010000 bytes. The bytes will be locked till 2019-10-01 0:00 UTC. You can withdraw your bytes only from the address you made this deposit: UWR2Z4DP5RZ2TAGLIRAUSWOS2KB6EAPV. Please make a wallet backup and store it in a safe place."
},
"error": "no messages after filtering"
}
Response: {
"responseVars": {
"message": "Total balance will be 120000 bytes. The bytes will be locked till 2019-09-25 0:00 UTC. You can withdraw your bytes only from the address you made this deposit: LYZLXRPL3LM7AMH46ZC6HO4QGD45A6WJ. Please make a wallet backup and store it in a safe place."
},
"error": "no messages after filtering"
}
Response: {
"responseVars": {
"message": "Total balance will be 100000 bytes. The bytes will be locked till 2019-09-25 0:00 UTC. You can withdraw your bytes only from the address you made this deposit: LYZLXRPL3LM7AMH46ZC6HO4QGD45A6WJ. Please make a wallet backup and store it in a safe place."
},
"error": "no messages after filtering"
}
Response: {
"responseVars": {
"message": "Total balance will be 76000 bytes. The bytes will be locked till 2030-02-08 0:00 UTC. 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"
}
Response: {
"responseVars": {
"message": "You will receive 59000 bytes to your account (50000 bytes will be released - 1000 bytes transaction fee + 10000 bytes bounced back)"
}
}
Response: {
"responseVars": {
"info": "You set 'lock_till' date from the past. You can withdraw at any time.",
"message": "Total balance will be 50000 bytes. The bytes will be locked till 2019-09-24 0:00 UTC. 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"
}