UNPKG

nft-folder-blockchain-connector-besu

Version:

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

93 lines 4.62 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); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TokenUpdateService = void 0; const common_1 = require("@nestjs/common"); const ethers_1 = require("ethers"); 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 token_read_service_1 = require("./token-read.service"); const event_service_1 = require("./event.service"); let TokenUpdateService = class TokenUpdateService extends token_base_services_1.TokenBaseService { blockchainService; configurationService; eventService; tokenReadService; ethersProvider; constructor(blockchainService, configurationService, eventService, tokenReadService, ethersProvider) { super(blockchainService, configurationService); this.blockchainService = blockchainService; this.configurationService = configurationService; this.eventService = eventService; this.tokenReadService = tokenReadService; this.ethersProvider = ethersProvider; } async transferToken(tokenId, receiverAddress) { const ownAddress = this.blockchainService.returnSignerAddress(); try { await this.tokenInstance.safeTransferFrom(ownAddress, receiverAddress, tokenId); await this.blockchainService.waitForTheNextBlock(); return this.tokenReadService.getToken(tokenId); } catch (err) { this.handleError(err); return Promise.reject(err); } } async updateToken(tokenId, tokenUpdateDto) { try { await this.tokenInstance.updateToken(tokenId, this.getValue(tokenUpdateDto.assetUri), this.getValue(tokenUpdateDto.assetHash), this.getValue(tokenUpdateDto.metadataUri), this.getValue(tokenUpdateDto.metadataHash), this.getValue(tokenUpdateDto.additionalData)); await this.blockchainService.waitForTheNextBlock(); return this.tokenReadService.getToken(tokenId); } catch (err) { this.handleError(err); return Promise.reject(err); } } getValue(field) { return field || ''; } async confirmChild(tokenId, childId) { try { const transactionResponse = await this.tokenInstance.confirmChildOfParent(tokenId, childId); await this.blockchainService.waitForTheNextBlock(); const transactionReceipt = await this.ethersProvider.getTransactionReceipt(transactionResponse.hash); const contractInterface = new ethers_1.Interface(this.tokenInstance.interface.fragments); const decodedLogs = this.eventService.decodeLogs(contractInterface, transactionReceipt, [ 'ChildOfParentConfirmed', ]); this.logger.log(`### Child confirmed ### TxId: ${transactionReceipt.hash} Parent '${tokenId}' confirmed Child '${childId}' ChildOfParentConfirmed: ${decodedLogs?.[0]?.args}`); } catch (err) { this.handleError(err); throw err; } } }; exports.TokenUpdateService = TokenUpdateService; exports.TokenUpdateService = TokenUpdateService = __decorate([ (0, common_1.Injectable)(), __param(4, (0, common_1.Inject)('EthersProvider')), __metadata("design:paramtypes", [blockchain_service_1.BlockchainService, configuration_service_1.ConfigurationService, event_service_1.EventService, token_read_service_1.TokenReadService, ethers_1.JsonRpcProvider]) ], TokenUpdateService); //# sourceMappingURL=token-update.service.js.map