@tatumio/nft-connector
Version:
NFT Connector for Tatum API
223 lines (208 loc) • 9.3 kB
text/typescript
import {BadRequestException, Body, Get, HttpCode, HttpStatus, Param, Post, Put, Query} from '@nestjs/common';
import {NftService} from './NftService';
import {NftError} from './NftError';
import {
TransferErc721 as CoreTransferErc721,
MintErc721 as CoreMintErc721,
BurnErc721 as CoreBurnErc721,
DeployErc721 as CoreDeployErc721,
} from '@tatumio/tatum-core';
import {
AddMinter,
CeloBurnErc721,
CeloDeployErc721,
CeloMintErc721,
CeloMintMultipleErc721,
CeloTransferErc721,
EthBurnErc721,
EthDeployErc721,
EthMintErc721,
EthMintMultipleErc721,
FlowBurnNft,
FlowDeployNft,
FlowMintMultipleNft,
FlowMintNft,
FlowTransferNft,
EthTransferErc721,
UpdateCashbackErc721,
TronUpdateCashbackTrc721,
CeloUpdateCashbackErc721,
TronDeployTrc721,
TronBurnTrc721,
TronMintMultipleTrc721,
TronTransferTrc721,
OneDeploy721, OneBurn721, OneMintMultiple721, OneUpdateCashback721, TronMintTrc721, OneMint721, OneTransfer721,
DeployErc721, BurnErc721, TransferErc721
} from '@tatumio/tatum';
import {PathTokenIdContractAddressChain} from './dto/PathTokenIdContractAddressChain';
import {ChainEgldEsdtTransaction} from './dto/ChainEgldEsdtTransaction'
import {PathChainTxId} from './dto/PathChainTxId';
import {PathAddressContractAddressChain} from "./dto/PathAddressContractAddressChain";
import {SolanaMintNft} from "@tatumio/tatum-solana";
export abstract class NftController {
protected constructor(protected readonly service: NftService) {
}
('/provenance/:chain/:contractAddress/:tokenId')
public async getProvenanceData(() path: any) {
try {
return await this.service.getProvenanceData(path.chain, path.contractAddress, path.tokenId);
} catch (e) {
throw new NftError(`Unexpected error occurred. Reason: ${e.response?.message || e.response?.data || e.message || e}`, 'nft.error');
}
}
('/balance/:chain/:contractAddress/:address')
public async getBalanceErc721(() path: PathAddressContractAddressChain, ('nonce') nonce?: string) {
try {
return await this.service.getTokensOfOwner(path.chain, path.address, path.contractAddress, nonce);
} catch (e) {
throw new NftError(`Unexpected error occurred. Reason: ${e.response?.message || e.response?.data || e.message || e}`, 'nft.error');
}
}
('/transaction/:chain/:txId')
public async getTransaction(() path: PathChainTxId) {
try {
return await this.service.getTransaction(path.chain, path.txId);
} catch (e) {
throw new NftError(`Unexpected error occurred. Reason: ${e.response?.message || e.response?.data || e.message || e}`, 'nft.error');
}
}
('/address/:chain/:txId')
public async getContractAddress(() path: PathChainTxId) {
try {
return await this.service.getContractAddress(path.chain, path.txId);
} catch (e) {
throw new NftError(`Unexpected error occurred. Reason: ${e.response?.message || e.response?.data || e.message || e}`, 'nft.error');
}
}
('/metadata/:chain/:contractAddress/:tokenId?')
public async getMetadataErc721(() path: PathTokenIdContractAddressChain, ('account') account: string, ('nonce') nonce?: string) {
try {
return await this.service.getMetadataErc721(path.chain, path.tokenId, path.contractAddress, account, nonce);
} catch (e) {
throw new NftError(`Unexpected error occurred. Reason: ${e.response?.message || e.response?.data || e.message || e}`, 'nft.error');
}
}
('/royalty/:chain/:contractAddress/:tokenId?')
public async getRoyaltyErc721(() path: PathTokenIdContractAddressChain, ('nonce') nonce?: string) {
try {
return await this.service.getRoyaltyErc721(path.chain, path.tokenId, path.contractAddress, nonce);
} catch (e) {
throw new NftError(`Unexpected error occurred. Reason: ${e.response?.message || e.response?.data || e.message || e}`, 'nft.error');
}
}
('/transaction')
(HttpStatus.OK)
public async transactionErc721(
() body: CeloTransferErc721 | EthTransferErc721 | FlowTransferNft | TronTransferTrc721 | OneTransfer721 | ChainEgldEsdtTransaction | TransferErc721 | CoreTransferErc721
) {
try {
return await this.service.transferErc721(body);
} catch (e) {
if (['Array', 'NftError', 'ValidationError'].includes(e.constructor.name)) {
throw new BadRequestException(e);
}
if (e.constructor.name === 'TatumError') {
throw e;
}
throw new NftError(`Unexpected error occurred. Reason: ${e.response?.message || e.response?.data || e.message || e}`, 'nft.error');
}
}
('/mint')
(HttpStatus.OK)
public async mintErc721(
() body: CeloMintErc721 | EthMintErc721 | FlowMintNft | TronMintTrc721 | OneMint721 | ChainEgldEsdtTransaction | SolanaMintNft | CoreMintErc721
) {
try {
return await this.service.mintErc721(body);
} catch (e) {
if (['Array', 'NftError', 'ValidationError'].includes(e.constructor.name)) {
throw new BadRequestException(e);
}
if (e.constructor.name === 'TatumError') {
throw e;
}
throw new NftError(`Unexpected error occurred. Reason: ${e.response?.message || e.response?.data || e.message || e}`, 'nft.error');
}
}
('/mint/add')
(HttpStatus.OK)
public async addMinter(
() body: AddMinter
) {
try {
return await this.service.addMinter(body);
} catch (e) {
if (['Array', 'NftError', 'ValidationError'].includes(e.constructor.name)) {
throw new BadRequestException(e);
}
if (e.constructor.name === 'TatumError') {
throw e;
}
throw new NftError(`Unexpected error occurred. Reason: ${e.response?.message || e.response?.data || e.message || e}`, 'nft.error');
}
}
('/royalty')
(HttpStatus.OK)
public async updateRoyaltyErc721(() body: CeloUpdateCashbackErc721 | TronUpdateCashbackTrc721 | UpdateCashbackErc721 | OneUpdateCashback721) {
try {
return await this.service.updateCashbackForAuthor(body);
} catch (e) {
if (['Array', 'NftError', 'ValidationError'].includes(e.constructor.name)) {
throw new BadRequestException(e);
}
if (e.constructor.name === 'TatumError') {
throw e;
}
throw new NftError(`Unexpected error occurred. Reason: ${e.response?.message || e.response?.data || e.message || e}`, 'nft.error');
}
}
('/mint/batch')
(HttpStatus.OK)
public async mintMultipleErc721(() body: CeloMintMultipleErc721 | TronMintMultipleTrc721 | EthMintMultipleErc721 | FlowMintMultipleNft | OneMintMultiple721) {
try {
return await this.service.mintMultipleErc721(body);
} catch (e) {
if (['Array', 'NftError', 'ValidationError'].includes(e.constructor.name)) {
throw new BadRequestException(e);
}
if (e.constructor.name === 'TatumError') {
throw e;
}
throw new NftError(`Unexpected error occurred. Reason: ${e.response?.message || e.response?.data || e.message || e}`, 'nft.error');
}
}
('/burn')
(HttpStatus.OK)
public async burnErc721(
() body: CeloBurnErc721 | TronBurnTrc721 | EthBurnErc721 | FlowBurnNft | OneBurn721 | ChainEgldEsdtTransaction | BurnErc721 | CoreBurnErc721
) {
try {
return await this.service.burnErc721(body);
} catch (e) {
if (['Array', 'NftError', 'ValidationError'].includes(e.constructor.name)) {
throw new BadRequestException(e);
}
if (e.constructor.name === 'TatumError') {
throw e;
}
throw new NftError(`Unexpected error occurred. Reason: ${e.response?.message || e.response?.data || e.message || e}`, 'nft.error');
}
}
('/deploy')
(HttpStatus.OK)
public async deployErc721(
() body: CeloDeployErc721 | TronDeployTrc721 | EthDeployErc721 | FlowDeployNft | OneDeploy721 | ChainEgldEsdtTransaction | DeployErc721 | CoreDeployErc721
) {
try {
return await this.service.deployErc721(body);
} catch (e) {
if (['Array', 'NftError', 'ValidationError'].includes(e.constructor.name)) {
throw new BadRequestException(e);
}
if (e.constructor.name === 'TatumError') {
throw e;
}
throw new NftError(`Unexpected error occurred. Reason: ${e.response?.message || e.response?.data || e.message || e}`, 'nft.error');
}
}
}