| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "init": "{ |
| 5 | $AA_NAME= "AAAA"; |
| 6 | $AA_OWNER = "O7NYCFUL5XIJTYE3O4MKGMGMTN6ATQAJ"; |
| 7 | $INSTRUCTIONS = "read doc!"; |
| 8 | $i = trigger.data; |
| 9 | $l = $i.list; |
| 10 | |
| 11 | if (!$l) bounce ("Need 'list = <list_name>'!"); |
| 12 | |
| 13 | $l_owner = var[$l||"_owner"] otherwise trigger.address; |
| 14 | $l_count = var[$l||"_count"] otherwise 0; |
| 15 | $l_public_mode = var[$l||"_public_mode"] otherwise $i.public; |
| 16 | |
| 17 | }", |
| 18 | "messages": { |
| 19 | "cases": [ |
| 20 | { |
| 21 | "if": "{ $i.add }", |
| 22 | "init": "{ |
| 23 | if (!$l_public_mode) |
| 24 | if (trigger.address != $l_owner) |
| 25 | bounce ("You don't own this private list"); |
| 26 | $e = $i.add; |
| 27 | }", |
| 28 | "messages": [ |
| 29 | { |
| 30 | "app": "state", |
| 31 | "state": "{ |
| 32 | var[$l||"_owner"] = $l_owner; |
| 33 | var[$l||"_count"] = $l_count + 1; |
| 34 | var[$l||"_public_mode"] = $l_public_mode; |
| 35 | |
| 36 | var[$l||"_"||$e] = $i.value; |
| 37 | var[$l||"_"||$e||"_position"] = var[$l||"_count"]; |
| 38 | var[$l||"_"||var[$l||"_count"]] = $e; |
| 39 | response['message']= $e||" added ^^."; |
| 40 | }" |
| 41 | } |
| 42 | ] |
| 43 | }, |
| 44 | { |
| 45 | "if": "{ $i.delete }", |
| 46 | "init": "{ |
| 47 | $l = $i.delete; |
| 48 | if (!(var[$l])) |
| 49 | bounce ("'"||$i.list_name||"' did not exist at the first place!"); |
| 50 | if (trigger.address != var[$l]) |
| 51 | bounce ("Must be owner to delete the list"); |
| 52 | if (var[$l||"_count"] > 0) |
| 53 | bounce ("List must be empty to be deleted, use 'remove_last' as much as needed"); |
| 54 | }", |
| 55 | "messages": [ |
| 56 | { |
| 57 | "app": "state", |
| 58 | "state": "{ |
| 59 | var[$l] = false; |
| 60 | var[$l||"_count"] = false; |
| 61 | |
| 62 | response['message']= $l||" delete ^^."; |
| 63 | }" |
| 64 | } |
| 65 | ] |
| 66 | }, |
| 67 | { |
| 68 | "if": "{ $i.remove_last }", |
| 69 | "init": "{ |
| 70 | $l = $i.remove_last; |
| 71 | if (!(var[$l])) |
| 72 | bounce ("'"||$i.list_name||"' did not exist !"); |
| 73 | if (trigger.address != var[$l]) |
| 74 | bounce ("Must be owner to remove last entry of the list"); |
| 75 | if (var[$l||"_count"] == 0) |
| 76 | bounce ("List is empty!"); |
| 77 | }", |
| 78 | "messages": [ |
| 79 | { |
| 80 | "app": "state", |
| 81 | "state": "{ |
| 82 | |
| 83 | $last_entry = var[$l||"_"||var[$l||"_count"]]; |
| 84 | |
| 85 | var[$l||"_"||$last_entry] = false; |
| 86 | var[$l||"_"||$last_entry||"_position"] = false; |
| 87 | var[$l||"_"||var[$l||"_count"]] = false; |
| 88 | var[$l||"_count"] -= 1; |
| 89 | |
| 90 | response['message']= $last_entry||" removed ^^."; |
| 91 | }" |
| 92 | } |
| 93 | ] |
| 94 | }, |
| 95 | { |
| 96 | "messages": [ |
| 97 | { |
| 98 | "app": "state", |
| 99 | "state": "{ bounce ($INSTRUCTIONS);}" |
| 100 | } |
| 101 | ] |
| 102 | } |
| 103 | ] |
| 104 | } |
| 105 | } |
| 106 | ] |