Skip to content

Commit d5e600f

Browse files
authored
Merge pull request #110 from rmrk-team/feat/collection-count-validation
update count field on collection when nft is minted or burned to vali…
2 parents b577a3b + 2d42eb1 commit d5e600f

21 files changed

+91
-6
lines changed

src/rmrk2.0.0/classes/collection.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export class Collection {
1313
readonly id: string;
1414
readonly metadata: string;
1515
changes: Change[] = [];
16+
count = 0;
1617

1718
constructor(
1819
block: number,

src/rmrk2.0.0/tools/consolidator/adapters/in-memory-adapter.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ export class InMemoryAdapter implements IConsolidatorAdapter {
171171
equipped: "",
172172
forsale: BigInt(nft.forsale) > BigInt(0) ? BigInt(0) : nft.forsale,
173173
};
174+
175+
this.collections[consolidatedNFT.collection].count =
176+
this.collections[consolidatedNFT.collection].count - 1;
174177
}
175178

176179
public async updateNFTMint(nft: NFT) {
@@ -179,6 +182,8 @@ export class InMemoryAdapter implements IConsolidatorAdapter {
179182
symbol: nft.symbol,
180183
id: nft.getId(),
181184
};
185+
this.collections[nft.collection].count =
186+
this.collections[nft.collection].count + 1;
182187
}
183188

184189
public async updateCollectionMint(collection: CollectionConsolidated) {

src/rmrk2.0.0/tools/consolidator/consolidator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export interface CollectionConsolidated {
106106
id: string;
107107
metadata: string;
108108
changes: Change[];
109+
count: number;
109110
}
110111

111112
export interface BaseConsolidated {

src/rmrk2.0.0/tools/consolidator/interactions/burn.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import { Remark } from "../remark";
55
import { Burn } from "../../../classes/burn";
66
import { NFT } from "../../../classes/nft";
77
import { hexToString } from "@polkadot/util";
8-
import { isValidAddressPolkadotAddress } from "../utils";
8+
import {
9+
consolidatedCollectionToInstance,
10+
isValidAddressPolkadotAddress,
11+
} from "../utils";
912
import { IConsolidatorAdapter } from "../adapters/types";
1013
import { NFTConsolidated } from "../consolidator";
1114

src/rmrk2.0.0/tools/consolidator/interactions/mint.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ export const validateMintNFT = async (
2323
`Attempted issue of NFT in non-owned collection. Issuer: ${nftParentCollection.issuer}, caller: ${remark.caller}`
2424
);
2525
}
26-
27-
const nfts = await dbAdapter.getNFTsByCollection(nftParentCollection.id);
28-
const unburnedNfts = nfts ? nfts.filter((nft) => nft.burned === "") : [];
29-
if (nftParentCollection.max <= unburnedNfts.length && nftParentCollection.max !== 0) {
26+
27+
if (
28+
nftParentCollection.count >= nftParentCollection.max &&
29+
nftParentCollection.max !== 0
30+
) {
3031
throw new Error(
3132
`Attempted to mint into maxed out collection ${nftParentCollection.id}`
3233
);

src/rmrk2.0.0/tools/consolidator/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,10 @@ export const consolidatedCollectionToInstance = (
189189
id,
190190
metadata
191191
);
192-
const { changes } = rest;
192+
const { changes, count } = rest;
193193

194194
collectionInstance.changes = changes;
195+
collectionInstance.count = count;
195196
return collectionInstance;
196197
};
197198

test/2.0.0/__snapshots__/consolidator.test.ts.snap

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/2.0.0/classes/__snapshots__/nft-class.test.ts.snap

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/2.0.0/consolidator/__snapshots__/accept.test.ts.snap

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/2.0.0/consolidator/__snapshots__/burn.test.ts.snap

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)