| 1 | [ |
| 2 | "autonomous agent", |
| 3 | { |
| 4 | "bounce_fees": { |
| 5 | "base": 10000 |
| 6 | }, |
| 7 | "getters": "{ |
| 8 | $validate = $asset =>{ |
| 9 | $unitInfo = unit[$asset]; |
| 10 | if (NOT $unitInfo.messages) |
| 11 | return false; |
| 12 | $schema = $unitInfo.authors[0].authentifiers |
| 13 | ? false |
| 14 | : $unitInfo.authors[0].address; |
| 15 | if (NOT $schema) |
| 16 | return false; |
| 17 | if ($schema != this_address) |
| 18 | return false; |
| 19 | |
| 20 | return true; |
| 21 | }; |
| 22 | $isValidQmHash = $hash=>{ |
| 23 | $allowedChars = { |
| 24 | "1": true, |
| 25 | "2": true, |
| 26 | "3": true, |
| 27 | "4": true, |
| 28 | "5": true, |
| 29 | "6": true, |
| 30 | "7": true, |
| 31 | "8": true, |
| 32 | "9": true, |
| 33 | "A": true, |
| 34 | "B": true, |
| 35 | "C": true, |
| 36 | "D": true, |
| 37 | "E": true, |
| 38 | "F": true, |
| 39 | "G": true, |
| 40 | "H": true, |
| 41 | "J": true, |
| 42 | "K": true, |
| 43 | "L": true, |
| 44 | "M": true, |
| 45 | "N": true, |
| 46 | "P": true, |
| 47 | "Q": true, |
| 48 | "R": true, |
| 49 | "S": true, |
| 50 | "T": true, |
| 51 | "U": true, |
| 52 | "V": true, |
| 53 | "W": true, |
| 54 | "X": true, |
| 55 | "Y": true, |
| 56 | "Z": true, |
| 57 | "a": true, |
| 58 | "b": true, |
| 59 | "c": true, |
| 60 | "d": true, |
| 61 | "e": true, |
| 62 | "f": true, |
| 63 | "g": true, |
| 64 | "h": true, |
| 65 | "i": true, |
| 66 | "j": true, |
| 67 | "k": true, |
| 68 | "m": true, |
| 69 | "n": true, |
| 70 | "o": true, |
| 71 | "p": true, |
| 72 | "q": true, |
| 73 | "r": true, |
| 74 | "s": true, |
| 75 | "t": true, |
| 76 | "u": true, |
| 77 | "v": true, |
| 78 | "w": true, |
| 79 | "x": true, |
| 80 | "y": true, |
| 81 | "z": true |
| 82 | }; |
| 83 | $prefix = substring($hash, 0, 2); |
| 84 | $payload = substring($hash, 2); |
| 85 | if ($prefix != "Qm") |
| 86 | return false; |
| 87 | if (length($payload) != 44) |
| 88 | return false; |
| 89 | return reduce(split($payload, ""), 44, ($acc, $x)=>$allowedChars[$x] AND $acc, true); |
| 90 | }; |
| 91 | }", |
| 92 | "init": "{ |
| 93 | $BOUNCER = "CFUQKRS37OGK4NDQRI6VHFNWTGHHAJAC"; |
| 94 | $sendAsset = var[trigger.initial_address]; |
| 95 | response["sendAsset"] = $sendAsset; |
| 96 | if (NOT $sendAsset AND NOT exists(trigger.data["title"])) |
| 97 | bounce("title field is mandatory"); |
| 98 | if (trigger.data){ |
| 99 | if (NOT exists(trigger.data["title"])) |
| 100 | bounce("title field is mandatory"); |
| 101 | if (NOT exists(trigger.data["ipfs"])) |
| 102 | bounce("ipfs field is mandatory"); |
| 103 | if (NOT exists(trigger.data["type"])) |
| 104 | bounce("type field is mandatory"); |
| 105 | if (length(trigger.data["type"]) > 16) |
| 106 | bounce("type field must be shorter than 16 characters"); |
| 107 | if (exists(trigger.data["ticker"])){ |
| 108 | if (length(trigger.data["ticker"]) > 5) |
| 109 | bounce("ticker field must be shorter than 5 characters"); |
| 110 | } |
| 111 | if (NOT exists(trigger.data["copies"])) |
| 112 | bounce("copies field is mandatory"); |
| 113 | if (NOT is_integer(trigger.data["copies"])) |
| 114 | bounce("copies field must be an integer"); |
| 115 | if (trigger.data["copies"] < 1) |
| 116 | bounce("copies must be at least 1"); |
| 117 | if (exists(trigger.data["royalty"])){ |
| 118 | if (NOT is_integer(trigger.data["royalty"])) |
| 119 | bounce("royalty field must be an integer"); |
| 120 | if (trigger.data["royalty"] < 0) |
| 121 | bounce("royalty cannot be negative"); |
| 122 | if (trigger.data["royalty"] > 100) |
| 123 | bounce("royalty can't be higher than 100"); |
| 124 | } |
| 125 | if (NOT $isValidQmHash(trigger.data["ipfs"])) |
| 126 | bounce("IPFS hash is not a V0 CID"); |
| 127 | } |
| 128 | }", |
| 129 | "messages": [ |
| 130 | { |
| 131 | "app": "asset", |
| 132 | "if": "{exists(trigger.data["title"])}", |
| 133 | "payload": { |
| 134 | "cap": "{trigger.data["copies"]}", |
| 135 | "is_private": false, |
| 136 | "is_transferrable": true, |
| 137 | "auto_destroy": "{trigger.data["burn"]}", |
| 138 | "fixed_denominations": false, |
| 139 | "issued_by_definer_only": true, |
| 140 | "cosigned_by_definer": false, |
| 141 | "spender_attested": false |
| 142 | } |
| 143 | }, |
| 144 | { |
| 145 | "app": "payment", |
| 146 | "payload": { |
| 147 | "asset": "base", |
| 148 | "outputs": [ |
| 149 | { |
| 150 | "if": "{trigger.address == $BOUNCER}", |
| 151 | "address": "{trigger.initial_address}" |
| 152 | }, |
| 153 | { |
| 154 | "if": "{trigger.address != $BOUNCER}", |
| 155 | "address": "{$BOUNCER}", |
| 156 | "amount": 1000 |
| 157 | } |
| 158 | ] |
| 159 | } |
| 160 | }, |
| 161 | { |
| 162 | "if": "{$sendAsset}", |
| 163 | "app": "payment", |
| 164 | "payload": { |
| 165 | "asset": "{$sendAsset.asset}", |
| 166 | "outputs": [ |
| 167 | { |
| 168 | "address": "{trigger.initial_address}", |
| 169 | "amount": "{$sendAsset.cap}" |
| 170 | } |
| 171 | ] |
| 172 | } |
| 173 | }, |
| 174 | { |
| 175 | "if": "{$sendAsset}", |
| 176 | "app": "data", |
| 177 | "payload": { |
| 178 | "asset": "{$sendAsset.asset}", |
| 179 | "decimals": 0, |
| 180 | "name": "{$sendAsset.title}", |
| 181 | "issuer": "NFT_IPFS_CIDV0", |
| 182 | "ticker": "{$sendAsset.ticker}" |
| 183 | } |
| 184 | }, |
| 185 | { |
| 186 | "app": "state", |
| 187 | "state": "{ |
| 188 | var[trigger.initial_address] = exists(trigger.data["title"]) ? {asset: response_unit, cap: trigger.data["copies"], title: trigger.data["title"], ticker: trigger.data["ticker"]} : false; |
| 189 | }" |
| 190 | } |
| 191 | ] |
| 192 | } |
| 193 | ] |