Skip to content

Commit

Permalink
fix: getting url from DDO when claiming NFT
Browse files Browse the repository at this point in the history
  • Loading branch information
aaitor committed Sep 22, 2023
1 parent 24c5cbd commit b977291
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions integration/nevermined/Subscriptions.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/keeper/contracts/templates/BaseTemplate.abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export abstract class BaseTemplate<Params, S extends Service>
public abstract description(): string
public abstract conditions(): Condition<any, any>[]

public serviceEndpoint(): ServiceType {
public serviceEndpoint(): ServiceType | string {
return this.service()
}

Expand Down
4 changes: 2 additions & 2 deletions src/keeper/contracts/templates/NFT721SalesTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export class NFT721SalesTemplate extends BaseTemplate<NFT721SalesTemplateParams,
public service(): ServiceType {
return 'nft-sales'
}
public serviceEndpoint(): ServiceType {
return 'nft-sales'
public serviceEndpoint(): ServiceType | string {
return 'nft-transfer'
}

public name(): string {
Expand Down
4 changes: 4 additions & 0 deletions src/keeper/contracts/templates/NFTSalesTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export class NFTSalesTemplate extends BaseTemplate<NFTSalesTemplateParams, Servi
return 'nft-sales'
}

public serviceEndpoint(): ServiceType | string {
return 'nft-transfer'
}

public name(): string {
return 'nft1155SalesAgreement'
}
Expand Down
18 changes: 16 additions & 2 deletions src/services/node/NeverminedNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class NeverminedNode extends Instantiable {
return `${this.url}${apiPath}/access-proof`
}

public getServiceEndpoint(service: ServiceType) {
public getServiceEndpoint(service: ServiceType | string) {
return `${this.url}${apiPath}/${service}`
}

Expand Down Expand Up @@ -380,9 +380,23 @@ export class NeverminedNode extends Instantiable {
ercType: ERCType = 1155,
did?: string,
): Promise<boolean> {
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,
Expand Down

0 comments on commit b977291

Please sign in to comment.