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