| 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.operation == 'keep'}", |
| 13 | "init": "{ |
| 14 | if (!var[$balance_key] AND !trigger.data.unlock_date) bounce("Warning! Please add 'unlock_date' data field."); |
| 15 | if (!var[$balance_key] AND trigger.data.unlock_date AND typeof(parse_date(trigger.data.unlock_date)) != "number") bounce("Warning! The format of the 'unlock_date' field is YYYY-MM-DD."); |
| 16 | if (var[$balance_key] AND parse_date(trigger.data.unlock_date) != var[$timestamp_key]) bounce("Warning! 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 either remove 'unlock_date' data field or make it 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.unlock_date); |
| 24 | var[$balance_key] = var[$balance_key] + trigger.output[[asset=base]]; |
| 25 | response['message'] = "Total balance will be "|| var[$balance_key] || " bytes. The bytes will be locked till "|| trigger.data.unlock_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."; |
| 26 | }" |
| 27 | } |
| 28 | ] |
| 29 | }, |
| 30 | { |
| 31 | "if": "{trigger.data.operation == 'return'}", |
| 32 | "init": "{ |
| 33 | if (!var[$balance_key]) bounce('Warning! No bytes to return for this address.'); |
| 34 | if (var[$timestamp_key] > timestamp) bounce('Warning! The unlock date has not come yet. Bytes are locked till '|| timestamp_to_string(var[$timestamp_key], 'date') || ' 0:00 UTC.'); |
| 35 | |
| 36 | }", |
| 37 | "messages": [ |
| 38 | { |
| 39 | "app": "payment", |
| 40 | "payload": { |
| 41 | "asset": "base", |
| 42 | "outputs": [ |
| 43 | { |
| 44 | "address": "{trigger.address}", |
| 45 | "amount": "{ var[$balance_key] - $return_fee}" |
| 46 | } |
| 47 | ] |
| 48 | } |
| 49 | }, |
| 50 | { |
| 51 | "app": "state", |
| 52 | "state": "{ |
| 53 | response['message'] = var[$balance_key] || ' bytes will be returned. Transaction fee is ' || $return_fee || ' bytes. You will receive ' || var[$balance_key] - $return_fee || ' bytes to your account.'; |
| 54 | var[$balance_key] = false; |
| 55 | var[$timestamp_key] = false; |
| 56 | }" |
| 57 | } |
| 58 | ] |
| 59 | }, |
| 60 | { |
| 61 | "messages": [ |
| 62 | { |
| 63 | "app": "state", |
| 64 | "state": "{ |
| 65 | bounce("Welcome user! Please add 'operation' data field with 'keep' or 'return' values. Otherwise the transaction will be bounced."); |
| 66 | }" |
| 67 | } |
| 68 | ] |
| 69 | } |
| 70 | ] |
| 71 | } |
| 72 | } |
| 73 | ] |