From 55b9eaa7d800946a4489b31c5c555402367eeca0 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Thu, 7 Nov 2024 16:56:56 +0200 Subject: [PATCH 01/20] Use createAsset function from SDK. --- package-lock.json | 15 ++--- package.json | 2 +- src/helpers.ts | 163 ++++------------------------------------------ 3 files changed, 22 insertions(+), 158 deletions(-) diff --git a/package-lock.json b/package-lock.json index 75bcbbd..f778b6a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "Apache-2.0", "dependencies": { "@oceanprotocol/contracts": "^2.0.4", - "@oceanprotocol/lib": "^3.4.1", + "@oceanprotocol/lib": "^3.4.3", "cross-fetch": "^3.1.5", "crypto-js": "^4.1.1", "decimal.js": "^10.4.1", @@ -1147,10 +1147,9 @@ "license": "Apache-2.0" }, "node_modules/@oceanprotocol/lib": { - "version": "3.4.1", - "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.4.1.tgz", - "integrity": "sha512-DhdNI6CF8O7ylTWNqLEdcqP9iWKFo9FDayfJvhNTL4mgWy2N1E3qzFMbsH2NAHN3fo+PbJ2KTfedpFt24r0LhA==", - "license": "Apache-2.0", + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.4.3.tgz", + "integrity": "sha512-S7qvnPORuiyu096AzlkvAH4pMzdTMcz9SMIVlo1UZ0neGV28yJYUjCYxgsTltHjn30Rn6eN5JhAuwPgUehLMIg==", "dependencies": { "@oasisprotocol/sapphire-paratime": "^1.3.2", "@oceanprotocol/contracts": "^2.2.0", @@ -10058,9 +10057,9 @@ "integrity": "sha512-QhewXdtTebycRSZEdkAdvJkSMMnGZyxldlw2eX4VOJto8wymyNdxuhjL/tiaZ5xO7SS5BqURricx9170hfh2kQ==" }, "@oceanprotocol/lib": { - "version": "3.4.1", - "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.4.1.tgz", - "integrity": "sha512-DhdNI6CF8O7ylTWNqLEdcqP9iWKFo9FDayfJvhNTL4mgWy2N1E3qzFMbsH2NAHN3fo+PbJ2KTfedpFt24r0LhA==", + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.4.3.tgz", + "integrity": "sha512-S7qvnPORuiyu096AzlkvAH4pMzdTMcz9SMIVlo1UZ0neGV28yJYUjCYxgsTltHjn30Rn6eN5JhAuwPgUehLMIg==", "requires": { "@oasisprotocol/sapphire-paratime": "^1.3.2", "@oceanprotocol/contracts": "^2.2.0", diff --git a/package.json b/package.json index f2e0354..2fff2be 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ }, "dependencies": { "@oceanprotocol/contracts": "^2.0.4", - "@oceanprotocol/lib": "^3.4.1", + "@oceanprotocol/lib": "^3.4.3", "cross-fetch": "^3.1.5", "crypto-js": "^4.1.1", "decimal.js": "^10.4.1", diff --git a/src/helpers.ts b/src/helpers.ts index 4e38a11..5071904 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -8,10 +8,7 @@ import * as sapphire from '@oasisprotocol/sapphire-paratime'; import { AccesslistFactory, Aquarius, - DatatokenCreateParams, Nft, - NftCreateData, - NftFactory, ProviderInstance, ZERO_ADDRESS, approveWei, @@ -22,14 +19,13 @@ import { DDO, orderAsset, getEventFromTx, - DispenserCreationParams, - FreCreationParams, DownloadResponse, Asset, ProviderFees, ComputeAlgorithm, LoggerInstance, - Datatoken4 + Datatoken4, + createAsset } from "@oceanprotocol/lib"; import { hexlify } from "ethers/lib/utils"; @@ -67,7 +63,7 @@ export async function downloadFile( return { data, filename }; } -export async function createAsset( +export async function createAssetUtil( name: string, symbol: string, owner: Signer, @@ -76,167 +72,36 @@ export async function createAsset( providerUrl: string, config: Config, aquariusInstance: Aquarius, + encryptDDO: boolean = true, templateIndex: number = 1, + providerFeeToken: string = ZERO_ADDRESS, + accessListFactory?: string, + allowAccessList?: string, + denyAccessList?: string, macOsProviderUrl?: string, - encryptDDO: boolean = true, + ) { const { chainId } = await owner.provider.getNetwork(); - const nft = new Nft(owner, chainId); - const nftFactory = new NftFactory(config.nftFactoryAddress, owner); - let wrappedSigner - let allowListAddress if(templateIndex === 4){ // Wrap the signer for Sapphire wrappedSigner = sapphire.wrap(owner); // Create Access List Factory - const accessListFactory = new AccesslistFactory(config.accessListFactory, wrappedSigner, chainId); + const accessListFactoryObj = new AccesslistFactory(config.accessListFactory, wrappedSigner, chainId); // Create Allow List - allowListAddress = await accessListFactory.deployAccessListContract( + await accessListFactoryObj.deployAccessListContract( 'AllowList', 'ALLOW', ['https://oceanprotocol.com/nft/'], false, await owner.getAddress(), [await owner.getAddress(), ZERO_ADDRESS] - ); + ) + return await createAsset(name, symbol, wrappedSigner, assetUrl, templateIndex, ddo, encryptDDO, providerUrl || macOsProviderUrl, providerFeeToken, aquariusInstance, accessListFactory, allowAccessList, denyAccessList); } - - ddo.chainId = parseInt(chainId.toString(10)); - const nftParamsAsset: NftCreateData = { - name, - symbol, - templateIndex, - tokenURI: "aaa", - transferable: true, - owner: await owner.getAddress(), - }; - const datatokenParams: DatatokenCreateParams = { - templateIndex, - cap: "100000", - feeAmount: "0", - paymentCollector: await owner.getAddress(), - feeToken: config.oceanTokenAddress, - minter: await owner.getAddress(), - mpFeeAddress: ZERO_ADDRESS, - }; - - let bundleNFT; - if (!ddo.stats?.price?.value) { - bundleNFT = await nftFactory.createNftWithDatatoken( - nftParamsAsset, - datatokenParams - ); - } else if (ddo?.stats?.price?.value === "0") { - const dispenserParams: DispenserCreationParams = { - dispenserAddress: config.dispenserAddress, - maxTokens: "1", - maxBalance: "100000000", - withMint: true, - allowedSwapper: ZERO_ADDRESS, - }; - - bundleNFT = await nftFactory.createNftWithDatatokenWithDispenser( - nftParamsAsset, - datatokenParams, - dispenserParams - ); - } else { - const fixedPriceParams: FreCreationParams = { - fixedRateAddress: config.fixedRateExchangeAddress, - baseTokenAddress: config.oceanTokenAddress, - owner: await owner.getAddress(), - marketFeeCollector: await owner.getAddress(), - baseTokenDecimals: 18, - datatokenDecimals: 18, - fixedRate: ddo.stats.price.value, - marketFee: "0", - allowedConsumer: await owner.getAddress(), - withMint: true, - }; - - bundleNFT = await nftFactory.createNftWithDatatokenWithFixedRate( - nftParamsAsset, - datatokenParams, - fixedPriceParams - ); - } - - const trxReceipt = await bundleNFT.wait(); - // events have been emitted - const nftCreatedEvent = getEventFromTx(trxReceipt, "NFTCreated"); - const tokenCreatedEvent = getEventFromTx(trxReceipt, "TokenCreated"); - - const nftAddress = nftCreatedEvent.args.newTokenAddress; - const datatokenAddressAsset = tokenCreatedEvent.args.newTokenAddress; - // create the files encrypted string - assetUrl.datatokenAddress = datatokenAddressAsset; - assetUrl.nftAddress = nftAddress; - ddo.services[0].files = templateIndex === 4 ? '' : await ProviderInstance.encrypt( - assetUrl, - chainId, - macOsProviderUrl || providerUrl - ); - ddo.services[0].datatokenAddress = datatokenAddressAsset; - ddo.services[0].serviceEndpoint = providerUrl; - - ddo.nftAddress = nftAddress; - ddo.id = - "did:op:" + - SHA256(ethers.utils.getAddress(nftAddress) + chainId.toString(10)); - - let metadata; - let metadataHash; - let flags; - if (encryptDDO) { - metadata = await ProviderInstance.encrypt( - ddo, - chainId, - macOsProviderUrl || providerUrl - ); - const validateResult = await aquariusInstance.validate(ddo); - metadataHash = validateResult.hash; - flags = 2 - } else { - const stringDDO = JSON.stringify(ddo); - const bytes = Buffer.from(stringDDO); - metadata = hexlify(bytes); - metadataHash = "0x" + createHash("sha256").update(metadata).digest("hex"); - flags = 0 - } - - await nft.setMetadata( - nftAddress, - await owner.getAddress(), - 0, - providerUrl, - "", - ethers.utils.hexlify(flags), - metadata, - metadataHash - ); - - if(templateIndex === 4){ // Use Datatoken4 for file object - const datatoken = new Datatoken4( - wrappedSigner, - ethers.utils.toUtf8Bytes(JSON.stringify(assetUrl.files)), - chainId, - config - ); - - // Set file object - await datatoken.setFileObject(datatokenAddressAsset, await wrappedSigner.getAddress()); - - // Set allow list for the datatoken - await datatoken.setAllowListContract( - datatokenAddressAsset, - allowListAddress, - await wrappedSigner.getAddress() - );} - - return ddo.id; + return await createAsset(name, symbol, owner, assetUrl, templateIndex, ddo, encryptDDO, providerUrl || macOsProviderUrl, providerFeeToken, aquariusInstance); } From 9eb253e6d78ae6201d92f0070c919514e722e22a Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Thu, 7 Nov 2024 17:18:44 +0200 Subject: [PATCH 02/20] Fix lint. --- src/helpers.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index 5071904..bdeba7a 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -1,8 +1,6 @@ -import { SHA256 } from "crypto-js"; import { ethers, Signer } from "ethers"; import fetch from "cross-fetch"; import { promises as fs } from "fs"; -import { createHash } from "crypto"; import * as path from "path"; import * as sapphire from '@oasisprotocol/sapphire-paratime'; import { @@ -24,7 +22,6 @@ import { ProviderFees, ComputeAlgorithm, LoggerInstance, - Datatoken4, createAsset } from "@oceanprotocol/lib"; import { hexlify } from "ethers/lib/utils"; From db0078266a98bcce678f57cbd74f26cddeafbc6e Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Thu, 7 Nov 2024 17:31:22 +0200 Subject: [PATCH 03/20] Fix exported function. --- src/commands.ts | 14 +++++--------- src/publishAsset.ts | 7 +++---- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index d2c50c0..c25e1f1 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -2,7 +2,7 @@ import fs from "fs"; import os from "os"; import util from "util"; import { - createAsset, + createAssetUtil, handleComputeOrder, updateAssetMetadata, downloadFile, @@ -92,17 +92,15 @@ export class Commands { const encryptDDO = args[2] === "false" ? false : true; try { // add some more checks - const urlAssetId = await createAsset( + const urlAssetId = await createAssetUtil( asset.nft.name, asset.nft.symbol, this.signer, asset.services[0].files, asset, - this.providerUrl, + this.providerUrl || this.macOsProviderUrl, this.config, this.aquarius, - 1, - this.macOsProviderUrl, encryptDDO ); console.log("Asset published. ID: " + urlAssetId); @@ -124,17 +122,15 @@ export class Commands { } const encryptDDO = args[2] === "false" ? false : true; // add some more checks - const algoDid = await createAsset( + const algoDid = await createAssetUtil( algoAsset.nft.name, algoAsset.nft.symbol, this.signer, algoAsset.services[0].files, algoAsset, - this.providerUrl, + this.providerUrl || this.macOsProviderUrl, this.config, this.aquarius, - 1, - this.macOsProviderUrl, encryptDDO ); // add some more checks diff --git a/src/publishAsset.ts b/src/publishAsset.ts index 57a08ce..d158802 100644 --- a/src/publishAsset.ts +++ b/src/publishAsset.ts @@ -5,7 +5,7 @@ import { Aquarius, DDO } from '@oceanprotocol/lib'; -import { createAsset, updateAssetMetadata } from './helpers'; +import { createAssetUtil, updateAssetMetadata } from './helpers'; export interface PublishAssetParams { title: string; @@ -81,7 +81,7 @@ export async function publishAsset(params: PublishAssetParams, signer: Signer, c }; // Other networks - const did = await createAsset( + const did = await createAssetUtil( params.title, 'OCEAN-NFT', signer, @@ -89,8 +89,7 @@ export async function publishAsset(params: PublishAssetParams, signer: Signer, c metadata, params.providerUrl, config, - aquarius, - params.template || 1 + aquarius ); From 5e2aac692bef29d53d3b03bd792c3ac83e38325b Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Mon, 18 Nov 2024 14:32:41 +0200 Subject: [PATCH 04/20] Fix indent. --- src/publishAsset.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/publishAsset.ts b/src/publishAsset.ts index d158802..34cb422 100644 --- a/src/publishAsset.ts +++ b/src/publishAsset.ts @@ -80,17 +80,17 @@ export async function publishAsset(params: PublishAssetParams, signer: Signer, c files: [{ type: params.storageType, url: params.assetLocation, method: 'GET' }], }; - // Other networks - const did = await createAssetUtil( - params.title, - 'OCEAN-NFT', - signer, - assetUrl, - metadata, - params.providerUrl, - config, - aquarius - ); + // Other networks + const did = await createAssetUtil( + params.title, + 'OCEAN-NFT', + signer, + assetUrl, + metadata, + params.providerUrl, + config, + aquarius + ); console.log(`Asset successfully published with DID: ${did}`); From 7fee679f63c72eb4431cda39059285de912836c2 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Mon, 18 Nov 2024 15:03:57 +0200 Subject: [PATCH 05/20] Remove reinforce type for DDO. --- src/publishAsset.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/publishAsset.ts b/src/publishAsset.ts index 34cb422..c5b4609 100644 --- a/src/publishAsset.ts +++ b/src/publishAsset.ts @@ -2,8 +2,7 @@ import { Signer } from 'ethers'; import { Config, - Aquarius, - DDO + Aquarius } from '@oceanprotocol/lib'; import { createAssetUtil, updateAssetMetadata } from './helpers'; @@ -28,7 +27,7 @@ export async function publishAsset(params: PublishAssetParams, signer: Signer, c const aquarius = new Aquarius(config.metadataCacheUri); // Prepare initial metadata for the asset - const metadata: DDO = { + const metadata: any = { '@context': ['https://w3id.org/did/v1'], id: '', // Will be updated after creating asset version: '4.1.0', From eabaa24c0f694c98c00876d7c49cb249661e5107 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Mon, 18 Nov 2024 15:21:27 +0200 Subject: [PATCH 06/20] Increase timeout. --- test/consumeFlow.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/consumeFlow.test.ts b/test/consumeFlow.test.ts index bf0c8c8..4bc27b1 100644 --- a/test/consumeFlow.test.ts +++ b/test/consumeFlow.test.ts @@ -6,7 +6,7 @@ import crypto from "crypto"; import https from "https"; describe("Ocean CLI Publishing", function() { - this.timeout(180000); // Set a longer timeout to allow the command to execute + this.timeout(240000); // Set a longer timeout to allow the command to execute let downloadDatasetDid: string; let computeDatasetDid: string; From d1efb18cdd127b99a86584f8c4e701630ab30afa Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Mon, 18 Nov 2024 15:30:54 +0200 Subject: [PATCH 07/20] debug and reinforce ddo type. --- src/publishAsset.ts | 39 +++++++++++++++++++++------------------ test/consumeFlow.test.ts | 3 ++- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/publishAsset.ts b/src/publishAsset.ts index c5b4609..6a0aff3 100644 --- a/src/publishAsset.ts +++ b/src/publishAsset.ts @@ -2,7 +2,8 @@ import { Signer } from 'ethers'; import { Config, - Aquarius + Aquarius, + DDO } from '@oceanprotocol/lib'; import { createAssetUtil, updateAssetMetadata } from './helpers'; @@ -27,7 +28,7 @@ export async function publishAsset(params: PublishAssetParams, signer: Signer, c const aquarius = new Aquarius(config.metadataCacheUri); // Prepare initial metadata for the asset - const metadata: any = { + const metadata: DDO = { '@context': ['https://w3id.org/did/v1'], id: '', // Will be updated after creating asset version: '4.1.0', @@ -43,13 +44,7 @@ export async function publishAsset(params: PublishAssetParams, signer: Signer, c license: 'MIT', tags: params.tags }, - stats: { - allocated: 0, - orders: 0, - price: { - value: params.isCharged ? params.price : "0" - } - }, + services: [ { id: 'access', @@ -61,17 +56,25 @@ export async function publishAsset(params: PublishAssetParams, signer: Signer, c timeout: Number(params.timeout), }, ], - nft: { - address: "", - name: "Ocean Data NFT", - symbol: "OCEAN-NFT", - state: 5, - tokenURI: "", - owner: "", - created: "" - } }; + // stats: { + // allocated: 0, + // orders: 0, + // price: { + // value: params.isCharged ? params.price : "0" + // } + // }, + // nft: { + // address: "", + // name: "Ocean Data NFT", + // symbol: "OCEAN-NFT", + // state: 5, + // tokenURI: "", + // owner: "", + // created: "" + // } + // Asset URL setup based on storage type const assetUrl = { nftAddress: '0x0', // Will be updated after creating asset diff --git a/test/consumeFlow.test.ts b/test/consumeFlow.test.ts index 4bc27b1..51ea09e 100644 --- a/test/consumeFlow.test.ts +++ b/test/consumeFlow.test.ts @@ -6,7 +6,7 @@ import crypto from "crypto"; import https from "https"; describe("Ocean CLI Publishing", function() { - this.timeout(240000); // Set a longer timeout to allow the command to execute + this.timeout(180000); // Set a longer timeout to allow the command to execute let downloadDatasetDid: string; let computeDatasetDid: string; @@ -59,6 +59,7 @@ describe("Ocean CLI Publishing", function() { const match = stdout.match(/did:op:[a-f0-9]{64}/); if (match) { downloadDatasetDid = match[0]; + console.log('match: ', match[0]) } expect(stdout).to.contain("Asset published. ID:"); done() From 478df75c3b71eacd0a143f9c82bdafe2ddbba954 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Mon, 18 Nov 2024 15:39:24 +0200 Subject: [PATCH 08/20] Print did. --- src/helpers.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index bdeba7a..863f925 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -79,10 +79,9 @@ export async function createAssetUtil( ) { const { chainId } = await owner.provider.getNetwork(); - let wrappedSigner if(templateIndex === 4){ // Wrap the signer for Sapphire - wrappedSigner = sapphire.wrap(owner); + const wrappedSigner = sapphire.wrap(owner); // Create Access List Factory const accessListFactoryObj = new AccesslistFactory(config.accessListFactory, wrappedSigner, chainId); @@ -98,7 +97,9 @@ export async function createAssetUtil( ) return await createAsset(name, symbol, wrappedSigner, assetUrl, templateIndex, ddo, encryptDDO, providerUrl || macOsProviderUrl, providerFeeToken, aquariusInstance, accessListFactory, allowAccessList, denyAccessList); } - return await createAsset(name, symbol, owner, assetUrl, templateIndex, ddo, encryptDDO, providerUrl || macOsProviderUrl, providerFeeToken, aquariusInstance); + const did = await createAsset(name, symbol, owner, assetUrl, templateIndex, ddo, encryptDDO, providerUrl || macOsProviderUrl, providerFeeToken, aquariusInstance); + console.log('did: ', did) + return did } From 7681750cbf946503e16990c74082fe4e0d7b0feb Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Tue, 19 Nov 2024 16:13:35 +0200 Subject: [PATCH 09/20] Add more logs into the tests. --- src/publishAsset.ts | 17 ----------------- test/consumeFlow.test.ts | 10 +++++++--- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/publishAsset.ts b/src/publishAsset.ts index 6a0aff3..400cc9d 100644 --- a/src/publishAsset.ts +++ b/src/publishAsset.ts @@ -58,23 +58,6 @@ export async function publishAsset(params: PublishAssetParams, signer: Signer, c ], }; - // stats: { - // allocated: 0, - // orders: 0, - // price: { - // value: params.isCharged ? params.price : "0" - // } - // }, - // nft: { - // address: "", - // name: "Ocean Data NFT", - // symbol: "OCEAN-NFT", - // state: 5, - // tokenURI: "", - // owner: "", - // created: "" - // } - // Asset URL setup based on storage type const assetUrl = { nftAddress: '0x0', // Will be updated after creating asset diff --git a/test/consumeFlow.test.ts b/test/consumeFlow.test.ts index 51ea09e..c7a5f43 100644 --- a/test/consumeFlow.test.ts +++ b/test/consumeFlow.test.ts @@ -41,6 +41,7 @@ describe("Ocean CLI Publishing", function() { it("should publish a dataset using 'npm run cli publish'", function(done) { const metadataFile = path.resolve(projectRoot, "metadata/simpleDownloadDataset.json"); + console.log('metadataFile 1 ', metadataFile); // Ensure the metadata file exists if (!fs.existsSync(metadataFile)) { @@ -53,13 +54,16 @@ describe("Ocean CLI Publishing", function() { process.env.AQUARIUS_URL = "http://127.0.0.1:8001"; process.env.PROVIDER_URL = "http://127.0.0.1:8001"; process.env.ADDRESS_FILE = path.join(process.env.HOME || "", ".ocean/ocean-contracts/artifacts/address.json"); - + console.log('RPC', process.env.RPC); + console.log('AQUARIUS_URL', process.env.AQUARIUS_URL); + console.log('PROVIDER_URL', process.env.PROVIDER_URL); + console.log('ADDRESS_FILE', process.env.ADDRESS_FILE); exec(`npm run cli publish ${metadataFile}`, { cwd: projectRoot }, (error, stdout) => { try { const match = stdout.match(/did:op:[a-f0-9]{64}/); if (match) { downloadDatasetDid = match[0]; - console.log('match: ', match[0]) + console.log('match 1: ', match[0]) } expect(stdout).to.contain("Asset published. ID:"); done() @@ -72,7 +76,7 @@ describe("Ocean CLI Publishing", function() { it("should publish a compute dataset using 'npm run cli publish'", function(done) { const metadataFile = path.resolve(projectRoot, "metadata/simpleComputeDataset.json"); - + console.log('metadataFile', metadataFile); // Ensure the metadata file exists if (!fs.existsSync(metadataFile)) { done(new Error("Metadata file not found: " + metadataFile)); From bca4cb1bed6485969a14e833bc0dc601a294689a Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Wed, 20 Nov 2024 15:16:16 +0200 Subject: [PATCH 10/20] Updated chain id from samples. --- metadata/simpleDownloadDataset.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata/simpleDownloadDataset.json b/metadata/simpleDownloadDataset.json index 21f78fd..39969eb 100644 --- a/metadata/simpleDownloadDataset.json +++ b/metadata/simpleDownloadDataset.json @@ -5,7 +5,7 @@ "id": "", "nftAddress": "", "version": "4.1.0", - "chainId": 80001, + "chainId": 8996, "metadata": { "created": "2021-12-20T14:35:20Z", "updated": "2021-12-20T14:35:20Z", From cb94b1d3e8a0c5998533eb5b9774dede6b51a216 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Wed, 20 Nov 2024 15:32:44 +0200 Subject: [PATCH 11/20] Adding try/catch at the algo side. --- src/commands.ts | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index c25e1f1..9babb5b 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -122,19 +122,26 @@ export class Commands { } const encryptDDO = args[2] === "false" ? false : true; // add some more checks - const algoDid = await createAssetUtil( - algoAsset.nft.name, - algoAsset.nft.symbol, - this.signer, - algoAsset.services[0].files, - algoAsset, - this.providerUrl || this.macOsProviderUrl, - this.config, - this.aquarius, - encryptDDO - ); - // add some more checks + try{ + const algoDid = await createAssetUtil( + algoAsset.nft.name, + algoAsset.nft.symbol, + this.signer, + algoAsset.services[0].files, + algoAsset, + this.providerUrl || this.macOsProviderUrl, + this.config, + this.aquarius, + encryptDDO + ); + // add some more checks console.log("Algorithm published. DID: " + algoDid); + } catch (e) { + console.error("Error when publishing dataset from file: " + args[1]); + console.error(e); + return; + } + } public async editAsset(args: string[]) { From 5a9de65efd5a546fb4f332fe8bbc3fba1db3b847 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Wed, 20 Nov 2024 15:35:33 +0200 Subject: [PATCH 12/20] Updated chain id. --- metadata/jsAlgo.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata/jsAlgo.json b/metadata/jsAlgo.json index 599c698..1bc3c66 100644 --- a/metadata/jsAlgo.json +++ b/metadata/jsAlgo.json @@ -5,7 +5,7 @@ "id": "", "nftAddress": "", "version": "4.1.0", - "chainId": 137, + "chainId": 8996, "metadata": { "created": "2023-08-01T17:09:39Z", "updated": "2023-08-01T17:09:39Z", From 022e47e4eb7febb31a1fbc9837b8328b849226b8 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Wed, 20 Nov 2024 15:49:16 +0200 Subject: [PATCH 13/20] cleanup console.logs. --- src/helpers.ts | 4 +--- test/consumeFlow.test.ts | 9 +-------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index 863f925..5efed08 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -97,9 +97,7 @@ export async function createAssetUtil( ) return await createAsset(name, symbol, wrappedSigner, assetUrl, templateIndex, ddo, encryptDDO, providerUrl || macOsProviderUrl, providerFeeToken, aquariusInstance, accessListFactory, allowAccessList, denyAccessList); } - const did = await createAsset(name, symbol, owner, assetUrl, templateIndex, ddo, encryptDDO, providerUrl || macOsProviderUrl, providerFeeToken, aquariusInstance); - console.log('did: ', did) - return did + return await createAsset(name, symbol, owner, assetUrl, templateIndex, ddo, encryptDDO, providerUrl || macOsProviderUrl, providerFeeToken, aquariusInstance); } diff --git a/test/consumeFlow.test.ts b/test/consumeFlow.test.ts index c7a5f43..c7bf0f7 100644 --- a/test/consumeFlow.test.ts +++ b/test/consumeFlow.test.ts @@ -41,7 +41,6 @@ describe("Ocean CLI Publishing", function() { it("should publish a dataset using 'npm run cli publish'", function(done) { const metadataFile = path.resolve(projectRoot, "metadata/simpleDownloadDataset.json"); - console.log('metadataFile 1 ', metadataFile); // Ensure the metadata file exists if (!fs.existsSync(metadataFile)) { @@ -54,21 +53,16 @@ describe("Ocean CLI Publishing", function() { process.env.AQUARIUS_URL = "http://127.0.0.1:8001"; process.env.PROVIDER_URL = "http://127.0.0.1:8001"; process.env.ADDRESS_FILE = path.join(process.env.HOME || "", ".ocean/ocean-contracts/artifacts/address.json"); - console.log('RPC', process.env.RPC); - console.log('AQUARIUS_URL', process.env.AQUARIUS_URL); - console.log('PROVIDER_URL', process.env.PROVIDER_URL); - console.log('ADDRESS_FILE', process.env.ADDRESS_FILE); + exec(`npm run cli publish ${metadataFile}`, { cwd: projectRoot }, (error, stdout) => { try { const match = stdout.match(/did:op:[a-f0-9]{64}/); if (match) { downloadDatasetDid = match[0]; - console.log('match 1: ', match[0]) } expect(stdout).to.contain("Asset published. ID:"); done() } catch (assertionError) { - console.log('assertionError', assertionError); done(assertionError); } }); @@ -76,7 +70,6 @@ describe("Ocean CLI Publishing", function() { it("should publish a compute dataset using 'npm run cli publish'", function(done) { const metadataFile = path.resolve(projectRoot, "metadata/simpleComputeDataset.json"); - console.log('metadataFile', metadataFile); // Ensure the metadata file exists if (!fs.existsSync(metadataFile)) { done(new Error("Metadata file not found: " + metadataFile)); From a3813287d6139e1128ebeaa8923f151ea5d1bbff Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Wed, 20 Nov 2024 15:56:02 +0200 Subject: [PATCH 14/20] Delete chain id from all samples. --- metadata/jsAlgo.json | 1 - metadata/jsIPFSAlgo.json | 1 - metadata/pythonAlgo.json | 1 - metadata/simpleComputeDataset.json | 1 - metadata/simpleDownloadDataset.json | 1 - metadata/simpleIPFSComputeDataset.json | 1 - 6 files changed, 6 deletions(-) diff --git a/metadata/jsAlgo.json b/metadata/jsAlgo.json index 1bc3c66..d8b91ca 100644 --- a/metadata/jsAlgo.json +++ b/metadata/jsAlgo.json @@ -5,7 +5,6 @@ "id": "", "nftAddress": "", "version": "4.1.0", - "chainId": 8996, "metadata": { "created": "2023-08-01T17:09:39Z", "updated": "2023-08-01T17:09:39Z", diff --git a/metadata/jsIPFSAlgo.json b/metadata/jsIPFSAlgo.json index 5dc46b3..dac810c 100644 --- a/metadata/jsIPFSAlgo.json +++ b/metadata/jsIPFSAlgo.json @@ -5,7 +5,6 @@ "id": "", "nftAddress": "", "version": "4.1.0", - "chainId": 8996, "metadata": { "created": "2023-08-01T17:09:39Z", "updated": "2023-08-01T17:09:39Z", diff --git a/metadata/pythonAlgo.json b/metadata/pythonAlgo.json index b9b7ff3..201a9bb 100644 --- a/metadata/pythonAlgo.json +++ b/metadata/pythonAlgo.json @@ -5,7 +5,6 @@ "id": "", "nftAddress": "", "version": "4.1.0", - "chainId": 8996, "metadata": { "created": "2023-08-01T17:09:39Z", "updated": "2023-08-01T17:09:39Z", diff --git a/metadata/simpleComputeDataset.json b/metadata/simpleComputeDataset.json index 3aa0a71..b5d4b99 100644 --- a/metadata/simpleComputeDataset.json +++ b/metadata/simpleComputeDataset.json @@ -5,7 +5,6 @@ "id": "", "nftAddress": "", "version": "4.1.0", - "chainId": 8996, "metadata": { "created": "2021-12-20T14:35:20Z", "updated": "2021-12-20T14:35:20Z", diff --git a/metadata/simpleDownloadDataset.json b/metadata/simpleDownloadDataset.json index 39969eb..dbffb7c 100644 --- a/metadata/simpleDownloadDataset.json +++ b/metadata/simpleDownloadDataset.json @@ -5,7 +5,6 @@ "id": "", "nftAddress": "", "version": "4.1.0", - "chainId": 8996, "metadata": { "created": "2021-12-20T14:35:20Z", "updated": "2021-12-20T14:35:20Z", diff --git a/metadata/simpleIPFSComputeDataset.json b/metadata/simpleIPFSComputeDataset.json index 3808a9d..0f47213 100644 --- a/metadata/simpleIPFSComputeDataset.json +++ b/metadata/simpleIPFSComputeDataset.json @@ -5,7 +5,6 @@ "id": "", "nftAddress": "", "version": "4.1.0", - "chainId": 8996, "metadata": { "created": "2021-12-20T14:35:20Z", "updated": "2021-12-20T14:35:20Z", From a792f83229c274b6077e62992a8440d1ca1e8cc4 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Wed, 20 Nov 2024 15:57:08 +0200 Subject: [PATCH 15/20] Use latest version of ocean-lib. --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index f778b6a..5c37d67 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "Apache-2.0", "dependencies": { "@oceanprotocol/contracts": "^2.0.4", - "@oceanprotocol/lib": "^3.4.3", + "@oceanprotocol/lib": "^3.4.4", "cross-fetch": "^3.1.5", "crypto-js": "^4.1.1", "decimal.js": "^10.4.1", @@ -1147,9 +1147,9 @@ "license": "Apache-2.0" }, "node_modules/@oceanprotocol/lib": { - "version": "3.4.3", - "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.4.3.tgz", - "integrity": "sha512-S7qvnPORuiyu096AzlkvAH4pMzdTMcz9SMIVlo1UZ0neGV28yJYUjCYxgsTltHjn30Rn6eN5JhAuwPgUehLMIg==", + "version": "3.4.4", + "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.4.4.tgz", + "integrity": "sha512-TRdW7lfBgDmqgG50S6YDiF3fe6cy0lDTtIazsTvvUs5sWAk1+a1TGQU1qfIYSpfNJM+Yg1KMUSJAPVOTZ65ehQ==", "dependencies": { "@oasisprotocol/sapphire-paratime": "^1.3.2", "@oceanprotocol/contracts": "^2.2.0", @@ -10057,9 +10057,9 @@ "integrity": "sha512-QhewXdtTebycRSZEdkAdvJkSMMnGZyxldlw2eX4VOJto8wymyNdxuhjL/tiaZ5xO7SS5BqURricx9170hfh2kQ==" }, "@oceanprotocol/lib": { - "version": "3.4.3", - "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.4.3.tgz", - "integrity": "sha512-S7qvnPORuiyu096AzlkvAH4pMzdTMcz9SMIVlo1UZ0neGV28yJYUjCYxgsTltHjn30Rn6eN5JhAuwPgUehLMIg==", + "version": "3.4.4", + "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.4.4.tgz", + "integrity": "sha512-TRdW7lfBgDmqgG50S6YDiF3fe6cy0lDTtIazsTvvUs5sWAk1+a1TGQU1qfIYSpfNJM+Yg1KMUSJAPVOTZ65ehQ==", "requires": { "@oasisprotocol/sapphire-paratime": "^1.3.2", "@oceanprotocol/contracts": "^2.2.0", diff --git a/package.json b/package.json index 2fff2be..9dd1243 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ }, "dependencies": { "@oceanprotocol/contracts": "^2.0.4", - "@oceanprotocol/lib": "^3.4.3", + "@oceanprotocol/lib": "^3.4.4", "cross-fetch": "^3.1.5", "crypto-js": "^4.1.1", "decimal.js": "^10.4.1", From 3182f0dadfc363cf31fb9f9d0379f78a564e61df Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Wed, 20 Nov 2024 16:05:46 +0200 Subject: [PATCH 16/20] Add chain id key with empty string. --- metadata/jsAlgo.json | 1 + metadata/jsIPFSAlgo.json | 1 + metadata/pythonAlgo.json | 1 + metadata/simpleComputeDataset.json | 1 + metadata/simpleDownloadDataset.json | 1 + metadata/simpleIPFSComputeDataset.json | 1 + 6 files changed, 6 insertions(+) diff --git a/metadata/jsAlgo.json b/metadata/jsAlgo.json index d8b91ca..ed4b7fd 100644 --- a/metadata/jsAlgo.json +++ b/metadata/jsAlgo.json @@ -5,6 +5,7 @@ "id": "", "nftAddress": "", "version": "4.1.0", + "chainId": "", "metadata": { "created": "2023-08-01T17:09:39Z", "updated": "2023-08-01T17:09:39Z", diff --git a/metadata/jsIPFSAlgo.json b/metadata/jsIPFSAlgo.json index dac810c..94f20d7 100644 --- a/metadata/jsIPFSAlgo.json +++ b/metadata/jsIPFSAlgo.json @@ -5,6 +5,7 @@ "id": "", "nftAddress": "", "version": "4.1.0", + "chainId": "", "metadata": { "created": "2023-08-01T17:09:39Z", "updated": "2023-08-01T17:09:39Z", diff --git a/metadata/pythonAlgo.json b/metadata/pythonAlgo.json index 201a9bb..e650f4a 100644 --- a/metadata/pythonAlgo.json +++ b/metadata/pythonAlgo.json @@ -5,6 +5,7 @@ "id": "", "nftAddress": "", "version": "4.1.0", + "chainId": "", "metadata": { "created": "2023-08-01T17:09:39Z", "updated": "2023-08-01T17:09:39Z", diff --git a/metadata/simpleComputeDataset.json b/metadata/simpleComputeDataset.json index b5d4b99..49c79f5 100644 --- a/metadata/simpleComputeDataset.json +++ b/metadata/simpleComputeDataset.json @@ -5,6 +5,7 @@ "id": "", "nftAddress": "", "version": "4.1.0", + "chainId": "", "metadata": { "created": "2021-12-20T14:35:20Z", "updated": "2021-12-20T14:35:20Z", diff --git a/metadata/simpleDownloadDataset.json b/metadata/simpleDownloadDataset.json index dbffb7c..a11ab19 100644 --- a/metadata/simpleDownloadDataset.json +++ b/metadata/simpleDownloadDataset.json @@ -5,6 +5,7 @@ "id": "", "nftAddress": "", "version": "4.1.0", + "chainId": "", "metadata": { "created": "2021-12-20T14:35:20Z", "updated": "2021-12-20T14:35:20Z", diff --git a/metadata/simpleIPFSComputeDataset.json b/metadata/simpleIPFSComputeDataset.json index 0f47213..c5541b7 100644 --- a/metadata/simpleIPFSComputeDataset.json +++ b/metadata/simpleIPFSComputeDataset.json @@ -5,6 +5,7 @@ "id": "", "nftAddress": "", "version": "4.1.0", + "chainId": "", "metadata": { "created": "2021-12-20T14:35:20Z", "updated": "2021-12-20T14:35:20Z", From a2ec4d2c0054efc3df1d1df1fe52d2b12a789d86 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Wed, 20 Nov 2024 16:06:48 +0200 Subject: [PATCH 17/20] replace with null. --- metadata/jsAlgo.json | 2 +- metadata/jsIPFSAlgo.json | 2 +- metadata/pythonAlgo.json | 2 +- metadata/simpleComputeDataset.json | 2 +- metadata/simpleDownloadDataset.json | 2 +- metadata/simpleIPFSComputeDataset.json | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/metadata/jsAlgo.json b/metadata/jsAlgo.json index ed4b7fd..01be122 100644 --- a/metadata/jsAlgo.json +++ b/metadata/jsAlgo.json @@ -5,7 +5,7 @@ "id": "", "nftAddress": "", "version": "4.1.0", - "chainId": "", + "chainId": null, "metadata": { "created": "2023-08-01T17:09:39Z", "updated": "2023-08-01T17:09:39Z", diff --git a/metadata/jsIPFSAlgo.json b/metadata/jsIPFSAlgo.json index 94f20d7..901e6da 100644 --- a/metadata/jsIPFSAlgo.json +++ b/metadata/jsIPFSAlgo.json @@ -5,7 +5,7 @@ "id": "", "nftAddress": "", "version": "4.1.0", - "chainId": "", + "chainId": null, "metadata": { "created": "2023-08-01T17:09:39Z", "updated": "2023-08-01T17:09:39Z", diff --git a/metadata/pythonAlgo.json b/metadata/pythonAlgo.json index e650f4a..dc64675 100644 --- a/metadata/pythonAlgo.json +++ b/metadata/pythonAlgo.json @@ -5,7 +5,7 @@ "id": "", "nftAddress": "", "version": "4.1.0", - "chainId": "", + "chainId": null, "metadata": { "created": "2023-08-01T17:09:39Z", "updated": "2023-08-01T17:09:39Z", diff --git a/metadata/simpleComputeDataset.json b/metadata/simpleComputeDataset.json index 49c79f5..19d9a3b 100644 --- a/metadata/simpleComputeDataset.json +++ b/metadata/simpleComputeDataset.json @@ -5,7 +5,7 @@ "id": "", "nftAddress": "", "version": "4.1.0", - "chainId": "", + "chainId": null, "metadata": { "created": "2021-12-20T14:35:20Z", "updated": "2021-12-20T14:35:20Z", diff --git a/metadata/simpleDownloadDataset.json b/metadata/simpleDownloadDataset.json index a11ab19..1bd5a42 100644 --- a/metadata/simpleDownloadDataset.json +++ b/metadata/simpleDownloadDataset.json @@ -5,7 +5,7 @@ "id": "", "nftAddress": "", "version": "4.1.0", - "chainId": "", + "chainId": null, "metadata": { "created": "2021-12-20T14:35:20Z", "updated": "2021-12-20T14:35:20Z", diff --git a/metadata/simpleIPFSComputeDataset.json b/metadata/simpleIPFSComputeDataset.json index c5541b7..bac4943 100644 --- a/metadata/simpleIPFSComputeDataset.json +++ b/metadata/simpleIPFSComputeDataset.json @@ -5,7 +5,7 @@ "id": "", "nftAddress": "", "version": "4.1.0", - "chainId": "", + "chainId": null, "metadata": { "created": "2021-12-20T14:35:20Z", "updated": "2021-12-20T14:35:20Z", From e451ffa41e60a987b0c19438e0c39703c443776b Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Thu, 21 Nov 2024 14:44:50 +0200 Subject: [PATCH 18/20] rename template index with template id. --- src/helpers.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index 5efed08..22e44c4 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -70,7 +70,7 @@ export async function createAssetUtil( config: Config, aquariusInstance: Aquarius, encryptDDO: boolean = true, - templateIndex: number = 1, + templateId: number = 1, providerFeeToken: string = ZERO_ADDRESS, accessListFactory?: string, allowAccessList?: string, @@ -79,7 +79,7 @@ export async function createAssetUtil( ) { const { chainId } = await owner.provider.getNetwork(); - if(templateIndex === 4){ + if(templateId === 4){ // Wrap the signer for Sapphire const wrappedSigner = sapphire.wrap(owner); @@ -95,9 +95,9 @@ export async function createAssetUtil( await owner.getAddress(), [await owner.getAddress(), ZERO_ADDRESS] ) - return await createAsset(name, symbol, wrappedSigner, assetUrl, templateIndex, ddo, encryptDDO, providerUrl || macOsProviderUrl, providerFeeToken, aquariusInstance, accessListFactory, allowAccessList, denyAccessList); + return await createAsset(name, symbol, wrappedSigner, assetUrl, templateId, ddo, encryptDDO, providerUrl || macOsProviderUrl, providerFeeToken, aquariusInstance, accessListFactory, allowAccessList, denyAccessList); } - return await createAsset(name, symbol, owner, assetUrl, templateIndex, ddo, encryptDDO, providerUrl || macOsProviderUrl, providerFeeToken, aquariusInstance); + return await createAsset(name, symbol, owner, assetUrl, templateId, ddo, encryptDDO, providerUrl || macOsProviderUrl, providerFeeToken, aquariusInstance); } From 0ed52a7a74014322b677c03adbe04a602e9a9958 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Thu, 21 Nov 2024 14:53:24 +0200 Subject: [PATCH 19/20] Fix workflow. --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2f075e..4059873 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -96,8 +96,6 @@ jobs: docker image rm node:20-alpine docker image rm node:18 docker image rm node:18-alpine - docker image rm node:16 - docker image rm node:16-alpine docker image rm debian:10 docker image rm debian:11 docker image rm ubuntu:22.04 From bfccdc78b69632b462e206d8f36646aa8988dd56 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Mon, 25 Nov 2024 15:09:25 +0200 Subject: [PATCH 20/20] Add sdk check. --- src/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers.ts b/src/helpers.ts index 22e44c4..80d0814 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -79,7 +79,7 @@ export async function createAssetUtil( ) { const { chainId } = await owner.provider.getNetwork(); - if(templateId === 4){ + if(templateId === 4 && config.sdk === 'oasis'){ // Wrap the signer for Sapphire const wrappedSigner = sapphire.wrap(owner);