From df9b1bd10ed09fc86ce4733d61d1555a2ffaf303 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Thu, 3 Oct 2024 16:13:19 +0300 Subject: [PATCH 01/17] Created download functionality. --- src/helpers/download.ts | 110 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 src/helpers/download.ts diff --git a/src/helpers/download.ts b/src/helpers/download.ts new file mode 100644 index 0000000..22ad5ef --- /dev/null +++ b/src/helpers/download.ts @@ -0,0 +1,110 @@ +import { + Aquarius, + Datatoken, + ProviderInstance, + ConfigHelper, + orderAsset +} from '@oceanprotocol/lib' +import { Signer } from 'ethers' +import fs from 'fs' +import * as path from "path" + + + export async function downloadFile( + url: string, + downloadPath: string, + index?: number +): Promise { + const response = await fetch(url); + if (!response.ok) { + throw new Error("Response error."); + } + + const defaultName = !isNaN(index) && index > -1 ? `file_${index}.out` : 'file.out' + let filename: string + + try { + // try to get it from headers + filename = response.headers + .get("content-disposition") + .match(/attachment;filename=(.+)/)[1]; + } catch { + filename = defaultName; + } + + const filePath = path.join(downloadPath, filename); + const data = await response.arrayBuffer(); + + try { + await fs.writeFile(filePath, Buffer.from(data)); + } catch (err) { + throw new Error("Error while saving the file:", err.message); + } + + return filename +} + + +export async function download( + did: string, + owner: Signer, + pathString: string = '.', + aquariusInstance: Aquarius, + macOsProviderUrl?: string, + providerUrl?: string, +) { + const dataDdo = await aquariusInstance.waitForAqua(did); + if (!dataDdo) { + console.error( + "Error fetching DDO " + did + ". Does this asset exists?" + ) + return + } + let providerURI + if (!providerUrl) { + providerURI = macOsProviderUrl && dataDdo.chainId === 8996 + ? macOsProviderUrl + : dataDdo.services[0].serviceEndpoint + } else { + providerURI = providerUrl + } + console.log("Downloading asset using provider: ", providerURI) + const { chainId } = await owner.provider.getNetwork() + console.log('Chain ID:', chainId) + const config = new ConfigHelper().getConfig(chainId) + console.log('Config:', config) + const datatoken = new Datatoken(owner, chainId) + + const tx = await orderAsset( + dataDdo, + owner, + config, + datatoken, + providerURI + ) + + if (!tx) { + console.error( + "Error ordering access for " + did + ". Do you have enough tokens?" + ) + return + } + + const orderTx = await tx.wait(); + + const urlDownloadUrl = await ProviderInstance.getDownloadUrl( + dataDdo.id, + dataDdo.services[0].id, + 0, + orderTx.transactionHash, + providerURI, + owner + ); + try { + const path = pathString ? pathString : '.'; + const { filename } = await downloadFile(urlDownloadUrl, path); + console.log("File downloaded successfully:", path + "/" + filename); + } catch (e) { + console.log(`Download url dataset failed: ${e}`); + } +} \ No newline at end of file From dc9ac21b362fecc832ec03ea6d4062c2ad886de5 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Mon, 7 Oct 2024 12:51:16 +0300 Subject: [PATCH 02/17] fix import. --- src/helpers/download.ts | 159 +++++++++++++++++++--------------------- 1 file changed, 74 insertions(+), 85 deletions(-) diff --git a/src/helpers/download.ts b/src/helpers/download.ts index 22ad5ef..17a58db 100644 --- a/src/helpers/download.ts +++ b/src/helpers/download.ts @@ -1,110 +1,99 @@ import { - Aquarius, - Datatoken, - ProviderInstance, - ConfigHelper, - orderAsset + Aquarius, + Datatoken, + ProviderInstance, + ConfigHelper, + orderAsset } from '@oceanprotocol/lib' import { Signer } from 'ethers' -import fs from 'fs' -import * as path from "path" +import { promises as fs } from 'fs' +import * as path from 'path' - - export async function downloadFile( - url: string, - downloadPath: string, - index?: number +export async function downloadFile( + url: string, + downloadPath: string, + index?: number ): Promise { - const response = await fetch(url); - if (!response.ok) { - throw new Error("Response error."); - } + const response = await fetch(url) + if (!response.ok) { + throw new Error('Response error.') + } - const defaultName = !isNaN(index) && index > -1 ? `file_${index}.out` : 'file.out' - let filename: string + const defaultName = !isNaN(index) && index > -1 ? `file_${index}.out` : 'file.out' + let filename: string - try { - // try to get it from headers - filename = response.headers - .get("content-disposition") - .match(/attachment;filename=(.+)/)[1]; - } catch { - filename = defaultName; - } + try { + // try to get it from headers + filename = response.headers + .get('content-disposition') + .match(/attachment;filename=(.+)/)[1] + } catch { + filename = defaultName + } - const filePath = path.join(downloadPath, filename); - const data = await response.arrayBuffer(); + const filePath = path.join(downloadPath, filename) + const data = await response.arrayBuffer() - try { - await fs.writeFile(filePath, Buffer.from(data)); - } catch (err) { - throw new Error("Error while saving the file:", err.message); - } + try { + await fs.writeFile(filePath, Buffer.from(data)) + } catch (err) { + throw new Error('Error while saving the file:', err.message) + } - return filename + return filename } - export async function download( did: string, owner: Signer, pathString: string = '.', aquariusInstance: Aquarius, macOsProviderUrl?: string, - providerUrl?: string, + providerUrl?: string ) { - const dataDdo = await aquariusInstance.waitForAqua(did); - if (!dataDdo) { - console.error( - "Error fetching DDO " + did + ". Does this asset exists?" - ) - return - } - let providerURI - if (!providerUrl) { - providerURI = macOsProviderUrl && dataDdo.chainId === 8996 + const dataDdo = await aquariusInstance.waitForAqua(did) + if (!dataDdo) { + console.error('Error fetching DDO ' + did + '. Does this asset exists?') + return + } + let providerURI + if (!providerUrl) { + providerURI = + macOsProviderUrl && dataDdo.chainId === 8996 ? macOsProviderUrl : dataDdo.services[0].serviceEndpoint - } else { - providerURI = providerUrl - } - console.log("Downloading asset using provider: ", providerURI) - const { chainId } = await owner.provider.getNetwork() - console.log('Chain ID:', chainId) - const config = new ConfigHelper().getConfig(chainId) - console.log('Config:', config) - const datatoken = new Datatoken(owner, chainId) + } else { + providerURI = providerUrl + } + console.log('Downloading asset using provider: ', providerURI) + const { chainId } = await owner.provider.getNetwork() + console.log('Chain ID:', chainId) + const config = new ConfigHelper().getConfig(chainId) + console.log('Config:', config) + const datatoken = new Datatoken(owner, chainId) - const tx = await orderAsset( - dataDdo, - owner, - config, - datatoken, - providerURI - ) + const tx = await orderAsset(dataDdo, owner, config, datatoken, providerURI) - if (!tx) { - console.error( - "Error ordering access for " + did + ". Do you have enough tokens?" - ) - return - } + if (!tx) { + console.error('Error ordering access for ' + did + '. Do you have enough tokens?') + return + } - const orderTx = await tx.wait(); + const orderTx = await tx.wait() - const urlDownloadUrl = await ProviderInstance.getDownloadUrl( - dataDdo.id, - dataDdo.services[0].id, - 0, - orderTx.transactionHash, - providerURI, - owner - ); - try { - const path = pathString ? pathString : '.'; - const { filename } = await downloadFile(urlDownloadUrl, path); - console.log("File downloaded successfully:", path + "/" + filename); - } catch (e) { - console.log(`Download url dataset failed: ${e}`); - } -} \ No newline at end of file + const urlDownloadUrl = await ProviderInstance.getDownloadUrl( + dataDdo.id, + dataDdo.services[0].id, + 0, + orderTx.transactionHash, + providerURI, + owner + ) + try { + const path = pathString ? pathString : '.' + const { filename } = await downloadFile(urlDownloadUrl, path) + console.log('File downloaded successfully:', path + '/' + filename) + } catch (e) { + console.log(`Download url dataset failed: ${e}`) + } +} From 94999d333a7caff126bbea9ed0098245e996d3b1 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Mon, 14 Oct 2024 14:11:31 +0300 Subject: [PATCH 03/17] Add download to extension. --- src/extension.ts | 91 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index d821201..5ec995c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -5,6 +5,7 @@ import { ethers } from 'ethers' import * as fs from 'fs' import { createAsset } from './helpers/publish' import fetch from 'cross-fetch' +import { download } from './helpers/download' globalThis.fetch = fetch @@ -156,7 +157,95 @@ export function activate(context: vscode.ExtensionContext) { } ) - context.subscriptions.push(getAssetDetails, publishAsset) + let downloadAsset = vscode.commands.registerCommand( + 'ocean-protocol.downloadAsset', + async (config: any, filePath: string, privateKey: string, assetDid: string) => { + vscode.window.showInformationMessage(`Private key: ${privateKey}`) + vscode.window.showInformationMessage(`File path: ${filePath}`) + vscode.window.showInformationMessage(`Config: ${JSON.stringify(config)}`) + vscode.window.showInformationMessage(`Asset DID: ${assetDid}`) + if (!assetDid) { + vscode.window.showErrorMessage('No DID provided.') + return + } + if (!filePath) { + vscode.window.showErrorMessage('No file path provided.') + return + } + + if (!privateKey) { + vscode.window.showErrorMessage('No private key provided.') + return + } + + try { + // Set up the signer + const provider = new ethers.providers.JsonRpcProvider(process.env.RPC) + + console.log('RPC URL:', config.rpcUrl) + + console.log('NFT Factory Address:', config.nftFactoryAddress) + console.log('Ocean Token Address:', config.oceanTokenAddress) + + const signer = new ethers.Wallet(privateKey, provider) + console.log('Signer:', signer) + const chainId = await signer.getChainId() + console.log('Chain ID:', chainId) + vscode.window.showInformationMessage(`Signer: ${signer}`) + + // Test provider connectivity + try { + const network = provider.network + vscode.window.showInformationMessage(`Connected to network: ${network}`) + } catch (networkError) { + console.error('Error connecting to network:', networkError) + vscode.window.showErrorMessage( + `Error connecting to network: ${networkError.message}` + ) + return + } + try { + const blockNumber = await provider.getBlockNumber() + console.log('Current block number:', blockNumber) + } catch (error) { + console.error('Error connecting to provider:', error) + } + + const aquarius = new Aquarius(config.aquariusUrl) + console.log('Chain ID:', chainId) + vscode.window.showInformationMessage(`Chain ID: ${chainId}`) + const oceanConfig = new ConfigHelper().getConfig(chainId) + vscode.window.showInformationMessage( + `Ocean Config: ${JSON.stringify(oceanConfig)}` + ) + console.log('Ocean Config:', oceanConfig) + + await download( + assetDid, + signer, + filePath, + aquarius, + undefined, + config.providerUrl + ) + + vscode.window.showInformationMessage( + `Asset download successfully. Path: ${filePath}` + ) + } catch (error) { + console.error('Error details:', error) + if (error instanceof Error) { + vscode.window.showErrorMessage(`Error downloading asset: ${error.message}`) + } else { + vscode.window.showErrorMessage( + `An unknown error occurred while downloading the asset.` + ) + } + } + } + ) + + context.subscriptions.push(getAssetDetails, publishAsset, downloadAsset) } export function deactivate() {} From 4a71458b3eadb2fff635dc19d116a90b8e6294fb Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Mon, 14 Oct 2024 14:28:13 +0300 Subject: [PATCH 04/17] Configure extension. --- src/viewProvider.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/viewProvider.ts b/src/viewProvider.ts index 0a2efb5..a36a1dd 100644 --- a/src/viewProvider.ts +++ b/src/viewProvider.ts @@ -174,6 +174,45 @@ export class OceanProtocolViewProvider implements vscode.WebviewViewProvider { } }); +

Download Asset

+ + + + + + + + + + + + ` From abce3efad198198889fc4feee7e931ff562a2d38 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Mon, 14 Oct 2024 22:00:33 +0300 Subject: [PATCH 05/17] Fix review. --- src/extension.ts | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 5ec995c..063d68c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -66,9 +66,6 @@ export function activate(context: vscode.ExtensionContext) { let publishAsset = vscode.commands.registerCommand( 'ocean-protocol.publishAsset', async (config: any, filePath: string, privateKey: string) => { - vscode.window.showInformationMessage(`Private key: ${privateKey}`) - vscode.window.showInformationMessage(`File path: ${filePath}`) - vscode.window.showInformationMessage(`Config: ${JSON.stringify(config)}`) if (!filePath) { vscode.window.showErrorMessage('No file path provided.') return @@ -90,15 +87,8 @@ export function activate(context: vscode.ExtensionContext) { // Set up the signer const provider = new ethers.providers.JsonRpcProvider(process.env.RPC) - console.log('RPC URL:', config.rpcUrl) - - console.log('NFT Factory Address:', config.nftFactoryAddress) - console.log('Ocean Token Address:', config.oceanTokenAddress) - const signer = new ethers.Wallet(privateKey, provider) - console.log('Signer:', signer) const chainId = await signer.getChainId() - console.log('Chain ID:', chainId) vscode.window.showInformationMessage(`Signer: ${signer}`) // Test provider connectivity @@ -112,22 +102,13 @@ export function activate(context: vscode.ExtensionContext) { ) return } - try { - const blockNumber = await provider.getBlockNumber() - console.log('Current block number:', blockNumber) - } catch (error) { - console.error('Error connecting to provider:', error) - } const aquarius = new Aquarius(config.aquariusUrl) - console.log('Chain ID:', chainId) vscode.window.showInformationMessage(`Chain ID: ${chainId}`) const oceanConfig = new ConfigHelper().getConfig(chainId) vscode.window.showInformationMessage( `Ocean Config: ${JSON.stringify(oceanConfig)}` ) - console.log('Ocean Config:', oceanConfig) - console.log('creating asset:', asset) const urlAssetId = await createAsset( asset.nft.name, @@ -160,10 +141,6 @@ export function activate(context: vscode.ExtensionContext) { let downloadAsset = vscode.commands.registerCommand( 'ocean-protocol.downloadAsset', async (config: any, filePath: string, privateKey: string, assetDid: string) => { - vscode.window.showInformationMessage(`Private key: ${privateKey}`) - vscode.window.showInformationMessage(`File path: ${filePath}`) - vscode.window.showInformationMessage(`Config: ${JSON.stringify(config)}`) - vscode.window.showInformationMessage(`Asset DID: ${assetDid}`) if (!assetDid) { vscode.window.showErrorMessage('No DID provided.') return @@ -181,16 +158,8 @@ export function activate(context: vscode.ExtensionContext) { try { // Set up the signer const provider = new ethers.providers.JsonRpcProvider(process.env.RPC) - - console.log('RPC URL:', config.rpcUrl) - - console.log('NFT Factory Address:', config.nftFactoryAddress) - console.log('Ocean Token Address:', config.oceanTokenAddress) - const signer = new ethers.Wallet(privateKey, provider) - console.log('Signer:', signer) const chainId = await signer.getChainId() - console.log('Chain ID:', chainId) vscode.window.showInformationMessage(`Signer: ${signer}`) // Test provider connectivity @@ -204,21 +173,13 @@ export function activate(context: vscode.ExtensionContext) { ) return } - try { - const blockNumber = await provider.getBlockNumber() - console.log('Current block number:', blockNumber) - } catch (error) { - console.error('Error connecting to provider:', error) - } const aquarius = new Aquarius(config.aquariusUrl) - console.log('Chain ID:', chainId) vscode.window.showInformationMessage(`Chain ID: ${chainId}`) const oceanConfig = new ConfigHelper().getConfig(chainId) vscode.window.showInformationMessage( `Ocean Config: ${JSON.stringify(oceanConfig)}` ) - console.log('Ocean Config:', oceanConfig) await download( assetDid, From 47ea8d4b2690557667c418892d38662799f81434 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Tue, 15 Oct 2024 12:03:17 +0300 Subject: [PATCH 06/17] Use private key once in configuration. --- src/viewProvider.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/viewProvider.ts b/src/viewProvider.ts index a36a1dd..bec48ff 100644 --- a/src/viewProvider.ts +++ b/src/viewProvider.ts @@ -112,6 +112,9 @@ export class OceanProtocolViewProvider implements vscode.WebviewViewProvider { + + +

Get Asset Details

@@ -121,9 +124,6 @@ export class OceanProtocolViewProvider implements vscode.WebviewViewProvider {
- - -

Download Asset

- - From c709e465366670ef86c620edf8046b117595efa3 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Tue, 15 Oct 2024 12:28:16 +0300 Subject: [PATCH 07/17] Switch params order. --- src/viewProvider.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/viewProvider.ts b/src/viewProvider.ts index bec48ff..77a6929 100644 --- a/src/viewProvider.ts +++ b/src/viewProvider.ts @@ -204,9 +204,9 @@ export class OceanProtocolViewProvider implements vscode.WebviewViewProvider { const filePathSelected = document.getElementById('filePathInput').value; vscode.postMessage({ type: 'downloadAsset', - privateKey: privateKey, - filePath: filePathSelected, config: config, + filePath: filePathSelected, + privateKey: privateKey, assetDid: assetDidSelected }); }); From 4c992ba3b474900058fbd649a6c4ee705505efd6 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Tue, 15 Oct 2024 15:04:04 +0300 Subject: [PATCH 08/17] Export command. --- src/extension.ts | 4 ++-- src/viewProvider.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 063d68c..4f6cab7 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -85,7 +85,7 @@ export function activate(context: vscode.ExtensionContext) { vscode.window.showInformationMessage('Asset JSON parsed successfully.') // Set up the signer - const provider = new ethers.providers.JsonRpcProvider(process.env.RPC) + const provider = new ethers.providers.JsonRpcProvider(config.rpcUrl) const signer = new ethers.Wallet(privateKey, provider) const chainId = await signer.getChainId() @@ -157,7 +157,7 @@ export function activate(context: vscode.ExtensionContext) { try { // Set up the signer - const provider = new ethers.providers.JsonRpcProvider(process.env.RPC) + const provider = new ethers.providers.JsonRpcProvider(config.rpcUrl) const signer = new ethers.Wallet(privateKey, provider) const chainId = await signer.getChainId() vscode.window.showInformationMessage(`Signer: ${signer}`) diff --git a/src/viewProvider.ts b/src/viewProvider.ts index 77a6929..10ef4c0 100644 --- a/src/viewProvider.ts +++ b/src/viewProvider.ts @@ -38,6 +38,15 @@ export class OceanProtocolViewProvider implements vscode.WebviewViewProvider { data.privateKey ) break + case 'downloadAsset': + vscode.commands.executeCommand( + 'ocean-protocol.downloadAsset', + data.config, + data.filePath, + data.privateKey, + data.assetDid + ) + break case 'openFilePicker': this.openFilePicker() break From 77eff23e23e2682fc45043eadae2d86254bbf1e3 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Tue, 15 Oct 2024 15:37:22 +0300 Subject: [PATCH 09/17] Clean ups. --- src/extension.ts | 18 +++++++++--------- src/viewProvider.ts | 8 +++++++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 4f6cab7..05cbad7 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -66,6 +66,10 @@ export function activate(context: vscode.ExtensionContext) { let publishAsset = vscode.commands.registerCommand( 'ocean-protocol.publishAsset', async (config: any, filePath: string, privateKey: string) => { + if (!config) { + vscode.window.showErrorMessage('No config provided.') + return + } if (!filePath) { vscode.window.showErrorMessage('No file path provided.') return @@ -88,13 +92,10 @@ export function activate(context: vscode.ExtensionContext) { const provider = new ethers.providers.JsonRpcProvider(config.rpcUrl) const signer = new ethers.Wallet(privateKey, provider) - const chainId = await signer.getChainId() - vscode.window.showInformationMessage(`Signer: ${signer}`) // Test provider connectivity try { - const network = provider.network - vscode.window.showInformationMessage(`Connected to network: ${network}`) + provider.network } catch (networkError) { console.error('Error connecting to network:', networkError) vscode.window.showErrorMessage( @@ -104,11 +105,6 @@ export function activate(context: vscode.ExtensionContext) { } const aquarius = new Aquarius(config.aquariusUrl) - vscode.window.showInformationMessage(`Chain ID: ${chainId}`) - const oceanConfig = new ConfigHelper().getConfig(chainId) - vscode.window.showInformationMessage( - `Ocean Config: ${JSON.stringify(oceanConfig)}` - ) const urlAssetId = await createAsset( asset.nft.name, @@ -141,6 +137,10 @@ export function activate(context: vscode.ExtensionContext) { let downloadAsset = vscode.commands.registerCommand( 'ocean-protocol.downloadAsset', async (config: any, filePath: string, privateKey: string, assetDid: string) => { + if (!config) { + vscode.window.showErrorMessage('No config provided.') + return + } if (!assetDid) { vscode.window.showErrorMessage('No DID provided.') return diff --git a/src/viewProvider.ts b/src/viewProvider.ts index cb342ca..eade640 100644 --- a/src/viewProvider.ts +++ b/src/viewProvider.ts @@ -235,6 +235,7 @@ export class OceanProtocolViewProvider implements vscode.WebviewViewProvider { document.getElementById('setupHeader').addEventListener('click', () => toggleSection('setup')); document.getElementById('getAssetHeader').addEventListener('click', () => toggleSection('getAsset')); document.getElementById('publishHeader').addEventListener('click', () => toggleSection('publish')); + document.getElementById('downloadHeader').addEventListener('click', () => toggleSection('download')); }); document.getElementById('getAssetDetailsBtn').addEventListener('click', () => { @@ -271,7 +272,12 @@ export class OceanProtocolViewProvider implements vscode.WebviewViewProvider { break; } }); - + + + + + + document.getElementById('downloadAssetBtn').addEventListener('click', () => { const config = getConfig(); const privateKey = document.getElementById('privateKeyInput').value; From 1d08237261101d7bb66bc7ff5336c038b0c8302b Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Thu, 17 Oct 2024 14:09:34 +0300 Subject: [PATCH 10/17] Fix extension. --- src/extension.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 028ea76..0254961 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -93,21 +93,10 @@ export function activate(context: vscode.ExtensionContext) { const provider = new ethers.providers.JsonRpcProvider(config.rpcUrl) const signer = new ethers.Wallet(privateKey, provider) -<<<<<<< HEAD // Test provider connectivity try { provider.network -======= - console.log('Signer:', signer) - const chainId = await signer.getChainId() - console.log('Chain ID:', chainId) - - // Test provider connectivity - try { - const network = provider.network - console.log(`Connected to network: ${network}`) ->>>>>>> main } catch (networkError) { console.error('Error connecting to network:', networkError) vscode.window.showErrorMessage( From 77ed322f2a71790a64d83b4183fde1b3bf6ce87a Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Thu, 17 Oct 2024 14:30:26 +0300 Subject: [PATCH 11/17] Update library. Fix HTML. --- package-lock.json | 175 ++++++++++++++++++++++++++++++++++++++++++-- package.json | 2 +- src/viewProvider.ts | 14 ++-- 3 files changed, 177 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index a616354..6e6947e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "name": "ocean-protocol", "version": "0.0.1", "dependencies": { - "@oceanprotocol/lib": "^3.3.3", + "@oceanprotocol/lib": "^3.4.2", "axios": "^1.7.7", "chai": "^4.3.10", "cross-fetch": "^4.0.0", @@ -45,6 +45,12 @@ "vscode": "^1.93.0" } }, + "node_modules/@adraffy/ens-normalize": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/@adraffy/ens-normalize/-/ens-normalize-1.10.0.tgz", + "integrity": "sha512-nA9XHtlAkYfJxY7bce8DcN7eKxWWCWkU+1GR9d+U6MbNpfwQp8TI7vqOsBsMcHoT4mBu2kypKoSKnghEzOOq5Q==", + "license": "MIT" + }, "node_modules/@bcoe/v8-coverage": { "version": "0.2.3", "resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz", @@ -1193,17 +1199,125 @@ "node": ">= 8" } }, + "node_modules/@oasisprotocol/deoxysii": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/@oasisprotocol/deoxysii/-/deoxysii-0.0.5.tgz", + "integrity": "sha512-a6wYPjk8ALDIiQW/971AKOTSTY1qSdld+Y05F44gVZvlb3FOyHfgbIxXm7CZnUG1A+jK49g5SCWYP+V3/Tc75Q==", + "license": "MIT", + "dependencies": { + "bsaes": "0.0.2", + "uint32": "^0.2.1" + } + }, + "node_modules/@oasisprotocol/sapphire-paratime": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@oasisprotocol/sapphire-paratime/-/sapphire-paratime-1.3.2.tgz", + "integrity": "sha512-98EQ2BrT0942B0VY50PKcJ6xmUAcz71y8OBMizP6oBJIh0+ogw/z3r5z4veJitMXM4zQbh5wOFaS9eOcKWX5FA==", + "license": "Apache-2.0", + "dependencies": { + "@noble/hashes": "1.3.2", + "@oasisprotocol/deoxysii": "0.0.5", + "cborg": "1.10.2", + "ethers": "6.10.0", + "tweetnacl": "1.0.3", + "type-fest": "2.19.0" + } + }, + "node_modules/@oasisprotocol/sapphire-paratime/node_modules/@noble/curves": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.2.0.tgz", + "integrity": "sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==", + "license": "MIT", + "dependencies": { + "@noble/hashes": "1.3.2" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@oasisprotocol/sapphire-paratime/node_modules/@noble/hashes": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.2.tgz", + "integrity": "sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==", + "license": "MIT", + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@oasisprotocol/sapphire-paratime/node_modules/@types/node": { + "version": "18.15.13", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.13.tgz", + "integrity": "sha512-N+0kuo9KgrUQ1Sn/ifDXsvg0TTleP7rIy4zOBGECxAljqvqfqpTfzx0Q1NUedOixRMBfe2Whhb056a42cWs26Q==", + "license": "MIT" + }, + "node_modules/@oasisprotocol/sapphire-paratime/node_modules/ethers": { + "version": "6.10.0", + "resolved": "https://registry.npmjs.org/ethers/-/ethers-6.10.0.tgz", + "integrity": "sha512-nMNwYHzs6V1FR3Y4cdfxSQmNgZsRj1RiTU25JwvnJLmyzw9z3SKxNc2XKDuiXXo/v9ds5Mp9m6HBabgYQQ26tA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/ethers-io/" + }, + { + "type": "individual", + "url": "https://www.buymeacoffee.com/ricmoo" + } + ], + "license": "MIT", + "dependencies": { + "@adraffy/ens-normalize": "1.10.0", + "@noble/curves": "1.2.0", + "@noble/hashes": "1.3.2", + "@types/node": "18.15.13", + "aes-js": "4.0.0-beta.5", + "tslib": "2.4.0", + "ws": "8.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@oasisprotocol/sapphire-paratime/node_modules/tslib": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", + "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==", + "license": "0BSD" + }, + "node_modules/@oasisprotocol/sapphire-paratime/node_modules/tweetnacl": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==", + "license": "Unlicense" + }, + "node_modules/@oasisprotocol/sapphire-paratime/node_modules/type-fest": { + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz", + "integrity": "sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==", + "license": "(MIT OR CC0-1.0)", + "engines": { + "node": ">=12.20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@oceanprotocol/contracts": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-2.2.0.tgz", "integrity": "sha512-QhewXdtTebycRSZEdkAdvJkSMMnGZyxldlw2eX4VOJto8wymyNdxuhjL/tiaZ5xO7SS5BqURricx9170hfh2kQ==" }, "node_modules/@oceanprotocol/lib": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.3.3.tgz", - "integrity": "sha512-d98X3tBsfbtUJe90wmXI2HcabE3jyY+5628md6vpuItBCnSZgHIQaFvvND2jRThNEmr+4axavylNk/BS3muA5g==", + "version": "3.4.2", + "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.4.2.tgz", + "integrity": "sha512-Xr/0coXw2eymjivozSwrffukPthCjOLJPbXhUtpv048ZslDdv/OaiEh5iciyx5rZBInh2cHVOaRb8Q0Lj69krQ==", + "license": "Apache-2.0", "dependencies": { - "@oceanprotocol/contracts": "^2.0.3", + "@oasisprotocol/sapphire-paratime": "^1.3.2", + "@oceanprotocol/contracts": "^2.2.0", "cross-fetch": "^4.0.0", "crypto-js": "^4.1.1", "decimal.js": "^10.4.1", @@ -1947,6 +2061,12 @@ "node": ">=0.4.0" } }, + "node_modules/aes-js": { + "version": "4.0.0-beta.5", + "resolved": "https://registry.npmjs.org/aes-js/-/aes-js-4.0.0-beta.5.tgz", + "integrity": "sha512-G965FqalsNyrPqgEGON7nIx1e/OVENSgiEIzyC63haUMuvNnwIgIjMs52hlTCKhkBny7A2ORNlfY9Zu+jmGk1Q==", + "license": "MIT" + }, "node_modules/agent-base": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", @@ -2574,6 +2694,15 @@ "safe-buffer": "^5.1.2" } }, + "node_modules/bsaes": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/bsaes/-/bsaes-0.0.2.tgz", + "integrity": "sha512-iVxJFMOvCUG85sX2UVpZ9IgvH6Jjc5xpd/W8pALvFE7zfCqHkV7hW3M2XZtpg9biPS0K4Eka96bbNNgLohcpgQ==", + "license": "MIT", + "dependencies": { + "uint32": "^0.2.1" + } + }, "node_modules/buffer": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", @@ -2787,6 +2916,15 @@ "integrity": "sha512-4tYFyifaFfGacoiObjJegolkwSU4xQNGbVgUiNYVUxbQ2x2lUsFvY4hVgVzGiIe6WLOPqycWXA40l+PWsxthUw==", "peer": true }, + "node_modules/cborg": { + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/cborg/-/cborg-1.10.2.tgz", + "integrity": "sha512-b3tFPA9pUr2zCUiCfRd2+wok2/LBSNUMKOuRRok+WlvvAgEt/PlbgPTsZUcwCOs53IJvLgTp0eotwtosE6njug==", + "license": "Apache-2.0", + "bin": { + "cborg": "cli.js" + } + }, "node_modules/chai": { "version": "4.3.10", "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.10.tgz", @@ -8922,6 +9060,12 @@ "node": ">=14.17" } }, + "node_modules/uint32": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/uint32/-/uint32-0.2.1.tgz", + "integrity": "sha512-d3i8kc/4s1CFW5g3FctmF1Bu2GVXGBMTn82JY2BW0ZtTtI8pRx1YWGPCFBwRF4uYVSJ7ua4y+qYEPqS+x+3w7Q==", + "license": "Do, what You want" + }, "node_modules/ultron": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz", @@ -9893,6 +10037,27 @@ "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", "license": "ISC" }, + "node_modules/ws": { + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.5.0.tgz", + "integrity": "sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==", + "license": "MIT", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": "^5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, "node_modules/xhr": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/xhr/-/xhr-2.6.0.tgz", diff --git a/package.json b/package.json index 9249fc5..4dbfd50 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "webpack-cli": "^5.1.4" }, "dependencies": { - "@oceanprotocol/lib": "^3.3.3", + "@oceanprotocol/lib": "^3.4.2", "axios": "^1.7.7", "chai": "^4.3.10", "cross-fetch": "^4.0.0", diff --git a/src/viewProvider.ts b/src/viewProvider.ts index eade640..74844f0 100644 --- a/src/viewProvider.ts +++ b/src/viewProvider.ts @@ -161,10 +161,10 @@ export class OceanProtocolViewProvider implements vscode.WebviewViewProvider {
- + - + @@ -205,7 +205,10 @@ export class OceanProtocolViewProvider implements vscode.WebviewViewProvider {
- + + + +
@@ -273,11 +276,6 @@ export class OceanProtocolViewProvider implements vscode.WebviewViewProvider { } }); - - - - - document.getElementById('downloadAssetBtn').addEventListener('click', () => { const config = getConfig(); const privateKey = document.getElementById('privateKeyInput').value; From e50a2feddf538125c7a7af35865290912a96abbd Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Thu, 17 Oct 2024 14:51:00 +0300 Subject: [PATCH 12/17] rollback. --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6e6947e..f2c07eb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "name": "ocean-protocol", "version": "0.0.1", "dependencies": { - "@oceanprotocol/lib": "^3.4.2", + "@oceanprotocol/lib": "^3.3.3", "axios": "^1.7.7", "chai": "^4.3.10", "cross-fetch": "^4.0.0", diff --git a/package.json b/package.json index 4dbfd50..9249fc5 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "webpack-cli": "^5.1.4" }, "dependencies": { - "@oceanprotocol/lib": "^3.4.2", + "@oceanprotocol/lib": "^3.3.3", "axios": "^1.7.7", "chai": "^4.3.10", "cross-fetch": "^4.0.0", From 559a044638a729a82423e88faabdd868fdc414e8 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Thu, 17 Oct 2024 15:20:41 +0300 Subject: [PATCH 13/17] Used right config. --- src/extension.ts | 19 +++---------------- src/viewProvider.ts | 4 ++-- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 0254961..4867c3d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -160,8 +160,7 @@ export function activate(context: vscode.ExtensionContext) { // Set up the signer const provider = new ethers.providers.JsonRpcProvider(config.rpcUrl) const signer = new ethers.Wallet(privateKey, provider) - const chainId = await signer.getChainId() - vscode.window.showInformationMessage(`Signer: ${signer}`) + console.log(`Signer: ${signer}`) // Test provider connectivity try { @@ -175,21 +174,9 @@ export function activate(context: vscode.ExtensionContext) { return } - const aquarius = new Aquarius(config.aquariusUrl) - vscode.window.showInformationMessage(`Chain ID: ${chainId}`) - const oceanConfig = new ConfigHelper().getConfig(chainId) - vscode.window.showInformationMessage( - `Ocean Config: ${JSON.stringify(oceanConfig)}` - ) + const aquarius = new Aquarius(config.nodeUrl) - await download( - assetDid, - signer, - filePath, - aquarius, - undefined, - config.providerUrl - ) + await download(assetDid, signer, filePath, aquarius, undefined, config.nodeUrl) vscode.window.showInformationMessage( `Asset download successfully. Path: ${filePath}` diff --git a/src/viewProvider.ts b/src/viewProvider.ts index 74844f0..8e3cb79 100644 --- a/src/viewProvider.ts +++ b/src/viewProvider.ts @@ -161,10 +161,10 @@ export class OceanProtocolViewProvider implements vscode.WebviewViewProvider {
- + - + From a5f6e3fb3b8ee797100a7abf29da74c9f32dabc8 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Thu, 17 Oct 2024 15:22:57 +0300 Subject: [PATCH 14/17] Fix. --- src/extension.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 4867c3d..ffb4e08 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -174,9 +174,16 @@ export function activate(context: vscode.ExtensionContext) { return } - const aquarius = new Aquarius(config.nodeUrl) + const aquarius = new Aquarius(config.aquariusUrl) - await download(assetDid, signer, filePath, aquarius, undefined, config.nodeUrl) + await download( + assetDid, + signer, + filePath, + aquarius, + undefined, + config.providerUrl + ) vscode.window.showInformationMessage( `Asset download successfully. Path: ${filePath}` From 61ae351242c3a835d1fabe0d6d802fdb0ddaf0b9 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Mon, 21 Oct 2024 11:38:38 +0300 Subject: [PATCH 15/17] Add debug log. --- src/extension.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index ffb4e08..3eef73d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,5 +1,5 @@ import * as vscode from 'vscode' -import { Aquarius, Asset, ConfigHelper } from '@oceanprotocol/lib' +import { Aquarius, Asset } from '@oceanprotocol/lib' import { OceanProtocolViewProvider } from './viewProvider' import { ethers } from 'ethers' import * as fs from 'fs' @@ -90,6 +90,7 @@ export function activate(context: vscode.ExtensionContext) { console.log('Asset JSON parsed successfully.') // Set up the signer + console.log(config.rpcUrl) const provider = new ethers.providers.JsonRpcProvider(config.rpcUrl) const signer = new ethers.Wallet(privateKey, provider) From 4ca289d3d5aa3e50bca6f8eeee53e51bf8014ef6 Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Thu, 24 Oct 2024 15:57:17 +0300 Subject: [PATCH 16/17] Changed chain to test chain. --- metadata/simpleDownloadDataset.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata/simpleDownloadDataset.json b/metadata/simpleDownloadDataset.json index 2c7d615..edbe19f 100644 --- a/metadata/simpleDownloadDataset.json +++ b/metadata/simpleDownloadDataset.json @@ -3,7 +3,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 0e51ad0b65d4a0a5b2263ea796d13bdd3f10cc8a Mon Sep 17 00:00:00 2001 From: mariacarmina Date: Tue, 29 Oct 2024 16:02:27 +0200 Subject: [PATCH 17/17] Updated chain id. --- metadata/simpleDownloadDataset.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata/simpleDownloadDataset.json b/metadata/simpleDownloadDataset.json index edbe19f..e810193 100644 --- a/metadata/simpleDownloadDataset.json +++ b/metadata/simpleDownloadDataset.json @@ -3,7 +3,7 @@ "id": "", "nftAddress": "", "version": "4.1.0", - "chainId": 8996, + "chainId": 11155420, "metadata": { "created": "2021-12-20T14:35:20Z", "updated": "2021-12-20T14:35:20Z",