UNPKG

nft-folder-blockchain-connector-besu

Version:

A NestJS-based blockchain connector that communicates with specific smart contracts from the NFT Folder project.

105 lines 5.38 kB
"use strict"; 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); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TokenReadService = void 0; const common_1 = require("@nestjs/common"); const token_base_services_1 = require("./token-base.services"); const blockchain_service_1 = require("../../shared/blockchain.service"); const configuration_service_1 = require("../../configuration/configuration.service"); const event_service_1 = require("./event.service"); const segment_service_1 = require("../../segment/segment.service"); const token_read_dto_1 = require("../dto/token-read.dto"); const token_asset_dto_1 = require("../dto/token.asset.dto"); const token_metadata_dto_1 = require("../dto/token.metadata.dto"); const token_hierarchy_dto_1 = require("../dto/token.hierarchy.dto"); let TokenReadService = class TokenReadService extends token_base_services_1.TokenBaseService { blockchainService; configurationService; eventInformationService; segmentService; constructor(blockchainService, configurationService, eventInformationService, segmentService) { super(blockchainService, configurationService); this.blockchainService = blockchainService; this.configurationService = configurationService; this.eventInformationService = eventInformationService; this.segmentService = segmentService; } async getTokens(remoteId) { const tokenIds = await this.getTokenIds(remoteId); return await Promise.all(tokenIds.map((tokenId) => this.getToken(Number(tokenId)))); } async getTokenIds(remoteId) { const ownerAddress = this.blockchainService.returnSignerAddress(); try { const tokenIdsForOwner = await this.tokenInstance.getTokenIdsByOwner(ownerAddress); if (!remoteId) { return tokenIdsForOwner; } const tokenIdsForRemoteId = await this.tokenInstance.getTokenIdsByRemoteId(remoteId); return tokenIdsForRemoteId.filter((tokenId) => tokenIdsForOwner.includes(tokenId)); } catch (err) { this.handleError(err); return Promise.reject(err); } } async getToken(tokenId) { try { const token = await this.tokenInstance.getToken(tokenId); const ownerAddress = await this.tokenInstance.ownerOf(tokenId); return new token_read_dto_1.TokenReadDto(token.remoteId, new token_asset_dto_1.TokenAssetDto(token.tokenData.asset.uri, token.tokenData.asset.hash), new token_metadata_dto_1.TokenMetadataDto(token.tokenData.metadata.uri, token.tokenData.metadata.hash), token.tokenData.additionalData, token.node.exists ? new token_hierarchy_dto_1.TokenHierarchyDto(token.node.active, token.node.childIds.map((childId) => Number(childId)), token.node.parentIds.map((parentId) => Number(parentId))) : undefined, ownerAddress, '', '', '', tokenId, this.configurationService.getBlockchainConfiguration().tokenAddress); } catch (err) { this.handleError(err); return Promise.reject(err); } } async getParentIds(tokenId, confirmed) { try { const parentIds = await this.tokenInstance.getParentIds(tokenId, confirmed); return parentIds.map((parentId) => Number(parentId)); } catch (err) { this.handleError(err); return Promise.reject(err); } } async getChildIds(tokenId, confirmed) { try { const childIds = await this.tokenInstance.getChildIds(tokenId, confirmed); return childIds.map((childId) => Number(childId)); } catch (err) { this.handleError(err); return Promise.reject(err); } } getTokenTransferEvents(tokenId) { return this.eventInformationService.fetchTransferEvents(tokenId); } async getSegments(tokenId) { const segments = await this.segmentService.fetchAllSegments(); return segments.filter((segment) => segment.tokenInformation && segment.tokenInformation.length > 0 && segment.tokenInformation.some((token) => token.tokenId === tokenId.toString())); } }; exports.TokenReadService = TokenReadService; exports.TokenReadService = TokenReadService = __decorate([ (0, common_1.Injectable)(), __metadata("design:paramtypes", [blockchain_service_1.BlockchainService, configuration_service_1.ConfigurationService, event_service_1.EventService, segment_service_1.SegmentService]) ], TokenReadService); //# sourceMappingURL=token-read.service.js.map