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