| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "getters": "{ |
| 5 | $_validateMetadata = $meta=>{ |
| 6 | if (NOT $meta.title) |
| 7 | bounce("The NFT metadata lacks a required title field"); |
| 8 | if (NOT $meta.ipfs) |
| 9 | bounce("The NFT metadata lacks a required ipfs field"); |
| 10 | if (NOT $meta.type) |
| 11 | bounce("The NFT metadata lacks a required type field"); |
| 12 | }; |
| 13 | $_validateAssetMetadata = $meta=>{ |
| 14 | if ($meta.is_private) |
| 15 | bounce("An NFT asset cannot be private"); |
| 16 | if ($meta.cosigned_by_definer) |
| 17 | bounce("We cannot accept NFTs with the cosigned_by_definer field since the definer cannot cosign an automated transaction"); |
| 18 | if ($meta.fixed_denominations) |
| 19 | bounce("Autonomous agents cannot deal with asset issued with fixed denominations"); |
| 20 | if ($meta.spender_attested) |
| 21 | bounce("We do not accept assets defined with the spender_attested option"); |
| 22 | if ($meta.transfer_condition) |
| 23 | bounce("We do not accept assets defined with the transfer_condition option"); |
| 24 | }; |
| 25 | $fetchNFT = $asset => { |
| 26 | $unitInfo = unit[$asset]; |
| 27 | if (NOT $unitInfo.messages) |
| 28 | bounce("Bad unit"); |
| 29 | $definedBy = $unitInfo.authors[0].authentifiers |
| 30 | ? $unitInfo.authors[0].address |
| 31 | : unit[$unitInfo.trigger_unit].authors[0].address; |
| 32 | $metadata = $unitInfo.messages[[.app='data']].payload; |
| 33 | $_validateMetadata($metadata); |
| 34 | $assetMetadata = $unitInfo.messages[[.app='asset']].payload; |
| 35 | $_validateAssetMetadata($assetMetadata); |
| 36 | return {asset: $assetMetadata, meta: $metadata}; |
| 37 | }; |
| 38 | }", |
| 39 | "messages": [ |
| 40 | { |
| 41 | "if": "{NOT var["a"]}", |
| 42 | "app": "data", |
| 43 | "payload": { |
| 44 | "title": "Untitled", |
| 45 | "author": "{trigger.address}", |
| 46 | "ipfs": "Qmmmsdmjsdjf", |
| 47 | "type": "IMG", |
| 48 | "decimals": 0 |
| 49 | } |
| 50 | }, |
| 51 | { |
| 52 | "app": "payment", |
| 53 | "payload": { |
| 54 | "outputs": [ |
| 55 | { |
| 56 | "address": "{this_address}", |
| 57 | "amount": 1000 |
| 58 | } |
| 59 | ] |
| 60 | } |
| 61 | }, |
| 62 | { |
| 63 | "app": "asset", |
| 64 | "payload": { |
| 65 | "cap": 1, |
| 66 | "is_private": false, |
| 67 | "is_transferrable": true, |
| 68 | "auto_destroy": false, |
| 69 | "fixed_denominations": false, |
| 70 | "issued_by_definer_only": true, |
| 71 | "cosigned_by_definer": false, |
| 72 | "spender_attested": false |
| 73 | } |
| 74 | }, |
| 75 | { |
| 76 | "if": "{var["a"]}", |
| 77 | "app": "data", |
| 78 | "payload": { |
| 79 | "nft": "{$fetchNFT(var["a"])}" |
| 80 | } |
| 81 | }, |
| 82 | { |
| 83 | "app": "state", |
| 84 | "state": "{ |
| 85 | var["a"] = response_unit; |
| 86 | }" |
| 87 | } |
| 88 | ] |
| 89 | } |
| 90 | ] |