[
"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.unlock_date) bounce("Welcome user! Please add 'unlock_date' data field with date format YYYY-MM-DD to deposit bytes or 'return' data field with any value to withdraw.");
if (typeof(parse_date(trigger.data.unlock_date)) != "number") bounce("The format of the 'unlock_date' field is YYYY-MM-DD.");
if (var[$balance_key] AND parse_date(trigger.data.unlock_date) != var[$timestamp_key]) bounce("This address have been already deposited before with 'unlock_date' set to " || timestamp_to_string(var[$timestamp_key], 'date') || ". You can't change the date. To increase the balance of this address make 'unlock_date' data field the same as before.");
}",
"messages": [
{
"app": "state",
"state": "{
if (!var[$balance_key])
var[$timestamp_key] = parse_date(trigger.data.unlock_date);
var[$balance_key] = var[$balance_key] + trigger.output[[asset=base]];
if (var[$timestamp_key] < timestamp)
response['info'] = "You set 'unlock_date' from the past. You can withdraw at any time.";
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.'); // It is ' || (var[$timestamp_key] - timestamp)/86400 || ' days ' || (var[$timestamp_key] - timestamp)/3600) || ' hours' || (var[$timestamp_key] - timestamp)/60 || ' minutes left.' );
//if (var[$balance_key] <= $return_fee) bounce("Warning! Bytes balance amount is less than ' || $return_fee || ' bytes fee. Can't return.");
}",
"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'] = var[$balance_key] || ' bytes will be released. Transaction fee is ' || $return_fee || ' bytes. Your current transaction is' || trigger.output[[asset=base]] || 'bytes. You will receive ' || (var[$balance_key] - $return_fee) || ' bytes to your account.';
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;
}"
}
]
}
]
}
}
]
Show transactions in assets:
Transactions
No transactions found, it may be worth changing the filter