nft-folder-blockchain-connector-besu
Version:
A NestJS-based blockchain connector that communicates with specific smart contracts from the NFT Folder project.
300 lines • 12.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.TokenController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const token_mint_service_1 = require("../service/token-mint.service");
const token_read_service_1 = require("../service/token-read.service");
const token_update_service_1 = require("../service/token-update.service");
const token_burn_service_1 = require("../service/token-burn.service");
const token_mint_dto_1 = require("../dto/token-mint.dto");
const token_update_dto_1 = require("../dto/token-update.dto");
const token_transfer_dto_1 = require("../dto/token-transfer.dto");
var Status;
(function (Status) {
Status["Confirmed"] = "confirmed";
Status["Unconfirmed"] = "unconfirmed";
})(Status || (Status = {}));
let TokenController = class TokenController {
tokenMintService;
tokenReadService;
tokenUpdateService;
tokenBurnService;
constructor(tokenMintService, tokenReadService, tokenUpdateService, tokenBurnService) {
this.tokenMintService = tokenMintService;
this.tokenReadService = tokenReadService;
this.tokenUpdateService = tokenUpdateService;
this.tokenBurnService = tokenBurnService;
}
async mintToken(dto, appendToHierarchy) {
return this.tokenMintService.mintToken(dto, appendToHierarchy === 'true');
}
async getTokens(remoteId) {
return this.tokenReadService.getTokens(remoteId);
}
async getToken(tokenId) {
const parsedTokenId = this.parseId(tokenId);
return this.tokenReadService.getToken(parsedTokenId);
}
async getTokenTransferEvents(tokenId) {
const parsedTokenId = this.parseId(tokenId);
return this.tokenReadService.getTokenTransferEvents(parsedTokenId);
}
async getParentIds(tokenId, status) {
this.validateStatus(status);
const parsedTokenId = this.parseId(tokenId);
return this.tokenReadService.getParentIds(parsedTokenId, status === Status.Confirmed);
}
async getChildIds(tokenId, status) {
this.validateStatus(status);
const parsedTokenId = this.parseId(tokenId);
return this.tokenReadService.getChildIds(parsedTokenId, status === Status.Confirmed);
}
async getSegments(tokenId) {
const parsedTokenId = this.parseId(tokenId);
return this.tokenReadService.getSegments(parsedTokenId);
}
async transferToken(tokenId, receiverTransferDto) {
const parsedTokenId = this.parseId(tokenId);
return this.tokenUpdateService.transferToken(parsedTokenId, receiverTransferDto.newOwnerAddress);
}
async updateToken(tokenId, dto) {
const parsedTokenId = this.parseId(tokenId);
return this.tokenUpdateService.updateToken(parsedTokenId, dto);
}
async confirmChild(tokenId, childId) {
const parsedTokenId = this.parseId(tokenId);
const parsedChildId = this.parseId(childId);
return this.tokenUpdateService.confirmChild(parsedTokenId, parsedChildId);
}
async burnToken(tokenId) {
const parsedTokenId = this.parseId(tokenId);
return this.tokenBurnService.burnToken(parsedTokenId);
}
parseId(tokenId) {
const parsedId = Number(tokenId);
if (isNaN(parsedId) || parsedId < 0) {
throw new common_1.BadRequestException('Invalid id provided. It must be a positive integer.');
}
return parsedId;
}
validateStatus(status) {
if (!Object.values(Status).includes(status)) {
throw new common_1.BadRequestException(`Status '${status}' is not supported. Use '${Status.Confirmed}' or '${Status.Unconfirmed}'`);
}
}
};
exports.TokenController = TokenController;
__decorate([
(0, common_1.Post)(),
(0, common_1.HttpCode)(common_1.HttpStatus.CREATED),
(0, swagger_1.ApiBody)({
type: token_mint_dto_1.TokenMintDto,
description: 'Contains all relevant information for the creation of a token',
}),
(0, swagger_1.ApiQuery)({
name: 'appendToHierarchy',
type: Boolean,
required: true,
description: 'Whether the token should be appended to a hierarchy or not',
}),
__param(0, (0, common_1.Body)()),
__param(1, (0, common_1.Query)('appendToHierarchy')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [token_mint_dto_1.TokenMintDto, String]),
__metadata("design:returntype", Promise)
], TokenController.prototype, "mintToken", null);
__decorate([
(0, common_1.Get)(),
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
(0, swagger_1.ApiQuery)({
name: 'remoteId',
type: String,
required: false,
description: 'The remoteId of the tokens to be returned',
}),
__param(0, (0, common_1.Query)('remoteId')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], TokenController.prototype, "getTokens", null);
__decorate([
(0, common_1.Get)(':tokenId'),
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
(0, swagger_1.ApiParam)({
name: 'tokenId',
type: Number,
required: true,
description: 'The id of the Token to be returned',
}),
__param(0, (0, common_1.Param)('tokenId')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], TokenController.prototype, "getToken", null);
__decorate([
(0, common_1.Get)(':tokenId/events/transfers'),
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
(0, swagger_1.ApiParam)({
name: 'tokenId',
type: Number,
required: true,
description: 'The id of the token whose transfer events are to be returned.',
}),
__param(0, (0, common_1.Param)('tokenId')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], TokenController.prototype, "getTokenTransferEvents", null);
__decorate([
(0, common_1.Get)(':tokenId/parents'),
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
(0, swagger_1.ApiParam)({
name: 'tokenId',
type: Number,
required: true,
description: 'The id of the token whose parent ids are to be returned',
}),
(0, swagger_1.ApiQuery)({
name: 'status',
type: String,
required: true,
enum: Status,
description: `The status of the parent ids to be returned ('${Status.Confirmed}' or '${Status.Unconfirmed}')`,
}),
__param(0, (0, common_1.Param)('tokenId')),
__param(1, (0, common_1.Query)('status')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, String]),
__metadata("design:returntype", Promise)
], TokenController.prototype, "getParentIds", null);
__decorate([
(0, common_1.Get)(':tokenId/children'),
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
(0, swagger_1.ApiParam)({
name: 'tokenId',
type: Number,
required: true,
description: 'The id of the token whose child ids are to be returned',
}),
(0, swagger_1.ApiQuery)({
name: 'status',
type: String,
required: true,
enum: Status,
description: `The status of the child ids to be returned ('${Status.Confirmed}' or '${Status.Unconfirmed}')`,
}),
__param(0, (0, common_1.Param)('tokenId')),
__param(1, (0, common_1.Query)('status')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, String]),
__metadata("design:returntype", Promise)
], TokenController.prototype, "getChildIds", null);
__decorate([
(0, common_1.Get)(':tokenId/segments'),
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
(0, swagger_1.ApiParam)({
name: 'tokenId',
type: Number,
required: true,
description: 'The id of the token whose segments to be returned',
}),
__param(0, (0, common_1.Param)('tokenId')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], TokenController.prototype, "getSegments", null);
__decorate([
(0, common_1.Patch)(':tokenId/owners'),
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
(0, swagger_1.ApiParam)({
name: 'tokenId',
type: Number,
required: true,
description: 'The id of the token to be transferred',
}),
(0, swagger_1.ApiBody)({
type: token_transfer_dto_1.TokenTransferDto,
description: 'The address of the new owner of the token',
}),
__param(0, (0, common_1.Param)('tokenId')),
__param(1, (0, common_1.Body)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, token_transfer_dto_1.TokenTransferDto]),
__metadata("design:returntype", Promise)
], TokenController.prototype, "transferToken", null);
__decorate([
(0, common_1.Patch)(':tokenId'),
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
(0, swagger_1.ApiParam)({
name: 'tokenId',
type: Number,
required: true,
description: 'The id of the token to be updated',
}),
(0, swagger_1.ApiBody)({
type: token_update_dto_1.TokenUpdateDto,
description: 'Contains the new properties of the Token',
}),
__param(0, (0, common_1.Param)('tokenId')),
__param(1, (0, common_1.Body)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, token_update_dto_1.TokenUpdateDto]),
__metadata("design:returntype", Promise)
], TokenController.prototype, "updateToken", null);
__decorate([
(0, common_1.Patch)(':tokenId/children/:childId/confirm'),
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
(0, swagger_1.ApiParam)({
name: 'tokenId',
type: Number,
required: true,
description: 'The id of the token that is the parent of the child to be confirmed',
}),
(0, swagger_1.ApiParam)({
name: 'childId',
type: Number,
required: true,
description: 'The id of the child to be confirmed',
}),
__param(0, (0, common_1.Param)('tokenId')),
__param(1, (0, common_1.Param)('childId')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, String]),
__metadata("design:returntype", Promise)
], TokenController.prototype, "confirmChild", null);
__decorate([
(0, common_1.Delete)(':tokenId'),
(0, common_1.HttpCode)(common_1.HttpStatus.NO_CONTENT),
(0, swagger_1.ApiParam)({
name: 'tokenId',
type: Number,
required: true,
description: 'The id of the Token to be burned',
}),
__param(0, (0, common_1.Param)('tokenId')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], TokenController.prototype, "burnToken", null);
exports.TokenController = TokenController = __decorate([
(0, common_1.Controller)('tokens'),
(0, swagger_1.ApiTags)('Tokens'),
__metadata("design:paramtypes", [token_mint_service_1.TokenMintService,
token_read_service_1.TokenReadService,
token_update_service_1.TokenUpdateService,
token_burn_service_1.TokenBurnService])
], TokenController);
//# sourceMappingURL=token.controller.js.map