From b977291276aaafcc9086d7324a30859fb9e15b7d Mon Sep 17 00:00:00 2001 From: Aitor <1726644+aaitor@users.noreply.github.com> Date: Fri, 22 Sep 2023 12:01:48 +0200 Subject: [PATCH] fix: getting url from DDO when claiming NFT --- .../nevermined/Subscriptions.e2e.test.ts | 1 + package.json | 2 +- .../templates/BaseTemplate.abstract.ts | 2 +- .../contracts/templates/NFT721SalesTemplate.ts | 4 ++-- .../contracts/templates/NFTSalesTemplate.ts | 4 ++++ src/services/node/NeverminedNode.ts | 18 ++++++++++++++++-- 6 files changed, 25 insertions(+), 6 deletions(-) diff --git a/integration/nevermined/Subscriptions.e2e.test.ts b/integration/nevermined/Subscriptions.e2e.test.ts index dd77cb1c9..be4971a70 100644 --- a/integration/nevermined/Subscriptions.e2e.test.ts +++ b/integration/nevermined/Subscriptions.e2e.test.ts @@ -27,6 +27,7 @@ describe('Subscriptions using NFT ERC-721 End-to-End', () => { let reseller: Account let nevermined: Nevermined + let token: Token let escrowPaymentCondition: EscrowPaymentCondition let transferNft721Condition: TransferNFT721Condition diff --git a/package.json b/package.json index 25cdba2f6..db4fd8297 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nevermined-io/sdk", - "version": "1.6.2", + "version": "1.6.3", "description": "Javascript SDK for connecting with Nevermined Data Platform ", "main": "./dist/node/sdk.js", "typings": "./dist/node/sdk.d.ts", diff --git a/src/keeper/contracts/templates/BaseTemplate.abstract.ts b/src/keeper/contracts/templates/BaseTemplate.abstract.ts index 889823a7d..c36882470 100644 --- a/src/keeper/contracts/templates/BaseTemplate.abstract.ts +++ b/src/keeper/contracts/templates/BaseTemplate.abstract.ts @@ -27,7 +27,7 @@ export abstract class BaseTemplate public abstract description(): string public abstract conditions(): Condition[] - public serviceEndpoint(): ServiceType { + public serviceEndpoint(): ServiceType | string { return this.service() } diff --git a/src/keeper/contracts/templates/NFT721SalesTemplate.ts b/src/keeper/contracts/templates/NFT721SalesTemplate.ts index 446f23e8d..6926bfa45 100644 --- a/src/keeper/contracts/templates/NFT721SalesTemplate.ts +++ b/src/keeper/contracts/templates/NFT721SalesTemplate.ts @@ -28,8 +28,8 @@ export class NFT721SalesTemplate extends BaseTemplate { + let claimNFTEndpoint = this.getClaimNftEndpoint() try { + if (did) { + // Getting Node endpoint from DDO + const ddo = await this.nevermined.assets.resolve(did) + const salesService = ddo.findServiceByType('nft-sales') + const endpointURL = new URL(salesService.serviceEndpoint) + claimNFTEndpoint = `${endpointURL.protocol}//${endpointURL.host}${apiPath}/nft-transfer` + } + } catch (e) { + this.logger.log(`Unable to get endpoint from DDO: ${did}`) + } + + try { + this.logger.log(`Claiming NFT using endpoint: ${claimNFTEndpoint}`) const response = await this.nevermined.utils.fetch.post( - this.getClaimNftEndpoint(), + claimNFTEndpoint, JSON.stringify({ agreementId, did,