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