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