| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "init": "{ |
| 8 | $HOUSE_CUT = 0.03; |
| 9 | $BYTES_IN_GBYTE = 1000000000; |
| 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; |
| 17 | $owner = var["owner"]; |
| 18 | $isHelper = var["helper_" || trigger.address]; |
| 19 | $oracle = var["oracle"]; |
| 20 | $getNFTInfo = $NFT=>{ |
| 21 | $unit = unit[$NFT]; |
| 22 | /* |
| 23 | ** Info should have at least 'author' field. 'ipfs' and 'type' field is also recommended. |
| 24 | */ |
| 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 | }", |
| 37 | "messages": { |
| 38 | "cases": [ |
| 39 | { |
| 40 | "if": "{ |
| 41 | NOT $owner |
| 42 | }", |
| 43 | "messages": [ |
| 44 | { |
| 45 | "app": "state", |
| 46 | "state": "{ |
| 47 | var["owner"] = "IUU43O7TS2TBYKAPGKUARDZHOTAE275A"; |
| 48 | var["oracle"] = "F4KHJUCLJKY4JV7M5F754LAJX4EB7M4N"; |
| 49 | }" |
| 50 | } |
| 51 | ] |
| 52 | }, |
| 53 | { |
| 54 | "if": "{ |
| 55 | trigger.address == $owner |
| 56 | AND ($method == "payout" |
| 57 | OR $method == "stopSale" |
| 58 | OR $method == "transferOwnership" |
| 59 | OR $method == "setOracle" |
| 60 | OR $method == "setHelper" |
| 61 | OR $method == "removeHelper") |
| 62 | }", |
| 63 | "messages": { |
| 64 | "cases": [ |
| 65 | { |
| 66 | "if": "{ |
| 67 | $method == "payout" |
| 68 | }", |
| 69 | "messages": [ |
| 70 | { |
| 71 | "app": "payment", |
| 72 | "payload": { |
| 73 | "asset": "base", |
| 74 | "outputs": [ |
| 75 | { |
| 76 | "address": "{trigger.address}", |
| 77 | "amount": "{$spendableFunds}" |
| 78 | } |
| 79 | ] |
| 80 | } |
| 81 | } |
| 82 | ] |
| 83 | }, |
| 84 | { |
| 85 | "if": "{ |
| 86 | $method == "transferOwnership" |
| 87 | }", |
| 88 | "init": "{ |
| 89 | if (NOT exists(trigger.data["newOwner"])) |
| 90 | bounce("newOwner field is mandatory"); |
| 91 | if (NOT is_valid_address(trigger.data["newOwner"])) |
| 92 | bounce("newOwner field is not a valid address"); |
| 93 | }", |
| 94 | "messages": [ |
| 95 | { |
| 96 | "app": "payment", |
| 97 | "payload": { |
| 98 | "asset": "base", |
| 99 | "outputs": [ |
| 100 | { |
| 101 | "address": "{trigger.address}", |
| 102 | "amount": "{$spendableFunds}" |
| 103 | } |
| 104 | ] |
| 105 | } |
| 106 | }, |
| 107 | { |
| 108 | "app": "state", |
| 109 | "state": "{ |
| 110 | var["owner"] = trigger.data["newOwner"]; |
| 111 | }" |
| 112 | } |
| 113 | ] |
| 114 | }, |
| 115 | { |
| 116 | "if": "{ |
| 117 | $method == "setOracle" |
| 118 | }", |
| 119 | "init": "{ |
| 120 | if (NOT exists(trigger.data["oracle"])) |
| 121 | bounce("oracle field is mandatory"); |
| 122 | if (NOT is_valid_address(trigger.data["oracle"])) |
| 123 | bounce("Invalid oracle address"); |
| 124 | if (NOT data_feed[[oracles=trigger.data["oracle"], feed_name="GBYTE_USD", ifseveral="last"]]) |
| 125 | bounce("That oracle is not posting a GBYTE_USD datafeed"); |
| 126 | }", |
| 127 | "messages": [ |
| 128 | { |
| 129 | "app": "state", |
| 130 | "state": "{ |
| 131 | var["oracle"] = trigger.data["oracle"]; |
| 132 | }" |
| 133 | } |
| 134 | ] |
| 135 | }, |
| 136 | { |
| 137 | "if": "{ |
| 138 | $method == "setHelper" |
| 139 | }", |
| 140 | "init": "{ |
| 141 | if (NOT exists(trigger.data["helper"])) |
| 142 | bounce("helper field is mandatory"); |
| 143 | if (NOT is_valid_address(trigger.data["helper"])) |
| 144 | bounce("helper address is invalid"); |
| 145 | }", |
| 146 | "messages": [ |
| 147 | { |
| 148 | "app": "state", |
| 149 | "state": "{ |
| 150 | var["helper_" || trigger.data["helper"]] = true; |
| 151 | }" |
| 152 | } |
| 153 | ] |
| 154 | }, |
| 155 | { |
| 156 | "if": "{ |
| 157 | $method == "removeHelper" |
| 158 | }", |
| 159 | "init": "{ |
| 160 | if (NOT exists(trigger.data["helper"])) |
| 161 | bounce("helper field is mandatory"); |
| 162 | if (NOT is_valid_address(trigger.data["helper"])) |
| 163 | bounce("helper address is invalid"); |
| 164 | }", |
| 165 | "messages": [ |
| 166 | { |
| 167 | "app": "state", |
| 168 | "state": "{ |
| 169 | var["helper_" || trigger.data["helper"]] = false; |
| 170 | }" |
| 171 | } |
| 172 | ] |
| 173 | } |
| 174 | ] |
| 175 | } |
| 176 | }, |
| 177 | { |
| 178 | "if": "{ |
| 179 | (trigger.address == $owner OR $isHelper) |
| 180 | AND $method == "trust" |
| 181 | }", |
| 182 | "init": "{ |
| 183 | if (NOT trigger.data["user"]) |
| 184 | bounce("user field is mandatory"); |
| 185 | if (NOT is_valid_address(trigger.data["user"])) |
| 186 | bounce("user field is an invalid address"); |
| 187 | }", |
| 188 | "messages": [ |
| 189 | { |
| 190 | "app": "state", |
| 191 | "state": "{ |
| 192 | var["trusted_" || trigger.data["user"]] = true; |
| 193 | }" |
| 194 | } |
| 195 | ] |
| 196 | }, |
| 197 | { |
| 198 | "if": "{ |
| 199 | (trigger.address == $owner OR $isHelper) |
| 200 | AND $method == "untrust" |
| 201 | }", |
| 202 | "init": "{ |
| 203 | if (NOT trigger.data["user"]) |
| 204 | bounce("user field is mandatory"); |
| 205 | if (NOT is_valid_address(trigger.data["user"])) |
| 206 | bounce("user field is an invalid address"); |
| 207 | }", |
| 208 | "messages": [ |
| 209 | { |
| 210 | "app": "state", |
| 211 | "state": "{ |
| 212 | var["trusted_" || trigger.data["user"]] = false; |
| 213 | }" |
| 214 | } |
| 215 | ] |
| 216 | }, |
| 217 | { |
| 218 | "if": "{ |
| 219 | $method == "MINT" |
| 220 | }", |
| 221 | "init": "{ |
| 222 | if (NOT exists(trigger.data["amount"])) |
| 223 | bounce("amount field is mandatory. Set it to 0 for unlimited"); |
| 224 | |
| 225 | if ((NOT is_valid_amount(trigger.data["amount"])) AND trigger.data["amount"] != 0) |
| 226 | bounce("The amount of NFT copies to mint is not valid"); |
| 227 | |
| 228 | $price = trigger.data["priceUSD"] OTHERWISE trigger.data["price"]; |
| 229 | $isTrusted = trigger.data["trusted_" || trigger.address]; |
| 230 | |
| 231 | if (NOT $price OR $price < 0) |
| 232 | bounce("price or priceUSD field must be filled and it must be a positive number"); |
| 233 | |
| 234 | if (NOT exists(trigger.data["priceUSD"])){ |
| 235 | if ($price < 20000) |
| 236 | bounce("The minium price is 20000 bytes"); |
| 237 | if (NOT is_valid_amount($price)) |
| 238 | bounce("price is not valid"); |
| 239 | } |
| 240 | |
| 241 | if (exists(trigger.data["maxPeriods"])){ |
| 242 | if (NOT is_integer(trigger.data["maxPeriods"])) |
| 243 | bounce("maxPeriods must be an integer"); |
| 244 | |
| 245 | if (trigger.data["maxPeriods"] <= 0) |
| 246 | bounce("maxPeriods must be positive"); |
| 247 | |
| 248 | if (NOT exists(trigger.data["validity"])) |
| 249 | bounce("If you set maxPeriods you have to set validity too"); |
| 250 | } |
| 251 | |
| 252 | if (exists(trigger.data["validity"])){ |
| 253 | if (NOT is_integer(trigger.data["validity"])) |
| 254 | bounce("validity must be an integer"); |
| 255 | |
| 256 | if (trigger.data["validity"] <= 0) |
| 257 | bounce("You cannot make a license valid for 0s or less"); |
| 258 | } |
| 259 | |
| 260 | if (trigger.address == $owner OR $isTrusted){ |
| 261 | if (NOT exists(trigger.data["ipfs"])) |
| 262 | bounce("ipfs field is mandatory"); |
| 263 | |
| 264 | if (NOT exists(trigger.data["title"])) |
| 265 | bounce("title field is mandatory"); |
| 266 | if (length(trigger.data["title"]) > 512) |
| 267 | bounce("The license title must be at most 512 characters long"); |
| 268 | |
| 269 | if (exists(trigger.data["name"])){ |
| 270 | if (length(trigger.data["name"] < 128)) |
| 271 | bounce("The length of the license ticker must be at most 128 characters long"); |
| 272 | } |
| 273 | |
| 274 | if (trigger.address == $owner){ |
| 275 | if (NOT exists(trigger.data["seller"])) |
| 276 | bounce("seller field is mandatory"); |
| 277 | |
| 278 | if (NOT is_valid_address(trigger.data["seller"])) |
| 279 | bounce("The seller address is not valid"); |
| 280 | } |
| 281 | |
| 282 | $pendingNaming = var["NFT_" || var["pendingNaming"]]; |
| 283 | } |
| 284 | |
| 285 | if (exists(trigger.data["soldAt"])){ |
| 286 | if (NOT is_integer(trigger.data["soldAt"])) |
| 287 | bounce("soldAt must be an integer"); |
| 288 | if (trigger.data["soldAt"] <= timestamp) |
| 289 | bounce("soldAt cannot be set in the past"); |
| 290 | } |
| 291 | |
| 292 | $isTransferrable = exists(trigger.data["validity"]) |
| 293 | ? false |
| 294 | : trigger.data["transferrable"] == "true" ? true : false; |
| 295 | }", |
| 296 | "messages": { |
| 297 | "cases": [ |
| 298 | { |
| 299 | "if": "{ |
| 300 | trigger.data["amount"] |
| 301 | }", |
| 302 | "messages": [ |
| 303 | { |
| 304 | "app": "asset", |
| 305 | "payload": { |
| 306 | "cap": "{trigger.data["amount"]}", |
| 307 | "is_private": false, |
| 308 | "is_transferrable": "{$isTransferrable}", |
| 309 | "auto_destroy": false, |
| 310 | "fixed_denominations": false, |
| 311 | "issued_by_definer_only": true, |
| 312 | "cosigned_by_definer": false, |
| 313 | "spender_attested": false |
| 314 | } |
| 315 | }, |
| 316 | { |
| 317 | "app": "data", |
| 318 | "if": "{ |
| 319 | $pendingNaming |
| 320 | }", |
| 321 | "payload": { |
| 322 | "asset": "{var["recordToData"]}", |
| 323 | "name": "{($pendingNaming.title OTHERWISE "Untitled")|| " license"}", |
| 324 | "author": "{$pendingNaming.author}", |
| 325 | "ipfs": "{$pendingNaming.ipfs}", |
| 326 | "type": "LIC", |
| 327 | "decimals": 0 |
| 328 | } |
| 329 | }, |
| 330 | { |
| 331 | "app": "state", |
| 332 | "state": "{ |
| 333 | if (trigger.address == $owner OR $isTrusted){ |
| 334 | var["NFT_" || response_unit] = { |
| 335 | price: trigger.data["price"] OTHERWISE false, |
| 336 | priceUSD: trigger.data["priceUSD"] OTHERWISE false, |
| 337 | title: trigger.data["title"], |
| 338 | ipfs: trigger.data["ipfs"], |
| 339 | author: trigger.data["seller"], |
| 340 | validity: trigger.data["validity"] OTHERWISE false, |
| 341 | maxPeriods: trigger.data["maxPeriods"] OTHERWISE false, |
| 342 | soldAt: trigger.data["soldAt"] OTHERWISE false, |
| 343 | onSale: true, |
| 344 | type: 'LIC' |
| 345 | }; |
| 346 | |
| 347 | var["pendingNaming"] = response_unit; |
| 348 | } |
| 349 | else{ |
| 350 | var["FREE_" || response_unit] = { |
| 351 | price: trigger.data["price"] OTHERWISE false, |
| 352 | priceUSD: trigger.data["priceUSD"] OTHERWISE false, |
| 353 | author: trigger.address, |
| 354 | validity: trigger.data["validity"], |
| 355 | maxPeriods: trigger.data["maxPeriods"], |
| 356 | soldAt: trigger.data["soldAt"] OTHERWISE false, |
| 357 | onSale: true, |
| 358 | type: 'LIC' |
| 359 | }; |
| 360 | } |
| 361 | }" |
| 362 | } |
| 363 | ] |
| 364 | }, |
| 365 | { |
| 366 | "messages": [ |
| 367 | { |
| 368 | "app": "asset", |
| 369 | "payload": { |
| 370 | "is_private": false, |
| 371 | "is_transferrable": "{$isTransferrable}", |
| 372 | "auto_destroy": false, |
| 373 | "fixed_denominations": false, |
| 374 | "issued_by_definer_only": true, |
| 375 | "cosigned_by_definer": false, |
| 376 | "spender_attested": false |
| 377 | } |
| 378 | }, |
| 379 | { |
| 380 | "app": "data", |
| 381 | "if": "{ |
| 382 | $pendingNaming |
| 383 | }", |
| 384 | "payload": { |
| 385 | "asset": "{var["recordToData"]}", |
| 386 | "name": "{($pendingNaming.title OTHERWISE "Untitled")|| " license"}", |
| 387 | "author": "{$pendingNaming.author}", |
| 388 | "ipfs": "{$pendingNaming.ipfs}", |
| 389 | "type": "LIC", |
| 390 | "decimals": 0 |
| 391 | } |
| 392 | }, |
| 393 | { |
| 394 | "app": "state", |
| 395 | "state": "{ |
| 396 | if (trigger.address == $owner OR $isTrusted){ |
| 397 | var["NFT_" || response_unit] = { |
| 398 | price: trigger.data["price"] OTHERWISE false, |
| 399 | priceUSD: trigger.data["priceUSD"] OTHERWISE false, |
| 400 | title: trigger.data["title"], |
| 401 | ipfs: trigger.data["ipfs"], |
| 402 | author: trigger.data["seller"], |
| 403 | validity: trigger.data["validity"] OTHERWISE false, |
| 404 | maxPeriods: trigger.data["maxPeriods"] OTHERWISE false, |
| 405 | onSale: true, |
| 406 | type: 'LIC' |
| 407 | }; |
| 408 | |
| 409 | var["pendingNaming"] = response_unit; |
| 410 | } |
| 411 | else{ |
| 412 | var["FREE_" || response_unit] = { |
| 413 | price: trigger.data["price"] OTHERWISE false, |
| 414 | priceUSD: trigger.data["priceUSD"] OTHERWISE false, |
| 415 | author: trigger.address, |
| 416 | validity: trigger.data["validity"], |
| 417 | maxPeriods: trigger.data["maxPeriods"], |
| 418 | onSale: true, |
| 419 | type: 'LIC' |
| 420 | }; |
| 421 | } |
| 422 | }" |
| 423 | } |
| 424 | ] |
| 425 | } |
| 426 | ] |
| 427 | } |
| 428 | }, |
| 429 | { |
| 430 | "if": "{ |
| 431 | $method == "END_SALE" |
| 432 | }", |
| 433 | "init": "{ |
| 434 | if (NOT exists(trigger.data["NFT"])) |
| 435 | bounce("NFT field is mandatory"); |
| 436 | |
| 437 | $NFT = var["NFT_" || trigger.data["NFT"]] OTHERWISE var["FREE_" || trigger.data["NFT"]]; |
| 438 | |
| 439 | if (NOT $NFT) |
| 440 | bounce("That NFT is not known by this AA"); |
| 441 | |
| 442 | if (trigger.address != $NFT.author) |
| 443 | bounce("You cannot stop a sale not created by yourself"); |
| 444 | }", |
| 445 | "messages": [ |
| 446 | { |
| 447 | "app": "state", |
| 448 | "state": "{ |
| 449 | if (var["NFT_" || trigger.data["NFT"]]) |
| 450 | var["NFT_" || trigger.data["NFT"]] ||= {onSale: false}; |
| 451 | else |
| 452 | var["FREE_" || trigger.data["NFT"]] ||= {onSale: false}; |
| 453 | }" |
| 454 | } |
| 455 | ] |
| 456 | }, |
| 457 | { |
| 458 | "if": "{ |
| 459 | trigger.data["method"] == "BUY" |
| 460 | }", |
| 461 | "init": "{ |
| 462 | $NFT = var["NFT_" || trigger.data["NFT"]] OTHERWISE var["FREE_" || trigger.data["NFT"]]; |
| 463 | $previousExpiry = var[trigger.address || "_" || trigger.data["NFT"]] OTHERWISE timestamp; |
| 464 | |
| 465 | if ($NFT.soldAt){ |
| 466 | if ($NFT.soldAt < timestamp) |
| 467 | bounce("That license sale period ended on " || timestamp_to_string($NFT.soldAt) || " UTC"); |
| 468 | } |
| 469 | |
| 470 | if (NOT $NFT.onSale) |
| 471 | bounce("The owner of that license cancelled its sale. No more copies will be ever sold."); |
| 472 | |
| 473 | if (exists(trigger.data["periods"])){ |
| 474 | if (NOT is_integer(trigger.data["periods"])) |
| 475 | bounce("periods must be an integer"); |
| 476 | |
| 477 | if ($NFT.validity AND $NFT.maxPeriods){ |
| 478 | if ($previousExpiry + trigger.data["periods"] * $NFT.validity > timestamp + ($NFT.maxPeriods OTHERWISE 1) * $NFT.validity) |
| 479 | bounce("You cannot buy that many periods in advance. You have to wait until your license is closer to expiry date"); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | $periods = trigger.data["periods"] OTHERWISE 1; |
| 484 | |
| 485 | $expectedAmount = $periods * ($NFT.price |
| 486 | ? $NFT.price |
| 487 | : round($NFT.priceUSD * 1 / data_feed[[oracles=$oracle, feed_name="GBYTE_USD", ifseveral="last"]] * $BYTES_IN_GBYTE, 0)); |
| 488 | |
| 489 | if (trigger.output[[asset="base"]].amount < $expectedAmount) |
| 490 | bounce("Your payment is lower than the NFT price. You have to send " || $expectedAmount || " bytes"); |
| 491 | |
| 492 | $pendingNaming = var["NFT_" || var["recordToData"]]; |
| 493 | }", |
| 494 | "messages": [ |
| 495 | { |
| 496 | "app": "payment", |
| 497 | "if": "{ |
| 498 | floor($expectedAmount * (1 - $HOUSE_CUT), 0) > 0 |
| 499 | }", |
| 500 | "payload": { |
| 501 | "asset": "base", |
| 502 | "outputs": [ |
| 503 | { |
| 504 | "address": "{$NFT.author}", |
| 505 | "amount": "{floor($expectedAmount * (1 - $HOUSE_CUT), 0)}" |
| 506 | } |
| 507 | ] |
| 508 | } |
| 509 | }, |
| 510 | { |
| 511 | "app": "payment", |
| 512 | "payload": { |
| 513 | "asset": "{trigger.data['NFT']}", |
| 514 | "outputs": [ |
| 515 | { |
| 516 | "address": "{trigger.address}", |
| 517 | "amount": "{$periods}" |
| 518 | } |
| 519 | ] |
| 520 | } |
| 521 | }, |
| 522 | { |
| 523 | "app": "data", |
| 524 | "if": "{ |
| 525 | $pendingNaming |
| 526 | }", |
| 527 | "payload": { |
| 528 | "asset": "{var["recordToData"]}", |
| 529 | "name": "{($pendingNaming.title OTHERWISE "Untitled") || " license"}", |
| 530 | "author": "{$pendingNaming.author}", |
| 531 | "ipfs": "{$pendingNaming.ipfs}", |
| 532 | "type": "LIC", |
| 533 | "decimals": 0 |
| 534 | } |
| 535 | }, |
| 536 | { |
| 537 | "app": "state", |
| 538 | "state": "{ |
| 539 | if ($pendingNaming){ |
| 540 | var["recordToData"] = false; |
| 541 | } |
| 542 | if ($NFT.validity){ |
| 543 | var[trigger.address || "_" || trigger.data["NFT"]] = $previousExpiry + $NFT.validity * $periods; |
| 544 | } |
| 545 | }" |
| 546 | } |
| 547 | ] |
| 548 | }, |
| 549 | { |
| 550 | "if": "{ |
| 551 | $method == "CHANGE_PRICE" |
| 552 | }", |
| 553 | "init": "{ |
| 554 | if (NOT exists(trigger.data["NFT"])) |
| 555 | bounce("NFT field is mandatory"); |
| 556 | |
| 557 | $NFT = var["NFT_" || trigger.data["NFT"]] OTHERWISE var["FREE_" || trigger.data["NFT"]]; |
| 558 | |
| 559 | $isRegisteredNFT = var["NFT_" || trigger.data["NFT"]]; |
| 560 | |
| 561 | if (NOT $NFT) |
| 562 | bounce("NFT not found"); |
| 563 | |
| 564 | if ($NFT.author != trigger.address) |
| 565 | bounce("You can only change the price of your own licenses!"); |
| 566 | |
| 567 | if (exists(trigger.data["price"])){ |
| 568 | if (NOT is_integer(trigger.data["price"])) |
| 569 | bounce("price must be an integer"); |
| 570 | if (NOT is_valid_amount(trigger.data["price"]) OR trigger.data["price"] < 20000) |
| 571 | bounce("price must be at least 20.000 bytes"); |
| 572 | if (exists(trigger.data["priceUSD"])) |
| 573 | bounce("You cannot set price and priceUSD at the same time"); |
| 574 | } |
| 575 | |
| 576 | if (NOT exists(trigger.data["price"]) AND NOT exists(trigger.data["priceUSD"])) |
| 577 | bounce("You have to provide either price or priceUSD field"); |
| 578 | |
| 579 | $price = trigger.data["price"] OTHERWISE trigger.data["priceUSD"]; |
| 580 | }", |
| 581 | "messages": [ |
| 582 | { |
| 583 | "app": "state", |
| 584 | "state": "{ |
| 585 | if ($isRegisteredNFT){ |
| 586 | var[($isRegisteredNFT ? "NFT_" : "FREE_") || trigger.data["NFT"]] ||= { |
| 587 | price: exists(trigger.data["price"]) ? $price : false, |
| 588 | priceUSD: exists(trigger.data["priceUSD"]) ? $price : false, |
| 589 | }; |
| 590 | } |
| 591 | }" |
| 592 | } |
| 593 | ] |
| 594 | }, |
| 595 | { |
| 596 | "if": "{ |
| 597 | $method == "REDEEM" |
| 598 | }", |
| 599 | "init": "{ |
| 600 | if (NOT exists(trigger.data["spack"])) |
| 601 | bounce("You need to provide a signed package"); |
| 602 | |
| 603 | $spack = json_parse(trigger.data["spack"]); |
| 604 | |
| 605 | if ($spack.signed_message.claimer){ |
| 606 | if (NOT is_valid_address($spack.signed_message.claimer)) |
| 607 | bounce("The claimer field of that code is invalid"); |
| 608 | if ($spack.signed_message.claimer != trigger.address) |
| 609 | bounce("That code can only be redeemed by " || $spack.signed_message.claimer); |
| 610 | } |
| 611 | |
| 612 | if (NOT is_valid_signed_package($spack, $spack.authors[0].address)) |
| 613 | bounce("The signed message signature is invalid"); |
| 614 | if (NOT $spack.signed_message.NFT) |
| 615 | bounce("The signer of this message did not include a NFT field"); |
| 616 | |
| 617 | $NFT = var["NFT_" || $spack.signed_message.NFT] OTHERWISE var["FREE_" || $spack.signed_message.NFT]; |
| 618 | |
| 619 | if (NOT $NFT) |
| 620 | bounce("That license does not exist"); |
| 621 | |
| 622 | |
| 623 | if ($spack.signed_message.expireDate){ |
| 624 | if ($spack.signed_message.expireDate < timestamp) |
| 625 | bounce("That license is no longer claimable"); |
| 626 | } |
| 627 | $signedAmount = $spack.signed_message.amount OTHERWISE 1; |
| 628 | |
| 629 | if ($NFT.author != $spack.authors[0].address) |
| 630 | bounce("The signer of that message is not the author of that license"); |
| 631 | }", |
| 632 | "messages": [ |
| 633 | { |
| 634 | "app": "payment", |
| 635 | "payload": { |
| 636 | "asset": "{$spack.signed_message.NFT}", |
| 637 | "outputs": [ |
| 638 | { |
| 639 | "address": "{trigger.address}", |
| 640 | "amount": "{$NFT.signedAmount}" |
| 641 | } |
| 642 | ] |
| 643 | } |
| 644 | }, |
| 645 | { |
| 646 | "app": "state", |
| 647 | "state": "{ |
| 648 | if ($NFT.validity){ |
| 649 | var[trigger.address || "_" || $spack.signed_message.NFT] = (var[trigger.address || "_" || $spack.signed_message.NFT] OTHERWISE 0) + $NFT.signedAmount * $NFT.validity; |
| 650 | } |
| 651 | }" |
| 652 | } |
| 653 | ] |
| 654 | } |
| 655 | ] |
| 656 | } |
| 657 | } |
| 658 | ] |