Skip to content

Commit

Permalink
Throw an error if a tokenIndex is passed to mint
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
  • Loading branch information
awrichar committed Jan 25, 2023
1 parent e4dccc4 commit 1f8d471
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 1f8d471

Please sign in to comment.