From ccf822f85979f70b04d3be30035707cf878a33b3 Mon Sep 17 00:00:00 2001 From: lacoop6tu Date: Mon, 13 Dec 2021 11:31:32 -0500 Subject: [PATCH 01/15] add template index checks on NFTFactory --- src/factories/NFTFactory.ts | 66 +++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/src/factories/NFTFactory.ts b/src/factories/NFTFactory.ts index aa87a7c4..1ca179b1 100644 --- a/src/factories/NFTFactory.ts +++ b/src/factories/NFTFactory.ts @@ -35,6 +35,7 @@ export interface NftCreateData { tokenURI: string } +const addressZERO = '0x0000000000000000000000000000000000000000' /** * Provides an interface for NFT Factory contract */ @@ -83,7 +84,7 @@ export class NftFactory { nftData.name, nftData.symbol, nftData.templateIndex, - '0x0000000000000000000000000000000000000000', + addressZERO, nftData.tokenURI ) .estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas)) @@ -107,7 +108,16 @@ export class NftFactory { nftData.name = name nftData.symbol = symbol } + if ( nftData.templateIndex > await this.getCurrentNFTTemplateCount()) { + throw new Error(`Template index doesnt exist`) + } + if ( nftData.templateIndex === 0) { + throw new Error(`Template index cannot be ZERO`) + } + if((await this.getNFTTemplate(nftData.templateIndex)).isActive === false) { + throw new Error(`Template is not active`) + } const estGas = await this.estGasCreateNFT(address, nftData) // Invoke createToken function of the contract @@ -116,7 +126,7 @@ export class NftFactory { nftData.name, nftData.symbol, nftData.templateIndex, - '0x0000000000000000000000000000000000000000', + addressZERO, nftData.tokenURI ) .send({ @@ -179,6 +189,13 @@ export class NftFactory { * @return {Promise