| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | $return_fee = 1000; |
| 6 | $balance_key = 'balance_'||trigger.address; |
| 7 | $timestamp_key = 'timestamp_'||trigger.address; |
| 8 | }", |
| 9 | "messages": { |
| 10 | "cases": [ |
| 11 | { |
| 12 | "if": "{!trigger.data.return}", |
| 13 | "init": "{ |
| 14 | 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."); |
| 15 | if (typeof(parse_date(trigger.data.lock_till)) != "number") bounce("The format of the 'lock_till' field is YYYY-MM-DD."); |
| 16 | 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."); |
| 17 | }", |
| 18 | "messages": [ |
| 19 | { |
| 20 | "app": "state", |
| 21 | "state": "{ |
| 22 | if (!var[$balance_key]) |
| 23 | var[$timestamp_key] = parse_date(trigger.data.lock_till); |
| 24 | var[$balance_key] = var[$balance_key] + trigger.output[[asset=base]]; |
| 25 | if (var[$timestamp_key] < timestamp) |
| 26 | response['info'] = "You set 'lock_till' date from the past. You can withdraw at any time."; |
| 27 | if (var[$timestamp_key] > timestamp + 1576800000) |
| 28 | response['info'] = "Your 'lock_till' date is set for more than 50 years!"; |
| 29 | 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."; |
| 30 | }" |
| 31 | } |
| 32 | ] |
| 33 | }, |
| 34 | { |
| 35 | "init": "{ |
| 36 | if (!var[$balance_key]) bounce('No bytes to return for this address.'); |
| 37 | 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.'); |
| 38 | }", |
| 39 | "messages": [ |
| 40 | { |
| 41 | "app": "payment", |
| 42 | "payload": { |
| 43 | "asset": "base", |
| 44 | "outputs": [ |
| 45 | { |
| 46 | "address": "{trigger.address}", |
| 47 | "amount": "{ var[$balance_key] - $return_fee + trigger.output[[asset=base]]}" |
| 48 | } |
| 49 | ] |
| 50 | } |
| 51 | }, |
| 52 | { |
| 53 | "app": "state", |
| 54 | "state": "{ |
| 55 | 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)'; |
| 56 | var[$balance_key] = false; |
| 57 | var[$timestamp_key] = false; |
| 58 | }" |
| 59 | } |
| 60 | ] |
| 61 | } |
| 62 | ] |
| 63 | } |
| 64 | } |
| 65 | ] |