@tatumio/nft-connector
Version:
NFT Connector for Tatum API
285 lines (284 loc) • 13.4 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NftController = void 0;
const common_1 = require("@nestjs/common");
const NftError_1 = require("./NftError");
const tatum_1 = require("@tatumio/tatum");
const PathTokenIdContractAddressChain_1 = require("./dto/PathTokenIdContractAddressChain");
const PathChainTxId_1 = require("./dto/PathChainTxId");
const PathAddressContractAddressChain_1 = require("./dto/PathAddressContractAddressChain");
class NftController {
constructor(service) {
this.service = service;
}
async getProvenanceData(path) {
var _a, _b;
try {
return await this.service.getProvenanceData(path.chain, path.contractAddress, path.tokenId);
}
catch (e) {
throw new NftError_1.NftError(`Unexpected error occurred. Reason: ${((_a = e.response) === null || _a === void 0 ? void 0 : _a.message) || ((_b = e.response) === null || _b === void 0 ? void 0 : _b.data) || e.message || e}`, 'nft.error');
}
}
async getBalanceErc721(path, nonce) {
var _a, _b;
try {
return await this.service.getTokensOfOwner(path.chain, path.address, path.contractAddress, nonce);
}
catch (e) {
throw new NftError_1.NftError(`Unexpected error occurred. Reason: ${((_a = e.response) === null || _a === void 0 ? void 0 : _a.message) || ((_b = e.response) === null || _b === void 0 ? void 0 : _b.data) || e.message || e}`, 'nft.error');
}
}
async getTransaction(path) {
var _a, _b;
try {
return await this.service.getTransaction(path.chain, path.txId);
}
catch (e) {
throw new NftError_1.NftError(`Unexpected error occurred. Reason: ${((_a = e.response) === null || _a === void 0 ? void 0 : _a.message) || ((_b = e.response) === null || _b === void 0 ? void 0 : _b.data) || e.message || e}`, 'nft.error');
}
}
async getContractAddress(path) {
var _a, _b;
try {
return await this.service.getContractAddress(path.chain, path.txId);
}
catch (e) {
throw new NftError_1.NftError(`Unexpected error occurred. Reason: ${((_a = e.response) === null || _a === void 0 ? void 0 : _a.message) || ((_b = e.response) === null || _b === void 0 ? void 0 : _b.data) || e.message || e}`, 'nft.error');
}
}
async getMetadataErc721(path, account, nonce) {
var _a, _b;
try {
return await this.service.getMetadataErc721(path.chain, path.tokenId, path.contractAddress, account, nonce);
}
catch (e) {
throw new NftError_1.NftError(`Unexpected error occurred. Reason: ${((_a = e.response) === null || _a === void 0 ? void 0 : _a.message) || ((_b = e.response) === null || _b === void 0 ? void 0 : _b.data) || e.message || e}`, 'nft.error');
}
}
async getRoyaltyErc721(path, nonce) {
var _a, _b;
try {
return await this.service.getRoyaltyErc721(path.chain, path.tokenId, path.contractAddress, nonce);
}
catch (e) {
throw new NftError_1.NftError(`Unexpected error occurred. Reason: ${((_a = e.response) === null || _a === void 0 ? void 0 : _a.message) || ((_b = e.response) === null || _b === void 0 ? void 0 : _b.data) || e.message || e}`, 'nft.error');
}
}
async transactionErc721(body) {
var _a, _b;
try {
return await this.service.transferErc721(body);
}
catch (e) {
if (['Array', 'NftError', 'ValidationError'].includes(e.constructor.name)) {
throw new common_1.BadRequestException(e);
}
if (e.constructor.name === 'TatumError') {
throw e;
}
throw new NftError_1.NftError(`Unexpected error occurred. Reason: ${((_a = e.response) === null || _a === void 0 ? void 0 : _a.message) || ((_b = e.response) === null || _b === void 0 ? void 0 : _b.data) || e.message || e}`, 'nft.error');
}
}
async mintErc721(body) {
var _a, _b;
try {
return await this.service.mintErc721(body);
}
catch (e) {
if (['Array', 'NftError', 'ValidationError'].includes(e.constructor.name)) {
throw new common_1.BadRequestException(e);
}
if (e.constructor.name === 'TatumError') {
throw e;
}
throw new NftError_1.NftError(`Unexpected error occurred. Reason: ${((_a = e.response) === null || _a === void 0 ? void 0 : _a.message) || ((_b = e.response) === null || _b === void 0 ? void 0 : _b.data) || e.message || e}`, 'nft.error');
}
}
async addMinter(body) {
var _a, _b;
try {
return await this.service.addMinter(body);
}
catch (e) {
if (['Array', 'NftError', 'ValidationError'].includes(e.constructor.name)) {
throw new common_1.BadRequestException(e);
}
if (e.constructor.name === 'TatumError') {
throw e;
}
throw new NftError_1.NftError(`Unexpected error occurred. Reason: ${((_a = e.response) === null || _a === void 0 ? void 0 : _a.message) || ((_b = e.response) === null || _b === void 0 ? void 0 : _b.data) || e.message || e}`, 'nft.error');
}
}
async updateRoyaltyErc721(body) {
var _a, _b;
try {
return await this.service.updateCashbackForAuthor(body);
}
catch (e) {
if (['Array', 'NftError', 'ValidationError'].includes(e.constructor.name)) {
throw new common_1.BadRequestException(e);
}
if (e.constructor.name === 'TatumError') {
throw e;
}
throw new NftError_1.NftError(`Unexpected error occurred. Reason: ${((_a = e.response) === null || _a === void 0 ? void 0 : _a.message) || ((_b = e.response) === null || _b === void 0 ? void 0 : _b.data) || e.message || e}`, 'nft.error');
}
}
async mintMultipleErc721(body) {
var _a, _b;
try {
return await this.service.mintMultipleErc721(body);
}
catch (e) {
if (['Array', 'NftError', 'ValidationError'].includes(e.constructor.name)) {
throw new common_1.BadRequestException(e);
}
if (e.constructor.name === 'TatumError') {
throw e;
}
throw new NftError_1.NftError(`Unexpected error occurred. Reason: ${((_a = e.response) === null || _a === void 0 ? void 0 : _a.message) || ((_b = e.response) === null || _b === void 0 ? void 0 : _b.data) || e.message || e}`, 'nft.error');
}
}
async burnErc721(body) {
var _a, _b;
try {
return await this.service.burnErc721(body);
}
catch (e) {
if (['Array', 'NftError', 'ValidationError'].includes(e.constructor.name)) {
throw new common_1.BadRequestException(e);
}
if (e.constructor.name === 'TatumError') {
throw e;
}
throw new NftError_1.NftError(`Unexpected error occurred. Reason: ${((_a = e.response) === null || _a === void 0 ? void 0 : _a.message) || ((_b = e.response) === null || _b === void 0 ? void 0 : _b.data) || e.message || e}`, 'nft.error');
}
}
async deployErc721(body) {
var _a, _b;
try {
return await this.service.deployErc721(body);
}
catch (e) {
if (['Array', 'NftError', 'ValidationError'].includes(e.constructor.name)) {
throw new common_1.BadRequestException(e);
}
if (e.constructor.name === 'TatumError') {
throw e;
}
throw new NftError_1.NftError(`Unexpected error occurred. Reason: ${((_a = e.response) === null || _a === void 0 ? void 0 : _a.message) || ((_b = e.response) === null || _b === void 0 ? void 0 : _b.data) || e.message || e}`, 'nft.error');
}
}
}
__decorate([
common_1.Get('/provenance/:chain/:contractAddress/:tokenId'),
__param(0, common_1.Param()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], NftController.prototype, "getProvenanceData", null);
__decorate([
common_1.Get('/balance/:chain/:contractAddress/:address'),
__param(0, common_1.Param()), __param(1, common_1.Query('nonce')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [PathAddressContractAddressChain_1.PathAddressContractAddressChain, String]),
__metadata("design:returntype", Promise)
], NftController.prototype, "getBalanceErc721", null);
__decorate([
common_1.Get('/transaction/:chain/:txId'),
__param(0, common_1.Param()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [PathChainTxId_1.PathChainTxId]),
__metadata("design:returntype", Promise)
], NftController.prototype, "getTransaction", null);
__decorate([
common_1.Get('/address/:chain/:txId'),
__param(0, common_1.Param()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [PathChainTxId_1.PathChainTxId]),
__metadata("design:returntype", Promise)
], NftController.prototype, "getContractAddress", null);
__decorate([
common_1.Get('/metadata/:chain/:contractAddress/:tokenId?'),
__param(0, common_1.Param()), __param(1, common_1.Query('account')), __param(2, common_1.Query('nonce')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [PathTokenIdContractAddressChain_1.PathTokenIdContractAddressChain, String, String]),
__metadata("design:returntype", Promise)
], NftController.prototype, "getMetadataErc721", null);
__decorate([
common_1.Get('/royalty/:chain/:contractAddress/:tokenId?'),
__param(0, common_1.Param()), __param(1, common_1.Query('nonce')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [PathTokenIdContractAddressChain_1.PathTokenIdContractAddressChain, String]),
__metadata("design:returntype", Promise)
], NftController.prototype, "getRoyaltyErc721", null);
__decorate([
common_1.Post('/transaction'),
common_1.HttpCode(common_1.HttpStatus.OK),
__param(0, common_1.Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], NftController.prototype, "transactionErc721", null);
__decorate([
common_1.Post('/mint'),
common_1.HttpCode(common_1.HttpStatus.OK),
__param(0, common_1.Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], NftController.prototype, "mintErc721", null);
__decorate([
common_1.Post('/mint/add'),
common_1.HttpCode(common_1.HttpStatus.OK),
__param(0, common_1.Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [tatum_1.AddMinter]),
__metadata("design:returntype", Promise)
], NftController.prototype, "addMinter", null);
__decorate([
common_1.Put('/royalty'),
common_1.HttpCode(common_1.HttpStatus.OK),
__param(0, common_1.Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], NftController.prototype, "updateRoyaltyErc721", null);
__decorate([
common_1.Post('/mint/batch'),
common_1.HttpCode(common_1.HttpStatus.OK),
__param(0, common_1.Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], NftController.prototype, "mintMultipleErc721", null);
__decorate([
common_1.Post('/burn'),
common_1.HttpCode(common_1.HttpStatus.OK),
__param(0, common_1.Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], NftController.prototype, "burnErc721", null);
__decorate([
common_1.Post('/deploy'),
common_1.HttpCode(common_1.HttpStatus.OK),
__param(0, common_1.Body()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], NftController.prototype, "deployErc721", null);
exports.NftController = NftController;