Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 34 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,24 @@ jobs:
node-version: ${{ matrix.node }}
cache: npm

# ocean.js#2216 build; remove with the link step after its release
- name: Checkout ocean.js
uses: actions/checkout@v7
with:
persist-credentials: false
repository: 'oceanprotocol/ocean.js'
ref: 'rc_11.0.0'
path: 'ocean.js'
- name: Build and link ocean.js
working-directory: ${{ github.workspace }}/ocean.js
run: npm ci && npm run build && npm link

- name: Install dependencies
run: npm ci

- name: Use the ocean.js build
run: npm link @oceanprotocol/lib

- name: Run build
run: npm run build

Expand Down Expand Up @@ -143,6 +158,9 @@ jobs:

test_system:
runs-on: ubuntu-latest
env:
# ocean-node#1601 image; remove after its release
NODE_VERSION: pr-1601
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -183,8 +201,23 @@ jobs:
working-directory: ${{ github.workspace }}/barge
run: |
bash -x start_ocean.sh --with-typesense 2>&1 > start_ocean.log &
# ocean.js#2216 build; remove with the link step after its release
- name: Checkout ocean.js
uses: actions/checkout@v7
with:
persist-credentials: false
repository: 'oceanprotocol/ocean.js'
ref: 'rc_11.0.0'
path: 'ocean.js'
- name: Build and link ocean.js
working-directory: ${{ github.workspace }}/ocean.js
run: npm ci && npm run build && npm link

- name: Install dependencies
run: npm ci
- name: Use the ocean.js build
run: npm link @oceanprotocol/lib

- run: npm run build
- run: docker image ls
- name: Wait for node to be ready
Expand Down Expand Up @@ -219,7 +252,7 @@ jobs:
attempt=1
echo "Waiting for node HTTP API to be ready..."
while [ $attempt -le $max_attempts ]; do
PEER_ID=$(curl -s http://127.0.0.1:8001 | jq -r '.nodeId // empty' 2>/dev/null)
PEER_ID=$(curl -s http://127.0.0.1:8001 | jq -r '.id // empty' 2>/dev/null)
if [ -n "$PEER_ID" ]; then
echo "Got peer ID: $PEER_ID"
echo "NODE_URL=${PEER_ID}" >> $GITHUB_ENV
Expand Down
8 changes: 4 additions & 4 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ One big class holding all command logic. The constructor:

- sets `this.config = config || new ConfigHelper().getConfig(network)` — ocean.js's `ConfigHelper` maps a chainId (or name) to a network config object,
- sets `this.oceanNodeUrl = process.env.NODE_URL` and `this.config.nodeUri = this.oceanNodeUrl`,
- creates `this.aquarius = new Aquarius(this.oceanNodeUrl)` (the Ocean Node also serves the Aquarius/indexer API),
- resolves and validates DDOs with `ProviderInstance` against `this.oceanNodeUrl` (`waitForIndexer`, `validateDdo`),
- loads `this.indexingParams` from `getIndexingWaitSettings()`.

### Config & chain selection — one mechanism (important)
Expand Down Expand Up @@ -157,9 +157,9 @@ uses directly. `destroyProviders()` tears providers down on exit (next to `stopP
`helpers.ts` is the seam between the CLI and ocean.js:

- `createAssetUtil(...)` wraps ocean.js `createAsset` (used by publish/publishAlgo and the interactive publisher). It resolves the active ERC20 template (`calculateActiveTemplateIndex` reads and `JSON.parse`s the `@oceanprotocol/contracts` `ERC20Template.json` ABI, resolved via `createRequire`/`require.resolve` so it works from any cwd — e.g. a global install — not a cwd-relative `node_modules` path), and for **Oasis Sapphire** (`config.sdk === 'oasis'`) wraps the signer with `wrapEthersSigner` from `@oasisprotocol/sapphire-ethers-v6` (`getSignerAccordingSdk`; sapphire-paratime v2 moved its ethers integration into that package, and it throws `SignerHasNoProviderError` for a provider-less signer) and deploys an allow access list before creating the asset.
- `updateAssetMetadata(...)` — used by `editAsset`, `allowAlgo`, `disallowAlgo` and the interactive publisher. It validates the DDO via `aquarius.validate`, then either `ProviderInstance.encrypt`s the DDO (flags = 2) or hexlifies raw JSON (flags = 0) depending on the `encryptDDO` flag, then calls `nft.setMetadata`.
- `updateAssetMetadata(...)` — used by `editAsset`, `allowAlgo`, `disallowAlgo` and the interactive publisher. It validates the DDO via `ProviderInstance.validateDdo`, then either `ProviderInstance.encrypt`s the DDO (flags = 2) or hexlifies raw JSON (flags = 0) depending on the `encryptDDO` flag, then calls `nft.setMetadata`.
- `handleComputeOrder(...)` — the ordering state machine used in compute: validOrder + no fees → reuse as-is; validOrder + fees → `datatoken.reuseOrder` paying only provider fees; no order → `orderAsset` (pay 1 datatoken + fees). Approves provider-fee tokens first when the fee amount > 0.
- `resolveComputeInputs(...)` + `parseComputeInput(...)` — parse the datasets/algo CLI strings (DID | JSON object | array | mixed | legacy `[did:a,did:b]`), resolve DID entries through `aquarius.waitForIndexer`, pass raw entries through (a `fileObject`, or for an algorithm inline `meta.rawcode`; aligned with a `null` DDO slot), and pick `providerURI` from the first DID-based DDO's `serviceEndpoint` (else fall back to `NODE_URL`).
- `resolveComputeInputs(...)` + `parseComputeInput(...)` — parse the datasets/algo CLI strings (DID | JSON object | array | mixed | legacy `[did:a,did:b]`), resolve DID entries through `ProviderInstance.waitForIndexer` on the node, pass raw entries through (a `fileObject`, or for an algorithm inline `meta.rawcode`; aligned with a `null` DDO slot), and pick `providerURI` from the first DID-based DDO's `serviceEndpoint` (else fall back to `NODE_URL`).
- `fixAndParseProviderFees(...)` — regex-based repair of the stringified provider-initialize response that is round-tripped from `initializeCompute` into `computeStart` (adds quotes to keys, DIDs, hex addresses). Fragile by design; touch carefully.
- `getIndexingWaitSettings()` — reads the `INDEXING_*` env vars.
- Signing/encryption is always done via the `Signer` and `ProviderInstance` from ocean.js; the CLI never handles raw keys beyond constructing the `ethers.Wallet`.
Expand Down Expand Up @@ -231,7 +231,7 @@ Most tests are **integration/system tests that require a running Ocean stack** (
- `test/setup.test.ts` — asserts `npm run cli h` help output and the env-var validation error messages.
- `test/consumeFlow.test.ts`, `paidComputeFlow.test.ts`, `escrow.test.ts`, `accessList.test.ts`, `storage.test.ts` — end-to-end flows against the live node.
- `test/http.test.ts` — hits the node HTTP API (`localhost:8001`) directly.
- `test/resolveComputeInputs.test.ts` — a **true unit test** using a fake `Aquarius`; runs with no infra.
- `test/resolveComputeInputs.test.ts` — a **true unit test** that stubs `ProviderInstance.waitForIndexer`; runs with no infra.
- `test/interactivePublishFlow.ts` — the enquirer wizard (note: no `.test.ts` suffix, so it is not picked up by the `test:system` glob).

CI (`.github/workflows/ci.yml`) has three jobs: `build`, `lint`, and `test_system` (matrix over `transport: [http, p2p]`), which checks out `oceanprotocol/barge`, runs `start_ocean.sh --with-typesense`, waits for `ocean-node-1`, sets `NODE_URL` (HTTP `http://127.0.0.1:8001`, or the peer id for P2P), and runs `npm run test:system` with `AVOID_LOOP_RUN=true` and `INDEXING_RETRY_INTERVAL=4000` / `INDEXING_MAX_RETRIES=120`.
Expand Down
31 changes: 13 additions & 18 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
listChains,
} from "./rpcRegistry.js";
import {
Aquarius,
ComputeAsset,
ComputeJob,
Config,
Expand Down Expand Up @@ -131,7 +130,7 @@
* Drains a (possibly endless) log stream into a string. Chunks already received
* when the read is aborted are kept — a bounded read is the normal way this ends.
*/
async function drainLogStream(stream: any): Promise<string> {

Check warning on line 133 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 133 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
const chunks: Uint8Array[] = [];
if (!stream[Symbol.asyncIterator]) {
return await new Response(stream).text();
Expand All @@ -152,7 +151,6 @@
export class Commands {
public signer: Signer;
public config: Config;
public aquarius: Aquarius;
public oceanNodeUrl: string;
// optional settings for indexing wait time
private indexingParams: IndexerWaitParams;
Expand All @@ -174,7 +172,6 @@
this.indexingParams = getIndexingWaitSettings();
console.log("Using Ocean Node URL :", this.oceanNodeUrl);
this.config.nodeUri = this.oceanNodeUrl;
this.aquarius = new Aquarius(this.oceanNodeUrl);
}

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -310,7 +307,7 @@
public async start() {
console.log("Starting the interactive CLI flow...\n\n");
const data = await interactiveFlow(this.oceanNodeUrl); // Collect data via CLI
await publishAsset(this.aquarius, data, this.signer, this.config); // Publish asset with collected data
await publishAsset(data, this.signer, this.config); // Publish asset with collected data
}

// utils
Expand Down Expand Up @@ -345,11 +342,10 @@
indexedMetadata.nft.name,
indexedMetadata.nft.symbol,
this.signer,
(services[0].files as any).files ?? services[0].files,

Check warning on line 345 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 345 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
asset,
this.oceanNodeUrl,
this.config,
this.aquarius,
encryptDDO,
);
console.log("Asset published. ID: " + urlAssetId);
Expand Down Expand Up @@ -383,11 +379,10 @@
indexedMetadata.nft.name,
indexedMetadata.nft.symbol,
this.signer,
(services[0].files as any).files ?? services[0].files,

Check warning on line 382 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 382 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
algoAsset,
this.oceanNodeUrl,
this.config,
this.aquarius,
encryptDDO,
);
// add some more checks
Expand All @@ -400,7 +395,8 @@
}

public async editAsset(args: string[]) {
const asset = await this.aquarius.waitForIndexer(
const asset = await ProviderInstance.waitForIndexer(
this.oceanNodeUrl,
args[1],
null,
null,
Expand Down Expand Up @@ -435,15 +431,15 @@
this.signer,
asset,
this.oceanNodeUrl,
this.aquarius,
encryptDDO,
);
console.log("Asset updated. Tx: " + JSON.stringify(updateAssetTx, null, 2));
}

public async getDDO(args: string[]) {
console.log("Resolving Asset with DID: " + args[1]);
const resolvedDDO = await this.aquarius.waitForIndexer(
const resolvedDDO = await ProviderInstance.waitForIndexer(
this.oceanNodeUrl,
args[1],
null,
null,
Expand Down Expand Up @@ -512,7 +508,8 @@

public async download(args: string[]) {
const did = args[1];
const dataDdo = await this.aquarius.waitForIndexer(
const dataDdo = await ProviderInstance.waitForIndexer(
this.oceanNodeUrl,
did,
null,
null,
Expand Down Expand Up @@ -635,7 +632,6 @@
const resolved = await resolveComputeInputs(
args[1],
args[2],
this.aquarius,
this.indexingParams,
this.oceanNodeUrl,
);
Expand Down Expand Up @@ -1038,7 +1034,6 @@
const resolved = await resolveComputeInputs(
args[1],
args[2],
this.aquarius,
this.indexingParams,
this.oceanNodeUrl,
);
Expand Down Expand Up @@ -1657,7 +1652,6 @@
const resolved = await resolveComputeInputs(
args[1],
args[2],
this.aquarius,
this.indexingParams,
this.oceanNodeUrl,
);
Expand Down Expand Up @@ -2590,7 +2584,7 @@
const jobs = await ProviderInstance.getServices(
nodeUrl,
this.signer,
filters as any,

Check warning on line 2587 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 2587 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
);
if (!jobs || jobs.length < 1) {
const filterDesc =
Expand Down Expand Up @@ -2746,12 +2740,12 @@
if (sameToken && pricedResources) {
const minutes = Math.ceil(additionalDuration / 60);
cost = job.resources.reduce(
(sum: number, r: any) =>

Check warning on line 2743 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 2743 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
sum + Number(r.price ?? 0) * Number(r.amount ?? 0) * minutes,
0,
);
} else {
const resources = (job.resources ?? []).map((r: any) => ({

Check warning on line 2748 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 2748 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
id: r.id,
amount: r.amount,
}));
Expand Down Expand Up @@ -2786,7 +2780,7 @@
node: this.oceanNodeUrl,
token,
environmentId: env.id,
resources: (job.resources ?? []).map((r: any) => ({

Check warning on line 2783 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 2783 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
id: r.id,
amount: r.amount,
})),
Expand Down Expand Up @@ -2949,7 +2943,8 @@
}

public async allowAlgo(args: string[]) {
const asset = await this.aquarius.waitForIndexer(
const asset = await ProviderInstance.waitForIndexer(
this.oceanNodeUrl,
args[1],
null,
null,
Expand Down Expand Up @@ -2982,7 +2977,8 @@
);
return;
}
const algoAsset = await this.aquarius.waitForIndexer(
const algoAsset = await ProviderInstance.waitForIndexer(
this.oceanNodeUrl,
args[2],
null,
null,
Expand Down Expand Up @@ -3034,7 +3030,6 @@
this.signer,
asset,
this.oceanNodeUrl,
this.aquarius,
encryptDDO,
);
console.log("Successfully updated asset metadata: " + txid);
Expand All @@ -3045,7 +3040,8 @@
}

public async disallowAlgo(args: string[]) {
const asset = await this.aquarius.waitForIndexer(
const asset = await ProviderInstance.waitForIndexer(
this.oceanNodeUrl,
args[1],
null,
null,
Expand Down Expand Up @@ -3103,7 +3099,6 @@
this.signer,
asset,
this.oceanNodeUrl,
this.aquarius,
encryptDDO,
);
console.log("Asset updated " + txid);
Expand Down Expand Up @@ -4068,7 +4063,7 @@
),
);
removedCount++;
} catch (e: any) {

Check warning on line 4066 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 4066 in src/commands.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
console.log(
chalk.yellow(
`⚠ Could not remove token ${tokenId} for user ${user}: ${e.message}`,
Expand Down
23 changes: 10 additions & 13 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
} from "@oceanprotocol/ddo-js";
import {
AccesslistFactory,
Aquarius,
Nft,
NftFactory,
ProviderInstance,
Expand Down Expand Up @@ -137,11 +136,10 @@
name: string,
symbol: string,
owner: Signer,
assetUrl: any,

Check warning on line 139 in src/helpers.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 139 in src/helpers.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
ddo: DDO,
oceanNodeUrl: string,
config: Config,
aquariusInstance: Aquarius,
encryptDDO: boolean = true,
templateIDorAddress: string | number = 1, // If string, it's template address , otherwise, it's templateId,
providerFeeToken: string = ZERO_ADDRESS,
Expand Down Expand Up @@ -184,7 +182,6 @@
encryptDDO,
oceanNodeUrl,
providerFeeToken,
aquariusInstance,
accessListFactory,
allowAccessList,
denyAccessList,
Expand All @@ -200,15 +197,13 @@
encryptDDO,
oceanNodeUrl,
providerFeeToken,
aquariusInstance,
);
}

export async function updateAssetMetadata(
owner: Signer,
updatedDdo: Asset,
oceanNodeUrl: string,
aquariusInstance: Aquarius,
encryptDDO: boolean = true,
): Promise<any> {
const nft = new Nft(
Expand All @@ -217,11 +212,12 @@
);
let flags;
let metadata;
const validateResult = await aquariusInstance.validate(
const validateResult = await ProviderInstance.validateDdo(
oceanNodeUrl,
updatedDdo,
owner,
oceanNodeUrl,
);
if (!validateResult) throw new Error("DDO validation failed");
const ddoInstance = DDOManager.getDDOClass(updatedDdo);
const { chainId, nftAddress } = ddoInstance.getDDOFields();
if (encryptDDO) {
Expand Down Expand Up @@ -424,14 +420,13 @@

// Resolves the raw datasets/algo CLI strings into fully-built ComputeAsset[] and
// ComputeAlgorithm, plus index-aligned DDO arrays (null where the entry is raw).
// DID entries are resolved via Aquarius; raw (fileObject) entries are passed through
// DID entries are resolved on nodeUri; raw (fileObject) entries are passed through
// untouched. Returns null (after logging) when a DID cannot be resolved.
export async function resolveComputeInputs(
datasetsInput: string,
algoInput: string,
aquarius: Aquarius,
indexingParams: IndexerWaitParams,
fallbackProviderURI: string,
nodeUri: string,
): Promise<ResolvedComputeInputs | null> {
const datasetTokens = parseComputeInput(datasetsInput);

Expand All @@ -440,7 +435,8 @@

for (const token of datasetTokens) {
if (typeof token === "string") {
const dataDdo = await aquarius.waitForIndexer(
const dataDdo = await ProviderInstance.waitForIndexer(
nodeUri,
token,
undefined,
undefined,
Expand Down Expand Up @@ -484,7 +480,7 @@
}
}

let providerURI = fallbackProviderURI;
let providerURI = nodeUri;
const firstDdo = ddos.find((d) => d !== null);
if (firstDdo) {
providerURI =
Expand All @@ -498,7 +494,8 @@
let algoDdo: Asset | DDO | null = null;

if (typeof algoToken === "string") {
algoDdo = await aquarius.waitForIndexer(
algoDdo = await ProviderInstance.waitForIndexer(
nodeUri,
algoToken,
undefined,
undefined,
Expand Down
6 changes: 2 additions & 4 deletions src/publishAsset.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// src/publishAsset.ts
import { Signer } from "ethers";
import { Config, Aquarius } from "@oceanprotocol/lib";
import { Config } from "@oceanprotocol/lib";
import { Asset } from "@oceanprotocol/ddo-js";
import { createAssetUtil, updateAssetMetadata } from "./helpers.js";

Expand All @@ -21,7 +21,6 @@ export interface PublishAssetParams {
}

export async function publishAsset(
aquarius: Aquarius,
params: PublishAssetParams,
signer: Signer,
config: Config,
Expand Down Expand Up @@ -105,7 +104,6 @@ export async function publishAsset(
metadata,
params.providerUrl,
config,
aquarius,
);

console.log(`Asset successfully published with DID: ${did}`);
Expand All @@ -116,7 +114,7 @@ export async function publishAsset(
metadata.services[0].datatokenAddress = assetUrl.datatokenAddress; // Update with the correct Datatoken address

// Use the helper function to update the metadata on the NFT
await updateAssetMetadata(signer, metadata, params.providerUrl, aquarius);
await updateAssetMetadata(signer, metadata, params.providerUrl);

console.log(`Metadata successfully updated for DID: ${did}`);
} catch (error) {
Expand Down
Loading
Loading