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

C2D V2 fixes #72

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion metadata/jsAlgo.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
"nftAddress": "0x0",
"files": [
{
"type": "url",
"url": "https://raw.githubusercontent.com/oceanprotocol/test-algorithm/master/javascript/algo.js",
"contentType": "text/js",
"encoding": "UTF-8"
"encoding": "UTF-8",
"method": "GET"
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion metadata/simpleComputeDataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"id": "",
"nftAddress": "",
"version": "4.1.0",
"chainId": 8996,
"chainId": null,
"metadata": {
"created": "2021-12-20T14:35:20Z",
"updated": "2021-12-20T14:35:20Z",
Expand Down
1,379 changes: 729 additions & 650 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"dependencies": {
"@oceanprotocol/contracts": "^2.0.4",
"@oceanprotocol/lib": "^3.4.1",
"@oceanprotocol/lib": "^4.0.0-next.1",
"cross-fetch": "^3.1.5",
"crypto-js": "^4.1.1",
"decimal.js": "^10.4.1",
Expand Down
17 changes: 12 additions & 5 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,9 @@ export class Commands {
}
assets.push({
documentId: ddos[dataDdo].id,
serviceId: ddos[dataDdo].services[0].id,
serviceId: ddos[dataDdo].services[0].id
});

}

console.log("Starting compute job using provider: ", providerURI);
Expand All @@ -346,7 +347,7 @@ export class Commands {
computeEnv.id,
computeValidUntil,
providerURI,
await this.signer.getAddress()
this.signer // V1 was this.signer.getAddress()
);
if (
!providerInitializeComputeJob ||
Expand Down Expand Up @@ -411,6 +412,10 @@ export class Commands {
" with additional datasets:" +
(!additionalDatasets ? "none" : additionalDatasets[0].documentId)
);
if(additionalDatasets!==null) {
console.log('Adding additional datasets to dataset, according to C2D V2 specs')
assets.push(additionalDatasets)
}

const output: ComputeOutput = {
metadataUri: await getMetadataURI()
Expand All @@ -420,12 +425,14 @@ export class Commands {
providerURI,
this.signer,
computeEnv.id,
assets[0],
assets, // assets[0] // only c2d v1,
algo,
null,
additionalDatasets,
output
// additionalDatasets, only c2d v1
output,
computeEnv.free ? true : false //
);

if (computeJobs && computeJobs[0]) {
const { jobId, agreementId } = computeJobs[0];
console.log("Compute started. JobID: " + jobId);
Expand Down
13 changes: 10 additions & 3 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
ProviderFees,
ComputeAlgorithm,
LoggerInstance,
Datatoken4
Datatoken4
} from "@oceanprotocol/lib";
import { hexlify } from "ethers/lib/utils";

Expand Down Expand Up @@ -71,8 +71,8 @@
name: string,
symbol: string,
owner: Signer,
assetUrl: any,

Check warning on line 74 in src/helpers.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
ddo: any,

Check warning on line 75 in src/helpers.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
providerUrl: string,
config: Config,
aquariusInstance: Aquarius,
Expand Down Expand Up @@ -130,14 +130,14 @@
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,
Expand Down Expand Up @@ -174,6 +174,9 @@
// create the files encrypted string
assetUrl.datatokenAddress = datatokenAddressAsset;
assetUrl.nftAddress = nftAddress;
if(!assetUrl.type) {
assetUrl.type = 'url'
}
ddo.services[0].files = templateIndex === 4 ? '' : await ProviderInstance.encrypt(
assetUrl,
chainId,
Expand Down Expand Up @@ -299,7 +302,10 @@
- have validOrder and providerFees -> then order is valid but providerFees are not valid, we need to call reuseOrder and pay only providerFees
- no validOrder -> we need to call startOrder, to pay 1 DT & providerFees
*/
if (order.providerFee && order.providerFee.providerFeeAmount) {
const hasProviderFees = order.providerFee && order.providerFee.providerFeeAmount
// no need to approve if it is 0
if (hasProviderFees && Number(order.providerFee.providerFeeAmount) > 0) {

await approveWei(
payerAccount,
config,
Expand All @@ -308,6 +314,7 @@
asset.services[0].datatokenAddress,
order.providerFee.providerFeeAmount
);

}
if (order.validOrder) {
if (!order.providerFee) return order.validOrder;
Expand Down
11 changes: 7 additions & 4 deletions src/publishAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Signer } from 'ethers';
import {
Config,
Aquarius,
DDO
Asset
} from '@oceanprotocol/lib';
import { createAsset, updateAssetMetadata } from './helpers';

Expand All @@ -28,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: DDO = {
const metadata: Asset = {
'@context': ['https://w3id.org/did/v1'],
id: '', // Will be updated after creating asset
version: '4.1.0',
Expand All @@ -48,7 +48,7 @@ export async function publishAsset(params: PublishAssetParams, signer: Signer, c
allocated: 0,
orders: 0,
price: {
value: params.isCharged ? params.price : "0"
value: params.isCharged ? Number(params.price) : 0
}
},
services: [
Expand All @@ -70,7 +70,10 @@ export async function publishAsset(params: PublishAssetParams, signer: Signer, c
tokenURI: "",
owner: "",
created: ""
}
},
datatokens: [],
event: undefined,
purgatory: undefined
};

// Asset URL setup based on storage type
Expand Down
Loading