| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | if (NOT trigger.data["method"]) |
| 9 | bounce("method field is mandatory"); |
| 10 | $method = trigger.data["method"]; |
| 11 | $owner = var["owner"]; |
| 12 | }", |
| 13 | "getters": "{ |
| 14 | /* |
| 15 | ** Attested profile (or just the address if not found) |
| 16 | */ |
| 17 | $profileOf = $address=>{ |
| 18 | $ret = attestation[[attestors=this_address, address=$address, ifseveral='last']].data; |
| 19 | if ($ret){ |
| 20 | return json_parse($ret) OTHERWISE $ret; |
| 21 | } |
| 22 | return {}; |
| 23 | }; |
| 24 | $isRevoked = $nft=>{ |
| 25 | $feed = data_feed[[oracles=this_address, feed_name=$nft, ifnone="OK", ifseveral="last", type="string"]]; |
| 26 | return $feed == "REVOKED"; |
| 27 | }; |
| 28 | $artistInfoOf = $artist=>var["artist_" || $artist]; |
| 29 | }", |
| 30 | "messages": { |
| 31 | "cases": [ |
| 32 | { |
| 33 | "if": "{NOT $owner}", |
| 34 | "messages": [ |
| 35 | { |
| 36 | "app": "state", |
| 37 | "state": "{ |
| 38 | var["owner"] = "HMFR76BEZXV5T7X4QVWXFKADT73DKS2G"; |
| 39 | var["helper"] = "HMFR76BEZXV5T7X4QVWXFKADT73DKS2G"; |
| 40 | var["maxRoyalty"] = 40; |
| 41 | }" |
| 42 | } |
| 43 | ] |
| 44 | }, |
| 45 | { |
| 46 | "if": "{ |
| 47 | trigger.address == $owner |
| 48 | AND ($method == "payout" |
| 49 | OR $method == "transferOwnership" |
| 50 | OR $method == "setHelper" |
| 51 | OR $method == "setReseller" |
| 52 | OR $method == "delReseller" |
| 53 | OR $method == "setMaxRoyalty" |
| 54 | OR $method == "unverify") |
| 55 | }", |
| 56 | "messages": { |
| 57 | "cases": [ |
| 58 | { |
| 59 | "if": "{$method == "payout"}", |
| 60 | "messages": [ |
| 61 | { |
| 62 | "app": "payment", |
| 63 | "payload": { |
| 64 | "asset": "base", |
| 65 | "outputs": [ |
| 66 | { |
| 67 | "address": "{trigger.address}" |
| 68 | } |
| 69 | ] |
| 70 | } |
| 71 | } |
| 72 | ] |
| 73 | }, |
| 74 | { |
| 75 | "if": "{$method == "setMaxRoyalty"}", |
| 76 | "init": "{ |
| 77 | if (NOT exists(trigger.data["royalty"])) |
| 78 | bounce("royalty field is mandatory"); |
| 79 | if (NOT is_integer(trigger.data["royalty"])) |
| 80 | bounce("royalty must be an integer"); |
| 81 | if (trigger.data["royalty"] < 0) |
| 82 | bounce("royalty must be positive"); |
| 83 | if (trigger.data["royalty"] > 100) |
| 84 | bounce("royalty cannot be higher than 100%"); |
| 85 | }", |
| 86 | "messages": [ |
| 87 | { |
| 88 | "app": "state", |
| 89 | "state": "{ |
| 90 | var["maxRoyalty"] = trigger.data["royalty"]; |
| 91 | }" |
| 92 | } |
| 93 | ] |
| 94 | }, |
| 95 | { |
| 96 | "if": "{$method == "unverify"}", |
| 97 | "init": "{ |
| 98 | if (NOT trigger.data["address"]) |
| 99 | bounce("address field is mandatory"); |
| 100 | $_ = $profileOf(trigger.data["address"]); |
| 101 | $oldUsername = $_["username"]; |
| 102 | $prof = $_ || {verified: false, username: false, isReseller: false}; |
| 103 | }", |
| 104 | "messages": [ |
| 105 | { |
| 106 | "app": "attestation", |
| 107 | "init": "{ |
| 108 | $profileString = json_stringify($prof); |
| 109 | if (length($profileString) > 4096) |
| 110 | bounce("The profile is too long, the user has to remove some fields and retry verification"); |
| 111 | }", |
| 112 | "payload": "{ |
| 113 | { |
| 114 | address: trigger.data["address"], |
| 115 | profile: { |
| 116 | data: $profileString |
| 117 | } |
| 118 | } |
| 119 | }" |
| 120 | }, |
| 121 | { |
| 122 | "app": "state", |
| 123 | "state": "{ |
| 124 | var["user_" || $oldUsername] = false; |
| 125 | }" |
| 126 | } |
| 127 | ] |
| 128 | }, |
| 129 | { |
| 130 | "if": "{$method == "transferOwnership"}", |
| 131 | "init": "{ |
| 132 | if (NOT trigger.data["newOwner"]) |
| 133 | bounce("newOwner field is mandatory"); |
| 134 | if (NOT is_valid_address(trigger.data["newOwner"])) |
| 135 | bounce("newOwner field is not a valid address"); |
| 136 | }", |
| 137 | "messages": [ |
| 138 | { |
| 139 | "app": "payment", |
| 140 | "payload": { |
| 141 | "asset": "base", |
| 142 | "outputs": [ |
| 143 | { |
| 144 | "address": "{trigger.address}" |
| 145 | } |
| 146 | ] |
| 147 | } |
| 148 | }, |
| 149 | { |
| 150 | "app": "state", |
| 151 | "state": "{ |
| 152 | var["owner"] = trigger.data["newOwner"]; |
| 153 | }" |
| 154 | } |
| 155 | ] |
| 156 | }, |
| 157 | { |
| 158 | "if": "{$method == "setHelper"}", |
| 159 | "init": "{ |
| 160 | if (NOT trigger.data["helper"]) |
| 161 | bounce("helper field is mandatory"); |
| 162 | }", |
| 163 | "messages": [ |
| 164 | { |
| 165 | "app": "state", |
| 166 | "state": "{ |
| 167 | var["helper"] = trigger.data["helper"]; |
| 168 | }" |
| 169 | } |
| 170 | ] |
| 171 | } |
| 172 | ] |
| 173 | } |
| 174 | }, |
| 175 | { |
| 176 | "if": "{ |
| 177 | (trigger.address == $owner |
| 178 | OR trigger.address == var["helper"]) |
| 179 | AND ($method == "verifyProfile" |
| 180 | OR $method == "revoke") |
| 181 | }", |
| 182 | "messages": { |
| 183 | "cases": [ |
| 184 | { |
| 185 | "if": "{$method == "revoke"}", |
| 186 | "init": "{ |
| 187 | if (NOT trigger.data["NFT"]) |
| 188 | bounce("NFT field is mandatory"); |
| 189 | $previousValue = data_feed[[oracles=[this_address], feed_name=trigger.data["NFT"], ifnone="OK", ifseveral="last", what="value", type="string"]]; |
| 190 | $newValue = $previousValue == "OK" ? "REVOKED" : "OK"; |
| 191 | }", |
| 192 | "messages": [ |
| 193 | { |
| 194 | "app": "data_feed", |
| 195 | "payload": { |
| 196 | "{trigger.data["NFT"]}": "{$newValue}" |
| 197 | } |
| 198 | } |
| 199 | ] |
| 200 | }, |
| 201 | { |
| 202 | "if": "{$method == "verifyProfile"}", |
| 203 | "init": "{ |
| 204 | if (NOT trigger.data["address"]) |
| 205 | bounce("address field is mandatory"); |
| 206 | if (NOT is_valid_address(trigger.data["address"])) |
| 207 | bounce("That address is not valid"); |
| 208 | |
| 209 | $profileObj = $profileOf(trigger.data["address"]) || {verified: true}; |
| 210 | |
| 211 | |
| 212 | |
| 213 | }", |
| 214 | "messages": [ |
| 215 | { |
| 216 | "app": "attestation", |
| 217 | "payload": "{ |
| 218 | { |
| 219 | address: trigger.data["address"], |
| 220 | profile: { |
| 221 | data: json_stringify($profileObj) |
| 222 | } |
| 223 | } |
| 224 | }" |
| 225 | }, |
| 226 | { |
| 227 | "app": "state", |
| 228 | "state": "{ |
| 229 | var["user_" || $profileObj.username] = trigger.data["address"]; |
| 230 | var["ret"] = $profileObj; |
| 231 | }" |
| 232 | } |
| 233 | ] |
| 234 | } |
| 235 | ] |
| 236 | } |
| 237 | }, |
| 238 | { |
| 239 | "if": "{$method == "PROFILE"}", |
| 240 | "init": "{ |
| 241 | $prof = $profileOf(trigger.address); |
| 242 | |
| 243 | $oldUsername = $prof.username; |
| 244 | $newUsername = trigger.data["username"] OTHERWISE $oldUsername; |
| 245 | |
| 246 | if (NOT $oldUsername){ |
| 247 | if (NOT trigger.data["username"]) |
| 248 | bounce("username field is mandatory"); |
| 249 | } |
| 250 | |
| 251 | if (var["user_" || $newUsername]){ |
| 252 | if ($oldUsername){ |
| 253 | if ($oldUsername != $newUsername){ |
| 254 | bounce("username already taken by a verified user"); |
| 255 | } |
| 256 | } |
| 257 | } |
| 258 | if (exists(trigger.data["username"]) OR exists(trigger.data["name"]) OR exists(trigger.data["company"]) OR exists(trigger.data["isReseller"]) OR exists(trigger.data["verified"])) |
| 259 | $unverify = true; |
| 260 | else |
| 261 | $unverify = false; |
| 262 | |
| 263 | if ($prof) |
| 264 | $profileObj = $prof || trigger.data || {username: $newUsername, verified: NOT $unverify}; |
| 265 | else |
| 266 | $profileObj = trigger.data || {username: $newUsername, verified: NOT $unverify}; |
| 267 | delete($profileObj, "method"); |
| 268 | }", |
| 269 | "messages": [ |
| 270 | { |
| 271 | "app": "attestation", |
| 272 | "init": "{ |
| 273 | $profileString = json_stringify($profileObj); |
| 274 | if (length($profileString) > 4000) |
| 275 | bounce("Your profile is too big, try removing some fields"); |
| 276 | }", |
| 277 | "payload": "{ |
| 278 | { |
| 279 | address: trigger.address, |
| 280 | profile: { |
| 281 | data: $profileString |
| 282 | } |
| 283 | } |
| 284 | }" |
| 285 | }, |
| 286 | { |
| 287 | "app": "state", |
| 288 | "state": "{ |
| 289 | if ($oldUsername){ |
| 290 | if ($oldUsername != $newUsername) |
| 291 | var["user_" || $oldUsername] = false; |
| 292 | } |
| 293 | |
| 294 | }" |
| 295 | } |
| 296 | ] |
| 297 | } |
| 298 | ] |
| 299 | } |
| 300 | } |
| 301 | ] |