Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | 7x 7x 7x 7x 8043x 99x 2265x 2265x 2265x 2265x 2265x 2265x 2265x 675x 675x 425x 208x 208x 208x 99x 99x 109x 14x 14x 95x 95x 95x 95x 273x 273x 273x 139x 139x 134x 4131x 4131x 4131x 4131x 4131x 4131x 4131x 134x 1x 1x 133x 133x 133x 101x 32x 32x 101x 20x 20x 20x 15x 15x 5x 5x 5x 3x 3x 2x 81x 81x 81x 10x 10x 71x 71x 71x 32x 32x 39x 23x 23x 23x 14x 14x 9x 9x 9x 9x 9x 16x 16x 16x 2x 2x 14x 14x 14x 13x 13x 1x 51x 51x 51x 29x 29x 792x 22x 22x 11x 11x 11x 3x 3x 3x 3x 3x 3x 3x 2x 2x 1x 7x 7x 675x 675x 675x 208x 113x 95x 273x 172x 101x 20x 18x 2x 16x 16x 23x 23x 81x 81x 51x 40x 11x 3x 2x 1x 7x 7x 7x 7x 7x | import JsonAdapter from "./adapters/json";
import { Collection as C100 } from "../../rmrk1.0.0/classes/collection";
import { NFT, NFT as N100 } from "../../rmrk1.0.0/classes/nft";
import { ChangeIssuer } from "../../rmrk1.0.0/classes/changeissuer";
import { Send } from "../../rmrk1.0.0/classes/send";
import { List } from "../../rmrk1.0.0/classes/list";
import { Buy } from "../../rmrk1.0.0/classes/buy";
import { Consume } from "../../rmrk1.0.0/classes/consume";
import { Emote } from "../../rmrk1.0.0/classes/emote";
import { deeplog } from "../utils";
import { Remark } from "./remark";
import { OP_TYPES } from "../constants";
import { Interaction } from "../types";
import { interactionBuy } from "./interactions/buy";
import { getCollectionFromRemark, validateMintIds } from "./interactions/mint";
import {
changeIssuerInteraction,
getChangeIssuerEntity,
} from "./interactions/changeIssuer";
import { validateMintNFT } from "./interactions/mintNFT";
import { listForSaleInteraction } from "./interactions/list";
import { consumeInteraction } from "./interactions/consume";
import { emoteInteraction } from "./interactions/emote";
import { sendInteraction } from "./interactions/send";
export type ConsolidatorReturnType = {
nfts: N100[];
collections: C100[];
invalid: InvalidCall[];
};
export class Consolidator {
private adapter?: JsonAdapter;
private invalidCalls: InvalidCall[];
private collections: C100[];
private nfts: N100[];
constructor(initializedAdapter?: JsonAdapter) {
Iif (initializedAdapter) {
this.adapter = initializedAdapter;
}
this.invalidCalls = [];
this.collections = [];
this.nfts = [];
}
private findExistingCollection(id: string) {
return this.collections.find((el) => el.id === id);
}
private findExistingNFT(interaction: Interaction): N100 | undefined {
return this.nfts.find((el) => {
const idExpand1 = el.getId().split("-");
idExpand1.shift();
const uniquePart1 = idExpand1.join("-");
const idExpand2 = interaction.id.split("-");
idExpand2.shift();
const uniquePart2 = idExpand2.join("-");
return uniquePart1 === uniquePart2;
});
}
private updateInvalidCalls(op_type: OP_TYPES, remark: Remark) {
const invalidCallBase: Partial<InvalidCall> = {
op_type,
block: remark.block,
caller: remark.caller,
};
return function update(
this: Consolidator,
object_id: string,
message: string
) {
this.invalidCalls.push({
...invalidCallBase,
object_id,
message,
} as InvalidCall);
};
}
/**
* The MINT interaction creates an NFT collection.
* https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk1.0.0/interactions/mint.md
*/
private mint(remark: Remark): boolean {
const invalidate = this.updateInvalidCalls(OP_TYPES.MINT, remark).bind(
this
);
let collection;
try {
collection = getCollectionFromRemark(remark);
} catch (e) {
invalidate(remark.remark, e.message);
return true;
}
if (this.findExistingCollection(collection.id)) {
invalidate(
collection.id,
`[${OP_TYPES.MINT}] Attempt to mint already existing collection`
);
return true;
}
try {
validateMintIds(collection, remark);
} catch (e) {
invalidate(collection.id, e.message);
return true;
}
this.collections.push(collection);
return false;
}
/**
* The MINT interaction creates an NFT inside of a Collection.
* https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk1.0.0/interactions/mintnft.md
*/
private mintNFT(remark: Remark): boolean {
const invalidate = this.updateInvalidCalls(OP_TYPES.MINTNFT, remark).bind(
this
);
const nft = NFT.fromRemark(remark.remark, remark.block);
if (typeof nft === "string") {
invalidate(
remark.remark,
`[${OP_TYPES.MINTNFT}] Dead before instantiation: ${nft}`
);
return true;
}
const existsCheck = this.nfts.find((el) => {
const idExpand1 = el.getId().split("-");
idExpand1.shift();
const uniquePart1 = idExpand1.join("-");
const idExpand2 = nft.getId().split("-");
idExpand2.shift();
const uniquePart2 = idExpand2.join("-");
return uniquePart1 === uniquePart2;
});
if (existsCheck) {
invalidate(
nft.getId(),
`[${OP_TYPES.MINTNFT}] Attempt to mint already existing NFT`
);
return true;
}
const nftParentCollection = this.findExistingCollection(nft.collection);
try {
validateMintNFT(remark, nft, nftParentCollection);
this.nfts.push(nft);
} catch (e) {
invalidate(nft.getId(), e.message);
return true;
}
return false;
}
/**
* Send an NFT to an arbitrary recipient.
* You can only SEND an existing NFT (one that has not been CONSUMEd yet).
* https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk1.0.0/interactions/send.md
*/
private send(remark: Remark): boolean {
const invalidate = this.updateInvalidCalls(OP_TYPES.SEND, remark).bind(
this
);
const sendEntity = Send.fromRemark(remark.remark);
if (typeof sendEntity === "string") {
invalidate(
remark.remark,
`[${OP_TYPES.SEND}] Dead before instantiation: ${sendEntity}`
);
return true;
}
const nft = this.findExistingNFT(sendEntity);
try {
sendInteraction(remark, sendEntity, nft);
} catch (e) {
invalidate(sendEntity.id, e.message);
return true;
}
return false;
}
/**
* A LIST interaction lists an NFT as available for sale. The NFT can be instantly purchased.
* A listing can be canceled, and is automatically considered canceled when a BUY is executed on top of a given LIST.
* You can only LIST an existing NFT (one that has not been CONSUMEd yet).
* https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk1.0.0/interactions/list.md
*/
private list(remark: Remark): boolean {
const invalidate = this.updateInvalidCalls(OP_TYPES.LIST, remark).bind(
this
);
const listEntity = List.fromRemark(remark.remark);
if (typeof listEntity === "string") {
invalidate(
remark.remark,
`[${OP_TYPES.LIST}] Dead before instantiation: ${listEntity}`
);
return true;
}
// Find the NFT in state
const nft = this.findExistingNFT(listEntity);
try {
listForSaleInteraction(remark, listEntity, nft);
} catch (e) {
invalidate(listEntity.id, e.message);
return true;
}
return true;
}
/**
* The CONSUME interaction burns an NFT for a specific purpose.
* This is useful when NFTs are spendable like with in-game potions, one-time votes in DAOs, or concert tickets.
* You can only CONSUME an existing NFT (one that has not been CONSUMEd yet).
* https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk1.0.0/interactions/consume.md
*/
private consume(remark: Remark): boolean {
const invalidate = this.updateInvalidCalls(OP_TYPES.CONSUME, remark).bind(
this
);
const consumeEntity = Consume.fromRemark(remark.remark);
// Check if consume is valid
if (typeof consumeEntity === "string") {
invalidate(
remark.remark,
`[${OP_TYPES.CONSUME}] Dead before instantiation: ${consumeEntity}`
);
return true;
}
// Find the NFT in state
const nft = this.findExistingNFT(consumeEntity);
try {
consumeInteraction(remark, consumeEntity, nft);
} catch (e) {
invalidate(consumeEntity.id, e.message);
return true;
}
return true;
}
/**
* The BUY interaction allows a user to immediately purchase an NFT listed for sale using the LIST interaction,
* as long as the listing hasn't been canceled.
* You can only BUY an existing NFT (one that has not been CONSUMEd yet).
* https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk1.0.0/interactions/buy.md
*/
private buy(remark: Remark): boolean {
const invalidate = this.updateInvalidCalls(OP_TYPES.BUY, remark).bind(this);
const buyEntity = Buy.fromRemark(remark.remark);
if (typeof buyEntity === "string") {
invalidate(
remark.remark,
`[${OP_TYPES.BUY}] Dead before instantiation: ${buyEntity}`
);
return true;
}
try {
// Find NFT in current state
const nft = this.findExistingNFT(buyEntity);
interactionBuy(remark, buyEntity, nft);
} catch (e) {
invalidate(buyEntity.id, e.message);
return true;
}
return true;
}
/**
* React to an NFT with an emoticon.
* You can only EMOTE on an existing NFT (one that has not been CONSUMEd yet).
* https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk1.0.0/interactions/emote.md
*/
private emote(remark: Remark): boolean {
const invalidate = this.updateInvalidCalls(OP_TYPES.EMOTE, remark).bind(
this
);
const emoteEntity = Emote.fromRemark(remark.remark);
if (typeof emoteEntity === "string") {
invalidate(
remark.remark,
`[${OP_TYPES.EMOTE}] Dead before instantiation: ${emoteEntity}`
);
return true;
}
const nft = this.nfts.find((el) => el.getId() === emoteEntity.id);
try {
emoteInteraction(remark, emoteEntity, nft);
} catch (e) {
invalidate(emoteEntity.id, e.message);
return true;
}
return false;
}
/**
* The CHANGEISSUER interaction allows a collection issuer to change the issuer field to another address.
* The original issuer immediately loses all rights to mint further NFTs inside that collection.
* This is particularly useful when selling the rights to a collection's operation
* or changing the issuer to a null address to relinquish control over it.
* https://github.com/rmrk-team/rmrk-spec/blob/master/standards/rmrk1.0.0/interactions/changeissuer.md
*/
private changeIssuer(remark: Remark): boolean {
const invalidate = this.updateInvalidCalls(
OP_TYPES.CHANGEISSUER,
remark
).bind(this);
let changeIssuerEntity: ChangeIssuer;
try {
changeIssuerEntity = getChangeIssuerEntity(remark);
} catch (e) {
invalidate(remark.remark, e.message);
return true;
}
const collection = this.collections.find(
(el: C100) => el.id === changeIssuerEntity.id
);
try {
changeIssuerInteraction(remark, changeIssuerEntity, collection);
} catch (e) {
invalidate(changeIssuerEntity.id, e.message);
return true;
}
return false;
}
public consolidate(rmrks?: Remark[]): ConsolidatorReturnType {
const remarks = rmrks || this.adapter?.getRemarks() || [];
//console.log(remarks);
for (const remark of remarks) {
console.log("==============================");
console.log("Remark is: " + remark.remark);
switch (remark.interaction_type) {
case OP_TYPES.MINT:
if (this.mint(remark)) {
continue;
}
break;
case OP_TYPES.MINTNFT:
if (this.mintNFT(remark)) {
continue;
}
break;
case OP_TYPES.SEND:
if (this.send(remark)) {
continue;
}
break;
case OP_TYPES.BUY:
// An NFT was bought after being LISTed
Eif (this.buy(remark)) {
continue;
}
break;
case OP_TYPES.CONSUME:
// An NFT was burned
Eif (this.consume(remark)) {
continue;
}
break;
case OP_TYPES.LIST:
// An NFT was listed for sale
Eif (this.list(remark)) {
continue;
}
break;
case OP_TYPES.EMOTE:
if (this.emote(remark)) {
continue;
}
break;
case OP_TYPES.CHANGEISSUER:
if (this.changeIssuer(remark)) {
continue;
}
break;
default:
console.error(
"Unable to process this remark - wrong type: " +
remark.interaction_type
);
}
}
deeplog(this.nfts);
deeplog(this.collections);
//console.log(this.invalidCalls);
console.log(
`${this.nfts.length} NFTs across ${this.collections.length} collections.`
);
console.log(`${this.invalidCalls.length} invalid calls.`);
return {
nfts: this.nfts,
collections: this.collections,
invalid: this.invalidCalls,
};
}
}
type InvalidCall = {
message: string;
caller: string;
block: number;
object_id: string;
op_type: string;
};
|