| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | $USER_REGISTRY_ADDRESS = "FRXC36NKZ5NYBJKWLLBPJNCL64XPOMCB"; |
| 9 | $CURRENCY_REGISTRY = "HWAVRAIY6MJPG2INNT2FIX2XXZCT55CL"; |
| 10 | |
| 11 | if (NOT exists(trigger.data["method"])) |
| 12 | bounce("method field is mandatory"); |
| 13 | |
| 14 | $method = trigger.data["method"]; |
| 15 | |
| 16 | $spendableFunds = balance["base"] - storage_size - trigger.output[[asset="base"]].amount; |
| 17 | $owner = var["owner"]; |
| 18 | $isHelper = var["helper_" || trigger.address]; |
| 19 | |
| 20 | /* |
| 21 | ** Provides information about the given license |
| 22 | */ |
| 23 | $getNFTInfo = $NFT=>{ |
| 24 | $unit = unit[$NFT]; |
| 25 | $info = var["FREE_" || $NFT] OTHERWISE var["NFT_" || $NFT]; |
| 26 | $transferrable = $unit.messages[[.app="asset"]]["payload"]["transferrable"]; |
| 27 | |
| 28 | if (NOT $transferrable) |
| 29 | return false; |
| 30 | |
| 31 | return $info || { |
| 32 | cap: $unit.messages[[.app="asset"]]["payload"]["cap"], |
| 33 | mintedAt: $unit.timestamp |
| 34 | }; |
| 35 | }; |
| 36 | $stripNFT = $NFT=>{ |
| 37 | delete($NFT, "cap"); |
| 38 | delete($NFT, "mintedAt"); |
| 39 | }; |
| 40 | $FEE = var["FEE"]; |
| 41 | }", |
| 42 | "messages": { |
| 43 | "cases": [ |
| 44 | { |
| 45 | "if": "{ |
| 46 | NOT $owner |
| 47 | }", |
| 48 | "messages": [ |
| 49 | { |
| 50 | "app": "state", |
| 51 | "state": "{ |
| 52 | var["owner"] = "IUU43O7TS2TBYKAPGKUARDZHOTAE275A"; |
| 53 | var["FEE"] = 0.04; |
| 54 | }" |
| 55 | } |
| 56 | ] |
| 57 | }, |
| 58 | { |
| 59 | "if": "{ |
| 60 | trigger.address == $owner |
| 61 | AND ($method == "payout" |
| 62 | OR $method == "stopSale" |
| 63 | OR $method == "transferOwnership" |
| 64 | OR $method == "setHelper" |
| 65 | OR $method == "reduceFee" |
| 66 | OR $method == "untrust" |
| 67 | OR $method == "delHelper") |
| 68 | }", |
| 69 | "messages": { |
| 70 | "cases": [ |
| 71 | { |
| 72 | "if": "{ |
| 73 | $method == "payout" |
| 74 | }", |
| 75 | "messages": [ |
| 76 | { |
| 77 | "app": "payment", |
| 78 | "payload": { |
| 79 | "asset": "base", |
| 80 | "outputs": [ |
| 81 | { |
| 82 | "address": "{trigger.address}", |
| 83 | "amount": "{$spendableFunds}" |
| 84 | } |
| 85 | ] |
| 86 | } |
| 87 | } |
| 88 | ] |
| 89 | }, |
| 90 | { |
| 91 | "if": "{ |
| 92 | $method == "untrust" |
| 93 | }", |
| 94 | "init": "{ |
| 95 | if (NOT trigger.data["user"]) |
| 96 | bounce("user field is mandatory"); |
| 97 | if (NOT is_valid_address(trigger.data["user"])) |
| 98 | bounce("user field is an invalid address"); |
| 99 | }", |
| 100 | "messages": [ |
| 101 | { |
| 102 | "app": "state", |
| 103 | "state": "{ |
| 104 | var["trusted_" || trigger.data["user"]] = false; |
| 105 | }" |
| 106 | } |
| 107 | ] |
| 108 | }, |
| 109 | { |
| 110 | "if": "{ |
| 111 | $method == "transferOwnership" |
| 112 | }", |
| 113 | "init": "{ |
| 114 | if (NOT exists(trigger.data["newOwner"])) |
| 115 | bounce("newOwner field is mandatory"); |
| 116 | if (NOT is_valid_address(trigger.data["newOwner"])) |
| 117 | bounce("newOwner field is not a valid address"); |
| 118 | }", |
| 119 | "messages": [ |
| 120 | { |
| 121 | "app": "payment", |
| 122 | "payload": { |
| 123 | "asset": "base", |
| 124 | "outputs": [ |
| 125 | { |
| 126 | "address": "{trigger.address}", |
| 127 | "amount": "{$spendableFunds}" |
| 128 | } |
| 129 | ] |
| 130 | } |
| 131 | }, |
| 132 | { |
| 133 | "app": "state", |
| 134 | "state": "{ |
| 135 | var["owner"] = trigger.data["newOwner"]; |
| 136 | }" |
| 137 | } |
| 138 | ] |
| 139 | }, |
| 140 | { |
| 141 | "if": "{ |
| 142 | $method == "reduceFee" |
| 143 | }", |
| 144 | "init": "{ |
| 145 | if (NOT exists(trigger.data["fee"])) |
| 146 | bounce("fee field is mandatory"); |
| 147 | if (trigger.data["fee"] <= 0) |
| 148 | bounce("Fee must be an strictly positive value"); |
| 149 | if (trigger.data["fee"] > $FEE) |
| 150 | bounce("You can only reduce the current fee"); |
| 151 | }", |
| 152 | "messages": [ |
| 153 | { |
| 154 | "app": "state", |
| 155 | "state": "{ |
| 156 | var["FEE"] = trigger.data["fee"]; |
| 157 | }" |
| 158 | } |
| 159 | ] |
| 160 | }, |
| 161 | { |
| 162 | "if": "{ |
| 163 | $method == "setHelper" |
| 164 | }", |
| 165 | "init": "{ |
| 166 | if (NOT exists(trigger.data["helper"])) |
| 167 | bounce("helper field is mandatory"); |
| 168 | if (NOT is_valid_address(trigger.data["helper"])) |
| 169 | bounce("helper address is invalid"); |
| 170 | }", |
| 171 | "messages": [ |
| 172 | { |
| 173 | "app": "state", |
| 174 | "state": "{ |
| 175 | var["helper_" || trigger.data["helper"]] = true; |
| 176 | }" |
| 177 | } |
| 178 | ] |
| 179 | }, |
| 180 | { |
| 181 | "if": "{ |
| 182 | $method == "delHelper" |
| 183 | }", |
| 184 | "init": "{ |
| 185 | if (NOT exists(trigger.data["helper"])) |
| 186 | bounce("helper field is mandatory"); |
| 187 | if (NOT is_valid_address(trigger.data["helper"])) |
| 188 | bounce("helper address is invalid"); |
| 189 | }", |
| 190 | "messages": [ |
| 191 | { |
| 192 | "app": "state", |
| 193 | "state": "{ |
| 194 | var["helper_" || trigger.data["helper"]] = false; |
| 195 | }" |
| 196 | } |
| 197 | ] |
| 198 | } |
| 199 | ] |
| 200 | } |
| 201 | }, |
| 202 | { |
| 203 | "if": "{ |
| 204 | (trigger.address == $owner OR $isHelper) |
| 205 | AND $method == "trust" |
| 206 | }", |
| 207 | "init": "{ |
| 208 | if (NOT trigger.data["user"]) |
| 209 | bounce("user field is mandatory"); |
| 210 | if (NOT is_valid_address(trigger.data["user"])) |
| 211 | bounce("user field is an invalid address"); |
| 212 | }", |
| 213 | "messages": [ |
| 214 | { |
| 215 | "app": "state", |
| 216 | "state": "{ |
| 217 | var["trusted_" || trigger.data["user"]] = true; |
| 218 | }" |
| 219 | } |
| 220 | ] |
| 221 | }, |
| 222 | { |
| 223 | "if": "{ |
| 224 | (trigger.address == $owner OR $isHelper) |
| 225 | AND $method == "untrust" |
| 226 | }", |
| 227 | "init": "{ |
| 228 | if (NOT trigger.data["NFT"]) |
| 229 | bounce("NFT field is mandatory"); |
| 230 | }", |
| 231 | "messages": [ |
| 232 | { |
| 233 | "app": "state", |
| 234 | "state": "{ |
| 235 | var["FREE_" || trigger.data["NFT"]] = var["NFT_" || trigger.data["NFT"]]; |
| 236 | var["NFT_" || trigger.data["NFT"]] = false; |
| 237 | }" |
| 238 | } |
| 239 | ] |
| 240 | }, |
| 241 | { |
| 242 | "if": "{ |
| 243 | $method == "MINT" |
| 244 | }", |
| 245 | "init": "{ |
| 246 | if (NOT exists(trigger.data["amount"])) |
| 247 | bounce("amount field is mandatory. Set it to 0 for unlimited"); |
| 248 | |
| 249 | if ((NOT is_valid_amount(trigger.data["amount"])) AND trigger.data["amount"] != 0) |
| 250 | bounce("The amount of license copies to mint is not valid"); |
| 251 | |
| 252 | if (NOT exists(trigger.data["price"])) |
| 253 | bounce("price field is mandatory"); |
| 254 | |
| 255 | $currency = $CURRENCY_REGISTRY.$getCurrency(trigger.data["currency"]); |
| 256 | $profile = $USER_REGISTRY_ADDRESS.$profileOf(trigger.address); |
| 257 | |
| 258 | if (trigger.data["currency"]){ |
| 259 | if (NOT $currency) |
| 260 | bounce("The provided currency is not supported"); |
| 261 | } |
| 262 | |
| 263 | $price = trigger.data["currency"] |
| 264 | ? $CURRENCY_REGISTRY.$convert(trigger.data["price"], trigger.data["currency"]) |
| 265 | : trigger.data["price"]; |
| 266 | |
| 267 | if ($price <= 0) |
| 268 | bounce("price field must be higher than 0"); |
| 269 | |
| 270 | if (NOT exists(trigger.data["currency"])){ |
| 271 | if ($price < 20000) |
| 272 | bounce("The minium price is 20.000 bytes"); |
| 273 | if (NOT is_valid_amount($price)) |
| 274 | bounce("price is not valid"); |
| 275 | } |
| 276 | |
| 277 | if (exists(trigger.data["maxPeriods"])){ |
| 278 | if (NOT is_integer(trigger.data["maxPeriods"])) |
| 279 | bounce("maxPeriods must be an integer"); |
| 280 | |
| 281 | if (trigger.data["maxPeriods"] <= 0) |
| 282 | bounce("maxPeriods must be positive"); |
| 283 | |
| 284 | if (NOT exists(trigger.data["validity"])) |
| 285 | bounce("If you set maxPeriods you have to set validity too"); |
| 286 | } |
| 287 | |
| 288 | if (exists(trigger.data["validity"])){ |
| 289 | if (NOT is_integer(trigger.data["validity"])) |
| 290 | bounce("validity must be an integer"); |
| 291 | |
| 292 | if (trigger.data["validity"] <= 0) |
| 293 | bounce("You cannot make a license valid for 0s or less"); |
| 294 | } |
| 295 | |
| 296 | if (trigger.address == $owner OR $profile.isLicensor){ |
| 297 | if (NOT exists(trigger.data["ipfs"])) |
| 298 | bounce("ipfs field is mandatory"); |
| 299 | |
| 300 | if (NOT exists(trigger.data["title"])) |
| 301 | bounce("title field is mandatory"); |
| 302 | if (length(trigger.data["title"]) > 512) |
| 303 | bounce("The license title must be at most 512 characters long"); |
| 304 | |
| 305 | if (exists(trigger.data["ticker"])){ |
| 306 | if (length(trigger.data["ticker"]) > 128) |
| 307 | bounce("The length of the license ticker must be at most 128 characters long"); |
| 308 | } |
| 309 | |
| 310 | $pendingNaming = var["NFT_" || var["pendingNaming"]]; |
| 311 | } |
| 312 | |
| 313 | if (exists(trigger.data["soldAt"])){ |
| 314 | if (NOT is_integer(trigger.data["soldAt"])) |
| 315 | bounce("soldAt must be an integer"); |
| 316 | if (trigger.data["soldAt"] <= timestamp) |
| 317 | bounce("soldAt cannot be set in the past"); |
| 318 | } |
| 319 | if (exists(trigger.data["tranferrable"])){ |
| 320 | $isTransferrable = exists(trigger.data["validity"]) |
| 321 | ? false |
| 322 | : trigger.data["tranferrable"] == "true" |
| 323 | ? true |
| 324 | : false; |
| 325 | } |
| 326 | else{ |
| 327 | $isTransferrable = false; |
| 328 | } |
| 329 | }", |
| 330 | "messages": { |
| 331 | "cases": [ |
| 332 | { |
| 333 | "if": "{ |
| 334 | trigger.data["amount"] |
| 335 | }", |
| 336 | "messages": [ |
| 337 | { |
| 338 | "app": "asset", |
| 339 | "payload": { |
| 340 | "cap": "{trigger.data["amount"]}", |
| 341 | "is_private": false, |
| 342 | "is_transferrable": "{$isTransferrable}", |
| 343 | "auto_destroy": false, |
| 344 | "fixed_denominations": false, |
| 345 | "issued_by_definer_only": true, |
| 346 | "cosigned_by_definer": false, |
| 347 | "spender_attested": false |
| 348 | } |
| 349 | }, |
| 350 | { |
| 351 | "app": "data", |
| 352 | "if": "{ |
| 353 | $pendingNaming |
| 354 | }", |
| 355 | "payload": { |
| 356 | "asset": "{var["recordToData"]}", |
| 357 | "name": "{($pendingNaming.ticker OTHERWISE "Untitled")|| " license"}", |
| 358 | "author": "{$pendingNaming.author}", |
| 359 | "ipfs": "{$pendingNaming.ipfs}", |
| 360 | "type": "LIC", |
| 361 | "decimals": 0 |
| 362 | } |
| 363 | }, |
| 364 | { |
| 365 | "app": "state", |
| 366 | "state": "{ |
| 367 | if (trigger.address == $owner OR $profile.isLicensor){ |
| 368 | var["NFT_" || response_unit] = { |
| 369 | price: trigger.data["price"] OTHERWISE false, |
| 370 | currency: trigger.data["currency"] OTHERWISE false, |
| 371 | title: trigger.data["title"], |
| 372 | ipfs: trigger.data["ipfs"], |
| 373 | unitsSold: 0, |
| 374 | author: trigger.data["seller"], |
| 375 | validity: trigger.data["validity"] OTHERWISE false, |
| 376 | maxPeriods: trigger.data["maxPeriods"] OTHERWISE false, |
| 377 | soldAt: trigger.data["soldAt"] OTHERWISE false, |
| 378 | onSale: true, |
| 379 | type: 'LIC' |
| 380 | }; |
| 381 | |
| 382 | var["pendingNaming"] = response_unit; |
| 383 | } |
| 384 | else{ |
| 385 | var["FREE_" || response_unit] = { |
| 386 | price: trigger.data["price"] OTHERWISE false, |
| 387 | currency: trigger.data["currency"] OTHERWISE false, |
| 388 | title: trigger.data["title"] OTHERWISE false, |
| 389 | author: trigger.address, |
| 390 | validity: trigger.data["validity"], |
| 391 | maxPeriods: trigger.data["maxPeriods"], |
| 392 | soldAt: trigger.data["soldAt"] OTHERWISE false, |
| 393 | ipfs: trigger.data["ipfs"] OTHERWISE false, |
| 394 | unitsSold: 0, |
| 395 | onSale: true, |
| 396 | type: 'LIC' |
| 397 | }; |
| 398 | } |
| 399 | }" |
| 400 | } |
| 401 | ] |
| 402 | }, |
| 403 | { |
| 404 | "messages": [ |
| 405 | { |
| 406 | "app": "asset", |
| 407 | "payload": { |
| 408 | "is_private": false, |
| 409 | "is_transferrable": "{$isTransferrable}", |
| 410 | "auto_destroy": false, |
| 411 | "fixed_denominations": false, |
| 412 | "issued_by_definer_only": true, |
| 413 | "cosigned_by_definer": false, |
| 414 | "spender_attested": false |
| 415 | } |
| 416 | }, |
| 417 | { |
| 418 | "app": "data", |
| 419 | "if": "{ |
| 420 | $pendingNaming |
| 421 | }", |
| 422 | "payload": { |
| 423 | "asset": "{var["recordToData"]}", |
| 424 | "name": "{($pendingNaming.ticker OTHERWISE "Untitled") || " license"}", |
| 425 | "author": "{$pendingNaming.author}", |
| 426 | "ipfs": "{$pendingNaming.ipfs}", |
| 427 | "type": "LIC", |
| 428 | "decimals": 0 |
| 429 | } |
| 430 | }, |
| 431 | { |
| 432 | "app": "state", |
| 433 | "state": "{ |
| 434 | if (trigger.address == $owner OR $profile.isLicensor){ |
| 435 | var["NFT_" || response_unit] = { |
| 436 | price: trigger.data["price"] OTHERWISE false, |
| 437 | currency: trigger.data["currency"] OTHERWISE false, |
| 438 | title: trigger.data["title"], |
| 439 | ipfs: trigger.data["ipfs"], |
| 440 | author: trigger.data["seller"], |
| 441 | validity: trigger.data["validity"] OTHERWISE false, |
| 442 | maxPeriods: trigger.data["maxPeriods"] OTHERWISE false, |
| 443 | onSale: true, |
| 444 | type: 'LIC' |
| 445 | }; |
| 446 | |
| 447 | var["pendingNaming"] = response_unit; |
| 448 | } |
| 449 | else{ |
| 450 | var["FREE_" || response_unit] = { |
| 451 | price: trigger.data["price"] OTHERWISE false, |
| 452 | priceCurrency: trigger.data["priceCurrency"] OTHERWISE false, |
| 453 | author: trigger.address, |
| 454 | validity: trigger.data["validity"], |
| 455 | maxPeriods: trigger.data["maxPeriods"], |
| 456 | onSale: true, |
| 457 | type: 'LIC' |
| 458 | }; |
| 459 | } |
| 460 | }" |
| 461 | } |
| 462 | ] |
| 463 | } |
| 464 | ] |
| 465 | } |
| 466 | }, |
| 467 | { |
| 468 | "if": "{ |
| 469 | $method == "END_SALE" |
| 470 | }", |
| 471 | "init": "{ |
| 472 | if (NOT exists(trigger.data["NFT"])) |
| 473 | bounce("NFT field is mandatory"); |
| 474 | |
| 475 | $NFT = var["NFT_" || trigger.data["NFT"]] OTHERWISE var["FREE_" || trigger.data["NFT"]]; |
| 476 | |
| 477 | if (NOT $NFT) |
| 478 | bounce("That NFT is not known by this AA"); |
| 479 | |
| 480 | if (trigger.address != $NFT.author) |
| 481 | bounce("You cannot stop a sale not created by yourself"); |
| 482 | }", |
| 483 | "messages": [ |
| 484 | { |
| 485 | "app": "state", |
| 486 | "state": "{ |
| 487 | if (var["NFT_" || trigger.data["NFT"]]) |
| 488 | var["NFT_" || trigger.data["NFT"]] ||= {onSale: false}; |
| 489 | else |
| 490 | var["FREE_" || trigger.data["NFT"]] ||= {onSale: false}; |
| 491 | }" |
| 492 | } |
| 493 | ] |
| 494 | }, |
| 495 | { |
| 496 | "if": "{ |
| 497 | trigger.data["method"] == "BUY" |
| 498 | }", |
| 499 | "init": "{ |
| 500 | $NFT = var["NFT_" || trigger.data["NFT"]] OTHERWISE var["FREE_" || trigger.data["NFT"]]; |
| 501 | |
| 502 | $previousExpiry = $USER_REGISTRY_ADDRESS.$licenseExpirationOf(trigger.address, trigger.data["NFT"]); |
| 503 | |
| 504 | if (NOT $NFT) |
| 505 | bounce("NFT field is mandatory"); |
| 506 | |
| 507 | if ($NFT.soldAt){ |
| 508 | if ($NFT.soldAt < timestamp) |
| 509 | bounce("That license sale period ended on " || timestamp_to_string($NFT.soldAt) || " UTC"); |
| 510 | } |
| 511 | |
| 512 | if (NOT $NFT.onSale) |
| 513 | bounce("The owner of that license cancelled its sale. No more copies will be ever sold."); |
| 514 | |
| 515 | if (exists(trigger.data["periods"])){ |
| 516 | if (NOT is_integer(trigger.data["periods"])) |
| 517 | bounce("periods must be an integer"); |
| 518 | } |
| 519 | |
| 520 | $unit = unit[trigger.data["NFT"]]; |
| 521 | $cap = $unit.messages[[.app="asset"]]["payload"]["cap"]; |
| 522 | |
| 523 | |
| 524 | $periods = trigger.data["periods"] OTHERWISE 1; |
| 525 | |
| 526 | if ($NFT.unitsSold + $periods > $cap){ |
| 527 | bounce("There are only " || json_stringify($cap - $NFT.unitsSold) || " copies left"); |
| 528 | } |
| 529 | |
| 530 | if ($NFT.currency) |
| 531 | $expectedAmount = $CURRENCY_REGISTRY.$convert($NFT.price, $NFT.currency) * $periods; |
| 532 | else |
| 533 | $expectedAmount = $NFT.price * $periods; |
| 534 | |
| 535 | if ($NFT.maxPeriods){ |
| 536 | $remainingPeriods = ceil((($USER_REGISTRY_ADDRESS.$licenseExpirationOf(trigger.address, trigger.data["NFT"]) OTHERWISE timestamp) - timestamp) / $NFT.validity, 0); |
| 537 | if ($remainingPeriods + $periods > $NFT.maxPeriods) |
| 538 | bounce("You cannot buy that many periods in advance. Please try again when your license is closer to expiry"); |
| 539 | } |
| 540 | |
| 541 | response["rate"] = $CURRENCY_REGISTRY.$convert(1, $NFT.currency); |
| 542 | response["price"] = $expectedAmount; |
| 543 | response["currency"] = $NFT.currency; |
| 544 | |
| 545 | if (trigger.output[[asset="base"]].amount < $expectedAmount) |
| 546 | bounce("Your payment is lower than the NFT price. You have to send " || $expectedAmount || " bytes"); |
| 547 | |
| 548 | $pendingNaming = var["NFT_" || var["recordToData"]]; |
| 549 | }", |
| 550 | "messages": [ |
| 551 | { |
| 552 | "app": "payment", |
| 553 | "if": "{ |
| 554 | floor($expectedAmount * (1 - $FEE), 0) > 0 |
| 555 | }", |
| 556 | "payload": { |
| 557 | "asset": "base", |
| 558 | "outputs": [ |
| 559 | { |
| 560 | "address": "{$NFT.author}", |
| 561 | "amount": "{floor($expectedAmount * (1 - $FEE) - 10000, 0)}" |
| 562 | }, |
| 563 | { |
| 564 | "if": "{$NFT.validity}", |
| 565 | "address": "{$USER_REGISTRY_ADDRESS}", |
| 566 | "amount": 1 |
| 567 | }, |
| 568 | { |
| 569 | "if": "{ |
| 570 | trigger.data["r"] |
| 571 | AND is_valid_address(trigger.data["r"]) |
| 572 | AND trigger.data["r"] != $NFT.author |
| 573 | AND floor($expectedAmount * ($FEE / 2), 0) > 7000 |
| 574 | }", |
| 575 | "init": "{ |
| 576 | $profile = $USER_REGISTRY_ADDRESS.$profileOf(trigger.data["r"]); |
| 577 | if (NOT $profile.verified OR NOT $profile.isReseller) |
| 578 | bounce("The website you are buying the license from is not an approved reseller"); |
| 579 | }", |
| 580 | "address": "{trigger.data["r"]}", |
| 581 | "amount": "{floor($expectedAmount * ($FEE / 2), 0)}" |
| 582 | } |
| 583 | ] |
| 584 | } |
| 585 | }, |
| 586 | { |
| 587 | "app": "payment", |
| 588 | "payload": { |
| 589 | "asset": "{trigger.data['NFT']}", |
| 590 | "outputs": [ |
| 591 | { |
| 592 | "address": "{trigger.address}", |
| 593 | "amount": "{$periods}" |
| 594 | } |
| 595 | ] |
| 596 | } |
| 597 | }, |
| 598 | { |
| 599 | "app": "data", |
| 600 | "if": "{ |
| 601 | $pendingNaming OR $NFT.validity |
| 602 | }", |
| 603 | "init": "{ |
| 604 | $payload = ($pendingNaming ? { |
| 605 | asset: var["recordToData"], |
| 606 | name: ($pendingNaming.ticker OTHERWISE "Untitled") || " license", |
| 607 | author: $pendingNaming.author, |
| 608 | ipfs: $pendingNaming.ipfs, |
| 609 | type: "LIC", |
| 610 | decimals: 0 |
| 611 | } : {}) || ($NFT.validity ? {NFT: trigger.data["NFT"], time: $NFT.validity * $periods, method: "addTime"} : {}); |
| 612 | }", |
| 613 | "payload": "{$payload}" |
| 614 | }, |
| 615 | { |
| 616 | "app": "state", |
| 617 | "state": "{ |
| 618 | if ($pendingNaming) |
| 619 | var["recordToData"] = false; |
| 620 | if (is_integer($NFT.unitsSold)){ |
| 621 | $NFT.unitsSold = $NFT.unitsSold + 1; |
| 622 | if (var["NFT_" || trigger.data["NFT"]]) |
| 623 | var["NFT_" || trigger.data["NFT"]] = $NFT; |
| 624 | else |
| 625 | var["FREE_" || trigger.data["NFT"]] = $NFT; |
| 626 | } |
| 627 | }" |
| 628 | } |
| 629 | ] |
| 630 | }, |
| 631 | { |
| 632 | "if": "{ |
| 633 | $method == "CHANGE_PRICE" |
| 634 | }", |
| 635 | "init": "{ |
| 636 | if (NOT exists(trigger.data["NFT"])) |
| 637 | bounce("NFT field is mandatory"); |
| 638 | |
| 639 | $currency = $CURRENCY_REGISTRY.$getCurrency(trigger.data["currency"]); |
| 640 | |
| 641 | if (NOT exists(trigger.data["price"])) |
| 642 | bounce("price field is mandatory"); |
| 643 | if (NOT exists(trigger.data["currency"])){ |
| 644 | if (trigger.data["price"] < 20000) |
| 645 | bounce("price must be greater than 20.000 bytes"); |
| 646 | if (NOT is_valid_amount(trigger.data["price"])) |
| 647 | bounce("price is invalid"); |
| 648 | } |
| 649 | else{ |
| 650 | if (NOT $currency) |
| 651 | bounce("That currency is unsupported"); |
| 652 | } |
| 653 | |
| 654 | $price = trigger.data["currency"] ? $CURRENCY_REGISTRY.$convert(trigger.data["price"], trigger.data["currency"]) : trigger.data["price"]; |
| 655 | |
| 656 | if ($price <= 0) |
| 657 | bounce("price field must be higher than 0"); |
| 658 | |
| 659 | $NFT = var["NFT_" || trigger.data["NFT"]] OTHERWISE var["FREE_" || trigger.data["NFT"]]; |
| 660 | |
| 661 | $isRegisteredNFT = var["NFT_" || trigger.data["NFT"]]; |
| 662 | |
| 663 | if (NOT $NFT) |
| 664 | bounce("NFT not found"); |
| 665 | |
| 666 | if ($NFT.author != trigger.address) |
| 667 | bounce("You can only change the price of your own licenses!"); |
| 668 | }", |
| 669 | "messages": [ |
| 670 | { |
| 671 | "app": "state", |
| 672 | "state": "{ |
| 673 | var[($isRegisteredNFT ? "NFT_" : "FREE_") || trigger.data["NFT"]] ||= { |
| 674 | price: $price, |
| 675 | currency: trigger.data["currency"] OTHERWISE false |
| 676 | }; |
| 677 | }" |
| 678 | } |
| 679 | ] |
| 680 | }, |
| 681 | { |
| 682 | "if": "{ |
| 683 | $method == "REDEEM" |
| 684 | }", |
| 685 | "init": "{ |
| 686 | if (NOT exists(trigger.data["signed_message"])) |
| 687 | bounce("signed_message field is mandatory"); |
| 688 | if (NOT exists(trigger.data["authors"])) |
| 689 | bounce('authors field is mandatory'); |
| 690 | |
| 691 | $spack = { |
| 692 | signed_message: trigger.data["signed_message"], |
| 693 | authors: trigger.data["authors"] |
| 694 | } || trigger.data["meta"]; |
| 695 | |
| 696 | if ($spack.signed_message["amount"]) |
| 697 | if (NOT is_integer($spack.signed_message["amount"])) |
| 698 | bounce("You cannot redeem fractional license periods"); |
| 699 | |
| 700 | if (NOT is_valid_signed_package($spack, $spack.authors[0]["address"])) |
| 701 | bounce("The signed message signature is invalid"); |
| 702 | if (NOT $spack.signed_message["serial"]) |
| 703 | bounce("The signed message does not contains a serial field"); |
| 704 | if (NOT $spack.signed_message["NFT"]) |
| 705 | bounce("The signer of this message did not include a NFT field"); |
| 706 | |
| 707 | |
| 708 | if (var["CODE_" || $spack.signed_message["NFT"] || "_" || sha256($spack.signed_message["serial"])]) |
| 709 | bounce("That code was already redeemed"); |
| 710 | |
| 711 | |
| 712 | if ($spack.signed_message["claimer"]) |
| 713 | if ($spack.signed_message["claimer"] != trigger.address) |
| 714 | bounce("You cannot claim that NFT from that address"); |
| 715 | |
| 716 | |
| 717 | $NFT = var["NFT_" || $spack.signed_message["NFT"]] OTHERWISE var["FREE_" || $spack.signed_message["NFT"]]; |
| 718 | |
| 719 | if (NOT $NFT) |
| 720 | bounce("That license does not exist"); |
| 721 | |
| 722 | if ($spack.signed_message["expireDate"]){ |
| 723 | if ($NFT.soldAt){ |
| 724 | if ($NFT.soldAt < timestamp) |
| 725 | bounce("The sale of that license has already ended. You cannot claim a copy of it"); |
| 726 | } |
| 727 | if ($spack.signed_message["expireDate"] < timestamp){ |
| 728 | bounce("That NFT is no longer claimable"); |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | $signedAmount = $spack.signed_message["amount"] OTHERWISE 1; |
| 733 | |
| 734 | if ($NFT.author != $spack.authors[0].address) |
| 735 | bounce("The signer of that message is not the issuer of that license"); |
| 736 | |
| 737 | |
| 738 | if (NOT $NFT.cap){ |
| 739 | $periods = $signedAmount; |
| 740 | } |
| 741 | |
| 742 | else { |
| 743 | if ($NFT.unitsSold + $signedAmount > $NFT.cap) |
| 744 | $periods = $NFT.cap - $NFT.unitsSold; |
| 745 | else |
| 746 | $periods = $signedAmount; |
| 747 | } |
| 748 | |
| 749 | |
| 750 | if ($periods == 0) |
| 751 | bounce("All copies of that NFT have been already minted"); |
| 752 | }", |
| 753 | "messages": [ |
| 754 | { |
| 755 | "app": "payment", |
| 756 | "payload": { |
| 757 | "asset": "{$spack.signed_message["NFT"]}", |
| 758 | "outputs": [ |
| 759 | { |
| 760 | "address": "{trigger.address}", |
| 761 | "amount": "{$periods}" |
| 762 | }, |
| 763 | { |
| 764 | "if": "{$NFT.validity}", |
| 765 | "address": "{$USER_REGISTRY_ADDRESS}", |
| 766 | "amount": 1 |
| 767 | } |
| 768 | ] |
| 769 | } |
| 770 | }, |
| 771 | { |
| 772 | "if": "{ |
| 773 | $NFT.validity |
| 774 | }", |
| 775 | "app": "data", |
| 776 | "payload": { |
| 777 | "NFT": "{$spack.signed_message["NFT"]}", |
| 778 | "time": "{$signedAmount * $NFT.validity}" |
| 779 | } |
| 780 | }, |
| 781 | { |
| 782 | "app": "state", |
| 783 | "state": "{ |
| 784 | if (is_integer($NFT.unitsSold)) |
| 785 | $NFT.unitsSold = $NFT.unitsSold + 1; |
| 786 | if (var["NFT_" || $spack.signed_message["NFT"]]) |
| 787 | var["NFT_" || $spack.signed_message["NFT"]] = $NFT; |
| 788 | else |
| 789 | var["FREE_" || $spack.signed_message["NFT"]] = $NFT; |
| 790 | var["CODE_" || $spack.signed_message["NFT"] || "_" || sha256($spack.signed_message["serial"])] = true; |
| 791 | }" |
| 792 | } |
| 793 | ] |
| 794 | } |
| 795 | ] |
| 796 | } |
| 797 | } |
| 798 | ] |