Skip to content

Commit

Permalink
Merge pull request #113 from kaleido-io/badrequest
Browse files Browse the repository at this point in the history
Throw an error if a tokenIndex is passed to mint
  • Loading branch information
nguyer committed Jan 26, 2023
2 parents e4dccc4 + 1f8d471 commit 206aab4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/tokens/erc1155.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -261,6 +262,7 @@ export const DynamicMethods: Record<TokenOperation, MethodSignature[]> = {
// 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++) {
Expand All @@ -280,6 +282,7 @@ export const DynamicMethods: Record<TokenOperation, MethodSignature[]> = {
// 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++) {
Expand Down Expand Up @@ -315,3 +318,9 @@ export const DynamicMethods: Record<TokenOperation, MethodSignature[]> = {
},
],
};

function verifyNoIndex(dto: TokenMint) {
if (dto.tokenIndex !== undefined) {
throw new BadRequestException('Setting token index is not supported by this contract');
}
}
2 changes: 1 addition & 1 deletion src/tokens/tokens.interfaces.ts
Expand Up @@ -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;
Expand Down

0 comments on commit 206aab4

Please sign in to comment.