Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 4.0 #1922

Draft
wants to merge 31 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f0acea3
add validate function signature changes, missing update docs and others
paulo-ocean Feb 19, 2025
858f264
fix nonce
paulo-ocean Feb 21, 2025
380420c
see if the issue was the format
paulo-ocean Feb 21, 2025
7d59523
debug paths
paulo-ocean Feb 21, 2025
a1e5a8b
update validate api call, consider legacy as backup
paulo-ocean Feb 21, 2025
2033cf9
undo function call extra params
paulo-ocean Feb 21, 2025
06912b9
more debug
paulo-ocean Feb 21, 2025
b5194cd
another try
paulo-ocean Feb 21, 2025
6f8628f
more debug
paulo-ocean Feb 21, 2025
0171930
more debug
paulo-ocean Feb 21, 2025
7ad8a97
more debug
paulo-ocean Feb 21, 2025
f7b7a85
more debug
paulo-ocean Feb 21, 2025
dac84ba
Merge f7b7a859604ff35bcf8f1f74bd41676aee0e7f3e into c8314806269ba21bb…
paulo-ocean Feb 21, 2025
b26f453
Updating CodeExamples.md
Feb 21, 2025
7b6e9e4
Updating ComputeExamples.md
Feb 21, 2025
528387a
remove console.log
paulo-ocean Feb 22, 2025
76e80ce
Merge branch 'issue-1913-validateddo-params' of github.com:oceanproto…
paulo-ocean Feb 22, 2025
9ee165a
refactor fn name to avoid confusion with new one
paulo-ocean Feb 22, 2025
e1b5d3f
minor refactor, nonce
paulo-ocean Feb 24, 2025
390c5fc
use process.env if not supplied in param
paulo-ocean Feb 25, 2025
2c00003
Merge branch 'main' into issue-1913-validateddo-params
paulo-ocean Feb 25, 2025
8444cf2
add comments
paulo-ocean Feb 28, 2025
52cffa3
Merge branch 'main' into issue-1913-validateddo-params
paulo-ocean Mar 3, 2025
8fc2fc5
fix filr url
paulo-ocean Mar 3, 2025
9a542d0
DDO.js integration + ESM updates
ahmedraza118 Mar 4, 2025
70d5a06
C2D_V2 ( Includes C2D V2 breaking changes + Free compute) (#1912)
paulo-ocean Mar 4, 2025
99cfc18
README update
alexcos20 Mar 4, 2025
4d7725d
push package-lock
alexcos20 Mar 4, 2025
1301acb
merge & fix conflicts
paulo-ocean Mar 5, 2025
6199be8
Merge pull request #1914 from oceanprotocol/issue-1913-validateddo-pa…
paulo-ocean Mar 5, 2025
059b37d
fix signature message for streamabale logs
paulo-ocean Mar 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"ignorePatterns": ["dist/**/*"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module",
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,6 @@ jobs:
bash -x start_ocean.sh --with-provider2 --no-dashboard --with-c2d 2>&1 > start_ocean.log &
- run: npm ci
- run: npm run build:metadata
- name: Delete default runner images
run: |
docker image rm -f node:18
docker image rm -f node:18-alpine
docker image rm -f node:20
docker image rm -f debian:10
docker image rm -f debian:11
docker image rm -f moby/buildkit:latest
- name: Wait for contracts deployment and C2D cluster to be ready
working-directory: ${{ github.workspace }}/barge
run: |
Expand Down
8 changes: 8 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"require": ["source-map-support/register", "mock-local-storage"],
"extension": ["ts"],
"timeout": 200000,
"bail": true,
"exit": true,
"fullTrace": true
}
9 changes: 5 additions & 4 deletions CodeExamples.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Start by importing all of the necessary dependencies
import fs from 'fs'

import { ethers, providers, Signer } from 'ethers'
import { SHA256 } from 'crypto-js'
import crypto from 'crypto-js'
import { homedir } from 'os'
import {
approve,
Expand Down Expand Up @@ -109,8 +109,9 @@ import {
getEventFromTx,
DDO,
LoggerInstance
} from '@oceanprotocol/lib'
} from '../../src/index.js'
```
const { SHA256 } = crypto

<!--
describe('Marketplace flow tests
Expand Down Expand Up @@ -165,7 +166,7 @@ Next, we define the metadata that will describe our data asset. This is what we
```Typescript
const genericAsset: DDO = {
'@context': ['https://w3id.org/did/v1'],
id: '',
id: 'did:op',
version: '4.1.0',
chainId: 8996,
nftAddress: '0x0',
Expand Down Expand Up @@ -821,7 +822,7 @@ Let's start by using the `setData` method to update the nft key value store with
data
)
} catch (e) {
console.log('e = ', e)
console.log('error = ', e)
assert.fail('Failed to set data in NFT ERC725 key value store', e)
}
```
Expand Down
221 changes: 125 additions & 96 deletions ComputeExamples.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ Start by importing all of the necessary dependencies
import fs from 'fs'
import { homedir } from 'os'

import { SHA256 } from 'crypto-js'
import { ethers, providers, Signer } from 'ethers'
import {
ProviderInstance,
Expand All @@ -144,9 +143,12 @@ import {
configHelperNetworks,
ConfigHelper,
getEventFromTx,
amountToUnits
} from '@oceanprotocol/lib'
amountToUnits,
isDefined
} from '../../src/index.js'
```
import crypto from 'crypto-js'
const { SHA256 } = crypto

### 4.2. Constants and variables

Expand Down Expand Up @@ -275,15 +277,18 @@ let resolvedAlgorithmDdo: DDO

let computeJobId: string
let agreementId: string

let computeRoutePath: string
let hasFreeComputeSupport: boolean
```

### 4.3 Helper methods

Now we define the helper methods which we will use later to publish the dataset and algorithm, and also order them

Add a `createAsset()`function.
Add a `createAssetHelper()`function.
```Typescript
async function createAsset(
async function createAssetHelper(
name: string,
symbol: string,
owner: Signer,
Expand Down Expand Up @@ -503,7 +508,7 @@ you need to mint oceans to mentioned accounts only if you are using barge to tes

### 6.1 Publish a dataset (create NFT + Datatoken) and set dataset metadata
```Typescript
datasetId = await createAsset(
datasetId = await createAssetHelper(
'D1Min',
'D1M',
publisherAccount,
Expand All @@ -520,7 +525,7 @@ Now, let's check that we successfully published a dataset (create NFT + Datatoke

### 6.2 Publish an algorithm (create NFT + Datatoken) and set algorithm metadata
```Typescript
algorithmId = await createAsset(
algorithmId = await createAssetHelper(
'D1Min',
'D1M',
publisherAccount,
Expand Down Expand Up @@ -594,119 +599,143 @@ Now, let's check that we successfully published a algorithm (create NFT + Datato
let's check the free compute environment
```Typescript
const computeEnv = computeEnvs[resolvedDatasetDdo.chainId].find(
(ce) => ce.priceMin === 0
(ce) => ce.priceMin === 0 || isDefined(ce.free)
)
console.log('Free compute environment = ', computeEnv)
```
<!--
assert(computeEnv, 'Cannot find the free compute env')
-->

Let's have 5 minute of compute access
```Typescript
const mytime = new Date()
const computeMinutes = 5
mytime.setMinutes(mytime.getMinutes() + computeMinutes)
const computeValidUntil = Math.floor(mytime.getTime() / 1000)

const assets: ComputeAsset[] = [
{
documentId: resolvedDatasetDdo.id,
serviceId: resolvedDatasetDdo.services[0].id
computeRoutePath = await ProviderInstance.getComputeStartRoutes(providerUrl, true)
if (isDefined(computeRoutePath)) {
hasFreeComputeSupport = true
Let's have 5 minute of compute access
```Typescript
const mytime = new Date()
const computeMinutes = 5
mytime.setMinutes(mytime.getMinutes() + computeMinutes)
const computeValidUntil = Math.floor(mytime.getTime() / 1000)

const assets: ComputeAsset[] = [
{
documentId: resolvedDatasetDdo.id,
serviceId: resolvedDatasetDdo.services[0].id
}
]
const dtAddressArray = [resolvedDatasetDdo.services[0].datatokenAddress]
const algo: ComputeAlgorithm = {
documentId: resolvedAlgorithmDdo.id,
serviceId: resolvedAlgorithmDdo.services[0].id
}
]
const dtAddressArray = [resolvedDatasetDdo.services[0].datatokenAddress]
const algo: ComputeAlgorithm = {
documentId: resolvedAlgorithmDdo.id,
serviceId: resolvedAlgorithmDdo.services[0].id
}

const providerInitializeComputeResults = await ProviderInstance.initializeCompute(
assets,
algo,
computeEnv.id,
computeValidUntil,
providerUrl,
await consumerAccount.getAddress()
)
```
<!--
assert(!('error' in providerInitializeComputeResults), 'Cannot order algorithm')
-->
```Typescript
algo.transferTxId = await handleOrder(
providerInitializeComputeResults.algorithm,
resolvedAlgorithmDdo.services[0].datatokenAddress,
consumerAccount,
computeEnv.consumerAddress,
0
)
for (let i = 0; i < providerInitializeComputeResults.datasets.length; i++) {
assets[i].transferTxId = await handleOrder(
providerInitializeComputeResults.datasets[i],
dtAddressArray[i],
const providerInitializeComputeResults = await ProviderInstance.initializeCompute(
assets,
algo,
computeEnv.id,
computeValidUntil,
providerUrl,
consumerAccount
)
```
<!--
assert(!('error' in providerInitializeComputeResults), 'Cannot order algorithm')
-->
```Typescript
algo.transferTxId = await handleOrder(
providerInitializeComputeResults.algorithm,
resolvedAlgorithmDdo.services[0].datatokenAddress,
consumerAccount,
computeEnv.consumerAddress,
0
)
}
for (let i = 0; i < providerInitializeComputeResults.datasets.length; i++) {
assets[i].transferTxId = await handleOrder(
providerInitializeComputeResults.datasets[i],
dtAddressArray[i],
consumerAccount,
computeEnv.consumerAddress,
0
)
}

const computeJobs = await ProviderInstance.computeStart(
providerUrl,
consumerAccount,
computeEnv.id,
assets[0],
algo
)
const computeJobs = await ProviderInstance.freeComputeStart(
providerUrl,
consumerAccount,
computeEnv.id,
assets,
algo
)

```
<!--
assert(computeJobs, 'Cannot start compute job')
-->
Let's save the compute job it, we re going to use later
```Typescript
computeJobId = computeJobs[0].jobId
// eslint-disable-next-line prefer-destructuring
agreementId = computeJobs[0].agreementId
```
<!--
assert(computeJobs, 'Cannot start compute job')
-->
Let's save the compute job it, we re going to use later
```Typescript
computeJobId = computeJobs[0].jobId
// eslint-disable-next-line prefer-destructuring
agreementId = computeJobs[0].agreementId
} else {
assert(
computeRoutePath === null,
'Route path for free compute is not defined (perhaps because provider does not support it yet?)'
)
hasFreeComputeSupport = false
}

```

## 11. Check compute status and get download compute results URL
### 11.1 Check compute status
You can also add various delays so you see the various states of the compute job
```Typescript
const jobStatus = await ProviderInstance.computeStatus(
providerUrl,
await consumerAccount.getAddress(),
computeJobId,
agreementId
)
```
<!--
assert(jobStatus, 'Cannot retrieve compute status!')
-->
Now, let's see the current status of the previously started computer job
```Typescript
console.log('Current status of the compute job: ', jobStatus)
if (!hasFreeComputeSupport) {
assert(
computeRoutePath === null,
'Compute route path for free compute is not defined (perhaps because provider does not support it yet?)'
)
} else {
You can also add various delays so you see the various states of the compute job
```Typescript
const jobStatus = await ProviderInstance.computeStatus(
providerUrl,
await consumerAccount.getAddress(),
computeJobId,
agreementId
)
```
<!--
assert(jobStatus, 'Cannot retrieve compute status!')
-->
Now, let's see the current status of the previously started computer job
```Typescript
console.log('Current status of the compute job: ', jobStatus)
}

```

### 11.2 Get download compute results URL
```Typescript
await sleep(10000)
const downloadURL = await ProviderInstance.getComputeResultUrl(
providerUrl,
consumerAccount,
computeJobId,
0
)
```
<!--
assert(downloadURL, 'Provider getComputeResultUrl failed!')
-->
Let's check the compute results url for the specified index
```Typescript
console.log(`Compute results URL: ${downloadURL}`)
if (!hasFreeComputeSupport) {
assert(
computeRoutePath === null,
'Compute route path for free compute is not defined (perhaps because provider does not support it yet?)'
)
} else {
```Typescript
await sleep(10000)
const downloadURL = await ProviderInstance.getComputeResultUrl(
providerUrl,
consumerAccount,
computeJobId,
0
)
```
<!--
assert(downloadURL, 'Provider getComputeResultUrl failed!')
-->
Let's check the compute results url for the specified index
```Typescript
console.log(`Compute results URL: ${downloadURL}`)
}

```

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ npm install @oceanprotocol/lib
- Visit the [Ocean Protocol website](https://docs.oceanprotocol.com/) for general information about Ocean Protocol.
- If you have any difficulties or if you have further questions about how to use ocean.js please reach out to us on [Discord](https://discord.gg/TnXjkR5).
- If you notice any bugs or issues with ocean.js please [open an issue on github](https://github.com/oceanprotocol/ocean.js/issues/new?assignees=&labels=bug&template=bug_report.md&title=).
- Developers using this library should ensure their tsconfig.json includes the necessary options:
```
{
"moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
}
```
- If using Next.js, they may need "moduleResolution": "bundler" for better compatibility.

## 🦑 Development

Expand Down
4 changes: 3 additions & 1 deletion docs/classes/Aquarius.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ ___

### validate

▸ **validate**(`ddo`, `signal?`): `Promise`<[`ValidateMetadata`](../interfaces/ValidateMetadata.md)\>
▸ **validate**(`ddo`, `signal?`,`signer?`,`providerUrl?`): `Promise`<[`ValidateMetadata`](../interfaces/ValidateMetadata.md)\>

Validate DDO content

Expand All @@ -132,6 +132,8 @@ Validate DDO content
| Name | Type | Description |
| :------ | :------ | :------ |
| `ddo` | [`DDO`](../interfaces/DDO.md) | DID Descriptor Object content. |
| `signer?` | `Signer` | publisher account (for signature). |
| `providerUrl?` | `string` | Provider url (to get nonce) |
| `signal?` | `AbortSignal` | abort signal |

#### Returns
Expand Down
Loading