Skip to content

Commit

Permalink
Change burned type back to string. Empty string if not consumed, "tru…
Browse files Browse the repository at this point in the history
…e" if consumed with no reason and otherwise it's a string of reasons separated by triple tilde ~~~
  • Loading branch information
Yuripetusko committed May 22, 2021
1 parent 4dede97 commit f9324e4
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 127 deletions.
4 changes: 2 additions & 2 deletions src/rmrk1.0.0/classes/nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class NFT {
changes: Change[] = [];
owner: string;
loadedMetadata?: NFTMetadata;
burned: string[] | boolean;
burned: string;
constructor(
block: number,
collection: string,
Expand All @@ -42,7 +42,7 @@ export class NFT {
this.owner = "";
this.reactions = {};
this.forsale = BigInt(0);
this.burned = false;
this.burned = "";
this.updatedAtBlock = updatedAtBlock || block;
}

Expand Down
2 changes: 1 addition & 1 deletion src/tools/consolidator/consolidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface NFTConsolidated {
changes: Change[];
owner: string;
loadedMetadata?: NFTMetadata;
burned: string[] | boolean;
burned: string;
updatedAtBlock?: number;
}

Expand Down
3 changes: 1 addition & 2 deletions src/tools/consolidator/interactions/buy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Change } from "../../../rmrk1.0.0/changelog";
import { Remark } from "../remark";
import { NFT as N100 } from "../../..";
import { encodeAddress } from "@polkadot/keyring";
import { isBurnedNFT } from "../../utils";

export const buyInteraction = (
remark: Remark, // Current remark
Expand Down Expand Up @@ -75,7 +74,7 @@ const validate = (
);

switch (true) {
case isBurnedNFT(nft):
case Boolean(nft.burned):
throw new Error(
`[${OP_TYPES.BUY}] Attempting to buy burned NFT ${buyEntity.id}`
);
Expand Down
5 changes: 2 additions & 3 deletions src/tools/consolidator/interactions/consume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Change } from "../../../rmrk1.0.0/changelog";
import { Remark } from "../remark";
import { Consume } from "../../../rmrk1.0.0/classes/consume";
import { NFT } from "../../..";
import { isBurnedNFT } from "../../utils";

export const consumeInteraction = (
remark: Remark,
Expand All @@ -17,7 +16,7 @@ export const consumeInteraction = (
);
}

if (isBurnedNFT(nft)) {
if (Boolean(nft.burned)) {
throw new Error(
`[${OP_TYPES.CONSUME}] Attempting to burn already burned NFT ${consumeEntity.id}`
);
Expand All @@ -42,7 +41,7 @@ export const consumeInteraction = (
}

nft.updatedAtBlock = remark.block;
const burnReason = burnReasons.length < 1 ? true : burnReasons;
const burnReason = burnReasons.length < 1 ? 'true' : burnReasons.join('~~~');
nft.addChange({
field: "burned",
old: "",
Expand Down
3 changes: 1 addition & 2 deletions src/tools/consolidator/interactions/emote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Remark } from "../remark";
import { Emote } from "../../../rmrk1.0.0/classes/emote";
import { NFT } from "../../..";
import { Change } from "../../../rmrk1.0.0/changelog";
import { isBurnedNFT } from "../../utils";

const addEmoteChange = (
remark: Remark,
Expand Down Expand Up @@ -33,7 +32,7 @@ export const emoteInteraction = (
);
}

if (isBurnedNFT(nft)) {
if (Boolean(nft.burned)) {
throw new Error(
`[${OP_TYPES.EMOTE}] Cannot emote to a burned NFT ${emoteEntity.id}`
);
Expand Down
3 changes: 1 addition & 2 deletions src/tools/consolidator/interactions/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { List } from "../../../rmrk1.0.0/classes/list";
import { NFT } from "../../..";
import { OP_TYPES } from "../../constants";
import { Change } from "../../../rmrk1.0.0/changelog";
import { isBurnedNFT } from "../../utils";

export const listForSaleInteraction = (
remark: Remark,
Expand All @@ -16,7 +15,7 @@ export const listForSaleInteraction = (
);
}

if (isBurnedNFT(nft)) {
if (Boolean(nft.burned)) {
throw new Error(
`[${OP_TYPES.LIST}] Attempting to list burned NFT ${listEntity.id}`
);
Expand Down
3 changes: 1 addition & 2 deletions src/tools/consolidator/interactions/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Change } from "../../../rmrk1.0.0/changelog";
import { Remark } from "../remark";
import { Send } from "../../../rmrk1.0.0/classes/send";
import { NFT } from "../../..";
import { isBurnedNFT } from "../../utils";

export const sendInteraction = (
remark: Remark,
Expand All @@ -16,7 +15,7 @@ export const sendInteraction = (
);
}

if (isBurnedNFT(nft)) {
if (Boolean(nft.burned)) {
throw new Error(
`[${OP_TYPES.SEND}] Attempting to send burned NFT ${sendEntity.id}`
);
Expand Down
7 changes: 0 additions & 7 deletions src/tools/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,3 @@ export const filterBlocksByCollection = (
rmrk.remark.includes(collectionFilter)
)
);

/**
* Burned NFT has burned field set as true or has atleast one burned reason string in array
* @param nft
*/
export const isBurnedNFT = (nft: NFT) =>
nft.burned || (Array.isArray(nft.burned) && nft.burned.length > 0);
Loading

0 comments on commit f9324e4

Please sign in to comment.