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