From 1f8d471185fb4db761834440f4c1bd948bb20f56 Mon Sep 17 00:00:00 2001 From: Andrew Richardson Date: Wed, 25 Jan 2023 16:45:26 -0500 Subject: [PATCH] Throw an error if a tokenIndex is passed to mint Signed-off-by: Andrew Richardson --- src/tokens/erc1155.ts | 9 +++++++++ src/tokens/tokens.interfaces.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/tokens/erc1155.ts b/src/tokens/erc1155.ts index ae8656a..2cc362e 100644 --- a/src/tokens/erc1155.ts +++ b/src/tokens/erc1155.ts @@ -14,6 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +import { BadRequestException } from '@nestjs/common'; import { MethodSignature, TokenOperation, @@ -261,6 +262,7 @@ export const DynamicMethods: Record = { // In the case of a non-fungible token: // - We parse the value as a whole integer count of NFTs to mint // - We require the number to be small enough to express as a JS number (we're packing into an array) + verifyNoIndex(dto); const to: string[] = []; const amount = parseInt(dto.amount); for (let i = 0; i < amount; i++) { @@ -280,6 +282,7 @@ export const DynamicMethods: Record = { // In the case of a non-fungible token: // - We parse the value as a whole integer count of NFTs to mint // - We require the number to be small enough to express as a JS number (we're packing into an array) + verifyNoIndex(dto); const to: string[] = []; const amount = parseInt(dto.amount); for (let i = 0; i < amount; i++) { @@ -315,3 +318,9 @@ export const DynamicMethods: Record = { }, ], }; + +function verifyNoIndex(dto: TokenMint) { + if (dto.tokenIndex !== undefined) { + throw new BadRequestException('Setting token index is not supported by this contract'); + } +} diff --git a/src/tokens/tokens.interfaces.ts b/src/tokens/tokens.interfaces.ts index 9701e4b..298a6bc 100644 --- a/src/tokens/tokens.interfaces.ts +++ b/src/tokens/tokens.interfaces.ts @@ -293,7 +293,7 @@ export class TokenTransfer { interface?: TokenInterface; } -export class TokenMint extends OmitType(TokenTransfer, ['tokenIndex', 'from']) { +export class TokenMint extends OmitType(TokenTransfer, ['from']) { @ApiProperty() @IsOptional() uri?: string;