| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | $owner = var['owner'] OTHERWISE "VYC2LXEXXYS4FZMXE3WNTT4E6XVU4IEL"; |
| 9 | require(trigger.address == $owner, 'only owner can add or update agent'); |
| 10 | |
| 11 | $aa_address = trigger.data.aa_address; |
| 12 | if ($aa_address) { |
| 13 | require(is_aa($aa_address), 'AA address isn\ valid!'); |
| 14 | } |
| 15 | |
| 16 | $category = trigger.data.category; |
| 17 | |
| 18 | if ($category) { |
| 19 | require(typeof($category) == 'string', 'Category must be a string'); |
| 20 | require(length($category) > 0 AND length($category) <= 30, 'Min 1 symbol; Max 30 symbols'); |
| 21 | } |
| 22 | |
| 23 | $symbol = trigger.data.symbol; |
| 24 | if ($symbol) { |
| 25 | require(length($symbol) > 0 AND length($symbol) <= 20, 'Min 1 symbol; Max 20 symbols'); |
| 26 | require($symbol == to_upper($symbol), 'Symbol must be uppercase'); |
| 27 | } |
| 28 | |
| 29 | $name = trigger.data.name; |
| 30 | require(length($name) >= 5 AND length($name) <= 50, 'Min 5 symbol; Max 50 symbols'); |
| 31 | |
| 32 | $description = trigger.data.description; |
| 33 | if ($description) { |
| 34 | require(length($description) > 5 AND length($description) <= 250, 'Min 5 symbol; Max 250 symbols'); |
| 35 | } |
| 36 | |
| 37 | $logo_url = trigger.data.logo_url; |
| 38 | if ($logo_url) { |
| 39 | require(length($logo_url) <= 300, 'max 300 symbols'); |
| 40 | require(starts_with($logo_url, "https://"), 'Logo URL is not valid'); |
| 41 | } |
| 42 | |
| 43 | $website = trigger.data.website; |
| 44 | if ($website) { |
| 45 | require(starts_with($website, "https://"), 'Website URL is not valid'); |
| 46 | require(length($website) <= 100, 'max 100 symbols'); |
| 47 | } |
| 48 | }", |
| 49 | "getters": "{ |
| 50 | $get_agent = ($aa_address) => var['agent.' || $aa_address] OTHERWISE {}; |
| 51 | }", |
| 52 | "messages": { |
| 53 | "cases": [ |
| 54 | { |
| 55 | "if": "{trigger.data.listing}", |
| 56 | "init": "{ |
| 57 | require($aa_address, 'AA address is required'); |
| 58 | $agent = var['agent.' || $aa_address]; |
| 59 | require(!exists($agent), 'agent already listed'); |
| 60 | |
| 61 | $s2a = var['s2a.' || $symbol]; |
| 62 | require(!exists($s2a), 'symbol already listed'); |
| 63 | }", |
| 64 | "messages": [ |
| 65 | { |
| 66 | "app": "state", |
| 67 | "state": "{ |
| 68 | $info = { |
| 69 | symbol: $symbol, |
| 70 | name: $name, |
| 71 | address: $aa_address, |
| 72 | description: $description |
| 73 | }; |
| 74 | |
| 75 | if ($website) { |
| 76 | $info.website = $website; |
| 77 | } |
| 78 | |
| 79 | if ($category) { |
| 80 | $info.category = $category; |
| 81 | } |
| 82 | |
| 83 | if ($description) { |
| 84 | $info.description = $description; |
| 85 | } |
| 86 | |
| 87 | if ($logo_url) { |
| 88 | $info.logo_url = $logo_url; |
| 89 | } |
| 90 | |
| 91 | var['agent.' || $aa_address] = $info; |
| 92 | |
| 93 | var['s2a.' || $symbol] = $aa_address; |
| 94 | |
| 95 | response['listed'] = $info; |
| 96 | }" |
| 97 | } |
| 98 | ] |
| 99 | }, |
| 100 | { |
| 101 | "if": "{trigger.data.update}", |
| 102 | "init": "{ |
| 103 | require($aa_address, 'AA address is required'); |
| 104 | $agent = var['agent.' || $aa_address]; |
| 105 | require($agent, 'agent not found'); |
| 106 | |
| 107 | $field_name = trigger.data.field_name; |
| 108 | require($field_name, 'field name is required'); |
| 109 | require($field_name == 'name' OR $field_name == 'description' OR $field_name == 'logo_url' OR $field_name == 'website' OR $field_name == 'category', 'field name is not valid'); |
| 110 | |
| 111 | $value = trigger.data[$field_name]; |
| 112 | require($value, 'value is required'); |
| 113 | }", |
| 114 | "messages": [ |
| 115 | { |
| 116 | "app": "state", |
| 117 | "state": "{ |
| 118 | $agent[$field_name] = $value; |
| 119 | var['agent.' || $aa_address] = $agent; |
| 120 | response['updated'] = $agent; |
| 121 | }" |
| 122 | } |
| 123 | ] |
| 124 | }, |
| 125 | { |
| 126 | "if": "{trigger.data.remove}", |
| 127 | "init": "{ |
| 128 | require($aa_address, 'AA address is required'); |
| 129 | $agent = var['agent.' || $aa_address]; |
| 130 | require($agent, 'agent not found'); |
| 131 | }", |
| 132 | "messages": [ |
| 133 | { |
| 134 | "app": "state", |
| 135 | "state": "{ |
| 136 | response['removed'] = $agent; |
| 137 | var['agent.' || $aa_address] = false; |
| 138 | var['s2a.' || $agent.symbol] = false; |
| 139 | }" |
| 140 | } |
| 141 | ] |
| 142 | }, |
| 143 | { |
| 144 | "if": "{trigger.data.change_owner}", |
| 145 | "init": "{ |
| 146 | $new_owner = trigger.data.new_owner; |
| 147 | require(is_valid_address($new_owner), 'New owner address is not valid'); |
| 148 | }", |
| 149 | "messages": [ |
| 150 | { |
| 151 | "app": "state", |
| 152 | "state": "{ |
| 153 | var['owner'] = $new_owner; |
| 154 | response['new_owner'] = $new_owner; |
| 155 | }" |
| 156 | } |
| 157 | ] |
| 158 | } |
| 159 | ] |
| 160 | } |
| 161 | } |
| 162 | ] |