@oceanprotocol/lib 4.0.2 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -4
- package/CodeExamples.md +38 -13
- package/ComputeExamples.md +92 -54
- package/dist/lib.cjs +1 -1
- package/dist/lib.cjs.map +1 -1
- package/dist/lib.modern.js +1 -1
- package/dist/lib.modern.js.map +1 -1
- package/dist/lib.module.mjs +1 -1
- package/dist/lib.module.mjs.map +1 -1
- package/dist/lib.umd.js +1 -1
- package/dist/lib.umd.js.map +1 -1
- package/dist/types/@types/Compute.d.ts +1 -1
- package/dist/types/@types/File.d.ts +1 -42
- package/dist/types/@types/NFT.d.ts +1 -1
- package/dist/types/@types/index.d.ts +0 -7
- package/dist/types/config/Config.d.ts +2 -12
- package/dist/types/contracts/NFT.d.ts +2 -1
- package/dist/types/services/Aquarius.d.ts +1 -1
- package/dist/types/services/Provider.d.ts +2 -2
- package/dist/types/utils/Assets.d.ts +2 -1
- package/dist/types/utils/OrderUtils.d.ts +1 -1
- package/package.json +5 -4
- package/dist/types/@types/Asset.d.ts +0 -148
- package/dist/types/@types/DDO/ConsumerParameter.d.ts +0 -37
- package/dist/types/@types/DDO/Credentials.d.ts +0 -8
- package/dist/types/@types/DDO/DDO.d.ts +0 -55
- package/dist/types/@types/DDO/Event.d.ts +0 -27
- package/dist/types/@types/DDO/Metadata.d.ts +0 -141
- package/dist/types/@types/DDO/Service.d.ts +0 -106
package/CHANGELOG.md
CHANGED
|
@@ -4,11 +4,25 @@ All notable changes to this project will be documented in this file. Dates are d
|
|
|
4
4
|
|
|
5
5
|
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
6
6
|
|
|
7
|
+
#### [v4.0.3](https://github.com/oceanprotocol/ocean.js/compare/v4.0.2...v4.0.3)
|
|
8
|
+
|
|
9
|
+
- Dependencies update [`#1938`](https://github.com/oceanprotocol/ocean.js/pull/1938)
|
|
10
|
+
- use main branch for node checkout [`#1936`](https://github.com/oceanprotocol/ocean.js/pull/1936)
|
|
11
|
+
- Further integrate ddo-js [`#1935`](https://github.com/oceanprotocol/ocean.js/pull/1935)
|
|
12
|
+
- Make integration tests use Ocean Node not Provider or Aquarius [`#1932`](https://github.com/oceanprotocol/ocean.js/pull/1932)
|
|
13
|
+
- update CODEOWNERS [`#1933`](https://github.com/oceanprotocol/ocean.js/pull/1933)
|
|
14
|
+
- Bump release-it from 15.6.1 to 18.1.2 [`#1921`](https://github.com/oceanprotocol/ocean.js/pull/1921)
|
|
15
|
+
- Bump esbuild and tsx [`#1925`](https://github.com/oceanprotocol/ocean.js/pull/1925)
|
|
16
|
+
- Bump serialize-javascript and mocha [`#1915`](https://github.com/oceanprotocol/ocean.js/pull/1915)
|
|
17
|
+
|
|
7
18
|
#### [v4.0.2](https://github.com/oceanprotocol/ocean.js/compare/v4.0.1...v4.0.2)
|
|
8
19
|
|
|
20
|
+
> 27 March 2025
|
|
21
|
+
|
|
9
22
|
- Bump axios from 1.7.9 to 1.8.3 [`#1926`](https://github.com/oceanprotocol/ocean.js/pull/1926)
|
|
10
23
|
- update to ddo.js v0.0.2 [`#1931`](https://github.com/oceanprotocol/ocean.js/pull/1931)
|
|
11
24
|
- Updating codeowners [`#1929`](https://github.com/oceanprotocol/ocean.js/pull/1929)
|
|
25
|
+
- Release 4.0.2 [`b6a78b6`](https://github.com/oceanprotocol/ocean.js/commit/b6a78b64c684af7c9f360e22ecb7a0fa839e8907)
|
|
12
26
|
|
|
13
27
|
#### [v4.0.1](https://github.com/oceanprotocol/ocean.js/compare/v4.0.0...v4.0.1)
|
|
14
28
|
|
|
@@ -17,7 +31,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
17
31
|
- moving the getChainId call [`#1928`](https://github.com/oceanprotocol/ocean.js/pull/1928)
|
|
18
32
|
- Release 4.0.1 [`519e378`](https://github.com/oceanprotocol/ocean.js/commit/519e378c3cfd6df0ece6e503c89c796a0c76027d)
|
|
19
33
|
|
|
20
|
-
### [v4.0.0](https://github.com/oceanprotocol/ocean.js/compare/
|
|
34
|
+
### [v4.0.0](https://github.com/oceanprotocol/ocean.js/compare/v4.0.0-next.1...v4.0.0)
|
|
21
35
|
|
|
22
36
|
> 18 March 2025
|
|
23
37
|
|
|
@@ -26,9 +40,35 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
26
40
|
- add missing exports, refactor addresses file [`#1904`](https://github.com/oceanprotocol/ocean.js/pull/1904)
|
|
27
41
|
- Use serviceIndex instead of hardcoded indexes. [`#1905`](https://github.com/oceanprotocol/ocean.js/pull/1905)
|
|
28
42
|
- Bump path-to-regexp and express [`#1893`](https://github.com/oceanprotocol/ocean.js/pull/1893)
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
-
|
|
43
|
+
- make retries and interval bigger & configurable on waitForAqua [`#1895`](https://github.com/oceanprotocol/ocean.js/pull/1895)
|
|
44
|
+
- Bump eslint-config-prettier from 9.0.0 to 9.1.0 [`#1884`](https://github.com/oceanprotocol/ocean.js/pull/1884)
|
|
45
|
+
- Add back check for access list factory. [`#1889`](https://github.com/oceanprotocol/ocean.js/pull/1889)
|
|
46
|
+
- Remove circular dependencies, fix imports and improve build [`#1881`](https://github.com/oceanprotocol/ocean.js/pull/1881)
|
|
47
|
+
- chore: remove redundant words in comment [`#1890`](https://github.com/oceanprotocol/ocean.js/pull/1890)
|
|
48
|
+
- Bump @truffle/hdwallet-provider from 2.1.10 to 2.1.15 [`#1886`](https://github.com/oceanprotocol/ocean.js/pull/1886)
|
|
49
|
+
- Bump nyc from 15.1.0 to 17.1.0 [`#1883`](https://github.com/oceanprotocol/ocean.js/pull/1883)
|
|
50
|
+
- Bump @types/crypto-js from 4.1.2 to 4.2.2 [`#1882`](https://github.com/oceanprotocol/ocean.js/pull/1882)
|
|
51
|
+
- Bump actions/download-artifact from 2 to 4.1.7 in /.github/workflows [`#1844`](https://github.com/oceanprotocol/ocean.js/pull/1844)
|
|
52
|
+
- Remove node:16 docker image from workflow. [`#1879`](https://github.com/oceanprotocol/ocean.js/pull/1879)
|
|
53
|
+
- Bump rollup from 2.61.1 to 2.79.2 [`#1866`](https://github.com/oceanprotocol/ocean.js/pull/1866)
|
|
54
|
+
- Remove checks from publishing. ADded chain ID check for ordering. [`#1875`](https://github.com/oceanprotocol/ocean.js/pull/1875)
|
|
55
|
+
- done [`60d0272`](https://github.com/oceanprotocol/ocean.js/commit/60d027294a2893410860f1180ff47177e12e45de)
|
|
56
|
+
- rename waitForAqua as waitForIndexer [`6381795`](https://github.com/oceanprotocol/ocean.js/commit/6381795c957f301b93461d84a14ff59991b58738)
|
|
57
|
+
- 4th pass [`bf94e10`](https://github.com/oceanprotocol/ocean.js/commit/bf94e102e53dd07eac6c671ef222b96e34ffca7f)
|
|
58
|
+
|
|
59
|
+
#### [v4.0.0-next.1](https://github.com/oceanprotocol/ocean.js/compare/v4.0.0-next.0...v4.0.0-next.1)
|
|
60
|
+
|
|
61
|
+
> 12 November 2024
|
|
62
|
+
|
|
63
|
+
- add datasets on ComputeAsset, new start compute fn [`8563429`](https://github.com/oceanprotocol/ocean.js/commit/85634293306fca9aaa3ab5ae06a114149ccc8911)
|
|
64
|
+
- support for consumer signature on initialize compute [`71c5923`](https://github.com/oceanprotocol/ocean.js/commit/71c59230db99a08a6c28df66c26e32ca61c71089)
|
|
65
|
+
- add file object types [`cd936c2`](https://github.com/oceanprotocol/ocean.js/commit/cd936c24a989633d3d8e71b908a375802d2e2970)
|
|
66
|
+
|
|
67
|
+
#### [v4.0.0-next.0](https://github.com/oceanprotocol/ocean.js/compare/v3.4.6...v4.0.0-next.0)
|
|
68
|
+
|
|
69
|
+
> 12 November 2024
|
|
70
|
+
|
|
71
|
+
- Release 4.0.0-next.0 [`658cfe8`](https://github.com/oceanprotocol/ocean.js/commit/658cfe83ff855a83eb97e3cbf1276bed6022a1a6)
|
|
32
72
|
|
|
33
73
|
#### [v3.4.6](https://github.com/oceanprotocol/ocean.js/compare/v3.4.5...v3.4.6)
|
|
34
74
|
|
package/CodeExamples.md
CHANGED
|
@@ -105,11 +105,10 @@ import {
|
|
|
105
105
|
ConfigHelper,
|
|
106
106
|
configHelperNetworks,
|
|
107
107
|
amountToUnits,
|
|
108
|
-
ValidateMetadata,
|
|
109
108
|
getEventFromTx,
|
|
110
|
-
DDO,
|
|
111
109
|
LoggerInstance
|
|
112
110
|
} from '../../src/index.js'
|
|
111
|
+
import { DDO, ValidateMetadata } from '@oceanprotocol/ddo-js'
|
|
113
112
|
```
|
|
114
113
|
const { SHA256 } = crypto
|
|
115
114
|
|
|
@@ -136,7 +135,7 @@ Now we define the variables which we will need later
|
|
|
136
135
|
let dispenserNftAddress: string
|
|
137
136
|
let dispenserDatatokenAddress: string
|
|
138
137
|
let dispenserAddress: string
|
|
139
|
-
let fixedDDO
|
|
138
|
+
let fixedDDO: DDO
|
|
140
139
|
```
|
|
141
140
|
|
|
142
141
|
We also define some constants that we will use:
|
|
@@ -208,9 +207,11 @@ Next, we define the metadata that will describe our data asset. This is what we
|
|
|
208
207
|
const config = new ConfigHelper().getConfig(
|
|
209
208
|
parseInt(String((await publisherAccount.provider.getNetwork()).chainId))
|
|
210
209
|
)
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
210
|
+
if (process.env.OCEAN_NODE_URL) {
|
|
211
|
+
config.oceanNodeUri = process.env.OCEAN_NODE_URL
|
|
212
|
+
}
|
|
213
|
+
aquarius = new Aquarius(config?.oceanNodeUri)
|
|
214
|
+
providerUrl = config?.oceanNodeUri
|
|
214
215
|
addresses = JSON.parse(
|
|
215
216
|
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
216
217
|
fs.readFileSync(
|
|
@@ -222,7 +223,7 @@ Next, we define the metadata that will describe our data asset. This is what we
|
|
|
222
223
|
```
|
|
223
224
|
As we go along it's a good idea to console log the values so that you check they are right
|
|
224
225
|
```Typescript
|
|
225
|
-
console.log(`
|
|
226
|
+
console.log(`Indexer URL: ${config.oceanNodeUri}`)
|
|
226
227
|
console.log(`Provider URL: ${providerUrl}`)
|
|
227
228
|
console.log(`Deployed contracts address: ${addresses}`)
|
|
228
229
|
console.log(`Publisher account address: ${await publisherAccount.getAddress()}`)
|
|
@@ -487,9 +488,11 @@ Before we call the contract we have to call `approve` so that the contract can m
|
|
|
487
488
|
consumerAccount,
|
|
488
489
|
await consumerAccount.getChainId()
|
|
489
490
|
)
|
|
491
|
+
|
|
490
492
|
```
|
|
491
493
|
Now we can make the contract call
|
|
492
494
|
```Typescript
|
|
495
|
+
|
|
493
496
|
await fixedRate.buyDatatokens(freId, '1', '2')
|
|
494
497
|
|
|
495
498
|
consumerOCEANBalance = await balance(
|
|
@@ -530,6 +533,17 @@ Next, we need to initialize the provider
|
|
|
530
533
|
validUntil: initializeData.providerFee.validUntil
|
|
531
534
|
}
|
|
532
535
|
|
|
536
|
+
console.log(`Provider fee amount: ${providerFees.providerFeeAmount}`)
|
|
537
|
+
|
|
538
|
+
const approveTx = await approve(
|
|
539
|
+
consumerAccount,
|
|
540
|
+
config,
|
|
541
|
+
await consumerAccount.getAddress(),
|
|
542
|
+
freDatatokenAddress,
|
|
543
|
+
providerFees.providerFeeAddress,
|
|
544
|
+
providerFees.providerFeeAmount
|
|
545
|
+
)
|
|
546
|
+
|
|
533
547
|
datatoken = new Datatoken(consumerAccount, await consumerAccount.getChainId())
|
|
534
548
|
|
|
535
549
|
```
|
|
@@ -543,6 +557,8 @@ Lets now make the payment
|
|
|
543
557
|
)
|
|
544
558
|
const orderTx = await tx.wait()
|
|
545
559
|
const orderStartedTx = getEventFromTx(orderTx, 'OrderStarted')
|
|
560
|
+
console.log(`Order started, tx: ${orderStartedTx.transactionHash}`)
|
|
561
|
+
|
|
546
562
|
```
|
|
547
563
|
Now we can get the url
|
|
548
564
|
```Typescript
|
|
@@ -580,8 +596,10 @@ Lets check that the download URL was successfully received
|
|
|
580
596
|
LoggerInstance.error('Download failed', e)
|
|
581
597
|
assert.fail('Download failed')
|
|
582
598
|
}
|
|
583
|
-
|
|
584
599
|
```
|
|
600
|
+
<!--
|
|
601
|
+
}).timeout(40000)
|
|
602
|
+
-->
|
|
585
603
|
|
|
586
604
|
## 8. Publish Data NFT and a Datatoken with a dispenser
|
|
587
605
|
|
|
@@ -639,9 +657,10 @@ Lets check that we managed to received all of those values without any problems
|
|
|
639
657
|
console.log(`Dispenser NFT address: ${dispenserNftAddress}`)
|
|
640
658
|
console.log(`Dispenser Datatoken address: ${dispenserDatatokenAddress}`)
|
|
641
659
|
console.log(`Dispenser address: ${dispenserAddress}`)
|
|
642
|
-
|
|
643
660
|
```
|
|
644
|
-
|
|
661
|
+
<!--
|
|
662
|
+
}).timeout(40000)
|
|
663
|
+
-->
|
|
645
664
|
### 8.2 Set metadata in the dispenser NFT
|
|
646
665
|
```Typescript
|
|
647
666
|
const nft = new Nft(
|
|
@@ -689,8 +708,10 @@ Now we need to encrypt file(s) using provider
|
|
|
689
708
|
encryptedDDO,
|
|
690
709
|
isAssetValid.hash
|
|
691
710
|
)
|
|
692
|
-
|
|
693
711
|
```
|
|
712
|
+
<!--
|
|
713
|
+
}).timeout(40000)
|
|
714
|
+
-->
|
|
694
715
|
|
|
695
716
|
## 9. Consume a dispenser data asset
|
|
696
717
|
|
|
@@ -793,8 +814,10 @@ Let's check we received the download URL ok
|
|
|
793
814
|
} catch (e) {
|
|
794
815
|
assert.fail('Download failed')
|
|
795
816
|
}
|
|
796
|
-
|
|
797
817
|
```
|
|
818
|
+
<!--
|
|
819
|
+
}).timeout(40000)
|
|
820
|
+
-->
|
|
798
821
|
|
|
799
822
|
## 10. Using ERC725 Key-Value Store
|
|
800
823
|
|
|
@@ -848,7 +871,9 @@ Use the `getData` method to get the data stored in the nft key value store
|
|
|
848
871
|
```
|
|
849
872
|
|
|
850
873
|
That's it! Note the simplicity. All data was stored and retrieved from on-chain. We don't need Ocean Provider or Ocean Aquarius for these use cases (though the latter can help for fast querying & retrieval).
|
|
851
|
-
|
|
874
|
+
<!--
|
|
875
|
+
}).timeout(40000)
|
|
876
|
+
-->
|
|
852
877
|
|
|
853
878
|
|
|
854
879
|
## Editing this file
|
package/ComputeExamples.md
CHANGED
|
@@ -12,7 +12,7 @@ Here are the steps:
|
|
|
12
12
|
7. [Resolve published datasets and algorithms](#7-resolve-assets)
|
|
13
13
|
8. [Send datatokens to consumer](#8-send-datatokens-to-consumer)
|
|
14
14
|
9. [Consumer fetches compute environment](#9-get-compute-environments)
|
|
15
|
-
10. [Consumer starts a compute job using a free C2D environment](#10-consumer-starts-a-compute-job)
|
|
15
|
+
10. [Consumer starts a free compute job using a free C2D environment](#10-consumer-starts-a-compute-job)
|
|
16
16
|
11. [Check compute status and get download compute results url](#11-check-compute-status-and-get-download-compute-results-url)
|
|
17
17
|
|
|
18
18
|
Let's go through each step.
|
|
@@ -136,7 +136,6 @@ import {
|
|
|
136
136
|
ComputeAsset,
|
|
137
137
|
Config,
|
|
138
138
|
Files,
|
|
139
|
-
DDO,
|
|
140
139
|
NftCreateData,
|
|
141
140
|
DatatokenCreateParams,
|
|
142
141
|
sendTx,
|
|
@@ -148,6 +147,7 @@ import {
|
|
|
148
147
|
} from '../../src/index.js'
|
|
149
148
|
```
|
|
150
149
|
import crypto from 'crypto-js'
|
|
150
|
+
import { DDO } from '@oceanprotocol/ddo-js'
|
|
151
151
|
const { SHA256 } = crypto
|
|
152
152
|
|
|
153
153
|
### 4.2. Constants and variables
|
|
@@ -342,7 +342,7 @@ async function createAssetHelper(
|
|
|
342
342
|
assetUrl.nftAddress = nftAddress
|
|
343
343
|
ddo.services[0].files = await ProviderInstance.encrypt(assetUrl, chain, providerUrl)
|
|
344
344
|
ddo.services[0].datatokenAddress = datatokenAddressAsset
|
|
345
|
-
ddo.services[0].serviceEndpoint =
|
|
345
|
+
ddo.services[0].serviceEndpoint = providerUrl
|
|
346
346
|
|
|
347
347
|
ddo.nftAddress = nftAddress
|
|
348
348
|
ddo.id = 'did:op:' + SHA256(ethers.utils.getAddress(nftAddress) + chain.toString(10))
|
|
@@ -353,7 +353,7 @@ async function createAssetHelper(
|
|
|
353
353
|
nftAddress,
|
|
354
354
|
await owner.getAddress(),
|
|
355
355
|
0,
|
|
356
|
-
|
|
356
|
+
providerUrl,
|
|
357
357
|
'',
|
|
358
358
|
ethers.utils.hexlify(2),
|
|
359
359
|
encryptedResponse,
|
|
@@ -428,9 +428,11 @@ We need to load the configuration. Add the following code into your `run(){ }` f
|
|
|
428
428
|
const config = new ConfigHelper().getConfig(
|
|
429
429
|
parseInt(String((await publisherAccount.provider.getNetwork()).chainId))
|
|
430
430
|
)
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
431
|
+
if (process.env.OCEAN_NODE_URL) {
|
|
432
|
+
config.oceanNodeUri = process.env.OCEAN_NODE_URL
|
|
433
|
+
}
|
|
434
|
+
aquariusInstance = new Aquarius(config?.oceanNodeUri)
|
|
435
|
+
providerUrl = config?.oceanNodeUri
|
|
434
436
|
addresses = JSON.parse(
|
|
435
437
|
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
436
438
|
fs.readFileSync(
|
|
@@ -443,7 +445,7 @@ We need to load the configuration. Add the following code into your `run(){ }` f
|
|
|
443
445
|
```
|
|
444
446
|
As we go along it's a good idea to console log the values so that you check they are right. At the end of your `run(){ ... }` function add the following logs:
|
|
445
447
|
```Typescript
|
|
446
|
-
console.log(`
|
|
448
|
+
console.log(`Indexer URL: ${config.oceanNodeUri}`)
|
|
447
449
|
console.log(`Provider URL: ${providerUrl}`)
|
|
448
450
|
console.log(`Deployed contracts address: ${addresses}`)
|
|
449
451
|
console.log(`Publisher account address: ${publisherAccount}`)
|
|
@@ -489,8 +491,10 @@ you need to mint oceans to mentioned accounts only if you are using barge to tes
|
|
|
489
491
|
await publisherAccount.getAddress(),
|
|
490
492
|
amountToUnits(null, null, '1000', 18)
|
|
491
493
|
)
|
|
492
|
-
|
|
493
494
|
```
|
|
495
|
+
<!--
|
|
496
|
+
}).timeout(40000) ///
|
|
497
|
+
--->
|
|
494
498
|
|
|
495
499
|
### 5.2 Send some OCEAN to consumer account
|
|
496
500
|
```Typescript
|
|
@@ -520,8 +524,10 @@ you need to mint oceans to mentioned accounts only if you are using barge to tes
|
|
|
520
524
|
Now, let's check that we successfully published a dataset (create NFT + Datatoken)
|
|
521
525
|
```Typescript
|
|
522
526
|
console.log(`dataset id: ${datasetId}`)
|
|
523
|
-
|
|
524
527
|
```
|
|
528
|
+
<!--
|
|
529
|
+
}).timeout(40000)
|
|
530
|
+
-->
|
|
525
531
|
|
|
526
532
|
### 6.2 Publish an algorithm (create NFT + Datatoken) and set algorithm metadata
|
|
527
533
|
```Typescript
|
|
@@ -537,9 +543,10 @@ Now, let's check that we successfully published a dataset (create NFT + Datatoke
|
|
|
537
543
|
Now, let's check that we successfully published a algorithm (create NFT + Datatoken)
|
|
538
544
|
```Typescript
|
|
539
545
|
console.log(`algorithm id: ${algorithmId}`)
|
|
540
|
-
|
|
541
546
|
```
|
|
542
|
-
|
|
547
|
+
<!--
|
|
548
|
+
}).timeout(40000)
|
|
549
|
+
-->
|
|
543
550
|
## 7. Resolve assets
|
|
544
551
|
|
|
545
552
|
### 7.1 Resolve published datasets and algorithms
|
|
@@ -550,8 +557,8 @@ Now, let's check that we successfully published a algorithm (create NFT + Datato
|
|
|
550
557
|
<!--
|
|
551
558
|
assert(resolvedDatasetDdo, 'Cannot fetch DDO from Aquarius')
|
|
552
559
|
assert(resolvedAlgorithmDdo, 'Cannot fetch DDO from Aquarius')
|
|
560
|
+
}).timeout(80000)
|
|
553
561
|
-->
|
|
554
|
-
|
|
555
562
|
|
|
556
563
|
## 8. Send datatokens to consumer
|
|
557
564
|
|
|
@@ -574,8 +581,10 @@ Now, let's check that we successfully published a algorithm (create NFT + Datato
|
|
|
574
581
|
'10',
|
|
575
582
|
await consumerAccount.getAddress()
|
|
576
583
|
)
|
|
577
|
-
|
|
578
584
|
```
|
|
585
|
+
<!--
|
|
586
|
+
}).timeout(40000)
|
|
587
|
+
-->
|
|
579
588
|
|
|
580
589
|
## 9. Get compute environments
|
|
581
590
|
|
|
@@ -585,21 +594,24 @@ Now, let's check that we successfully published a algorithm (create NFT + Datato
|
|
|
585
594
|
```
|
|
586
595
|
<!--
|
|
587
596
|
assert(computeEnvs, 'No Compute environments found')
|
|
597
|
+
}).timeout(40000)
|
|
588
598
|
-->
|
|
589
|
-
|
|
590
599
|
|
|
591
|
-
## 10. Consumer starts a compute job
|
|
600
|
+
## 10. Consumer starts a free compute job
|
|
592
601
|
|
|
593
602
|
### 10.1 Start a compute job using a free C2D environment
|
|
603
|
+
<!--
|
|
594
604
|
datatoken = new Datatoken(
|
|
595
605
|
consumerAccount,
|
|
596
606
|
(await consumerAccount.provider.getNetwork()).chainId
|
|
597
607
|
)
|
|
608
|
+
-->
|
|
598
609
|
|
|
599
610
|
let's check the free compute environment
|
|
600
611
|
```Typescript
|
|
601
|
-
const computeEnv = computeEnvs
|
|
602
|
-
(ce) =>
|
|
612
|
+
const computeEnv = computeEnvs.find(
|
|
613
|
+
(ce) =>
|
|
614
|
+
!ce?.fees || ce.fees.find((fee) => fee.symbol === 'OCEAN' && fee.amount === '0')
|
|
603
615
|
)
|
|
604
616
|
console.log('Free compute environment = ', computeEnv)
|
|
605
617
|
```
|
|
@@ -607,9 +619,12 @@ let's check the free compute environment
|
|
|
607
619
|
assert(computeEnv, 'Cannot find the free compute env')
|
|
608
620
|
-->
|
|
609
621
|
|
|
622
|
+
<!--
|
|
610
623
|
computeRoutePath = await ProviderInstance.getComputeStartRoutes(providerUrl, true)
|
|
611
624
|
if (isDefined(computeRoutePath)) {
|
|
612
625
|
hasFreeComputeSupport = true
|
|
626
|
+
-->
|
|
627
|
+
|
|
613
628
|
Let's have 5 minute of compute access
|
|
614
629
|
```Typescript
|
|
615
630
|
const mytime = new Date()
|
|
@@ -617,6 +632,9 @@ let's check the free compute environment
|
|
|
617
632
|
mytime.setMinutes(mytime.getMinutes() + computeMinutes)
|
|
618
633
|
const computeValidUntil = Math.floor(mytime.getTime() / 1000)
|
|
619
634
|
|
|
635
|
+
```
|
|
636
|
+
Let's prepare the dataset and algorithm assets to be used in the compute job
|
|
637
|
+
```Typescript
|
|
620
638
|
const assets: ComputeAsset[] = [
|
|
621
639
|
{
|
|
622
640
|
documentId: resolvedDatasetDdo.id,
|
|
@@ -624,41 +642,49 @@ let's check the free compute environment
|
|
|
624
642
|
}
|
|
625
643
|
]
|
|
626
644
|
const dtAddressArray = [resolvedDatasetDdo.services[0].datatokenAddress]
|
|
645
|
+
|
|
627
646
|
const algo: ComputeAlgorithm = {
|
|
628
647
|
documentId: resolvedAlgorithmDdo.id,
|
|
629
|
-
serviceId: resolvedAlgorithmDdo.services[0].id
|
|
648
|
+
serviceId: resolvedAlgorithmDdo.services[0].id,
|
|
649
|
+
meta: resolvedAlgorithmDdo.metadata.algorithm
|
|
630
650
|
}
|
|
631
|
-
|
|
632
|
-
const providerInitializeComputeResults = await ProviderInstance.initializeCompute(
|
|
633
|
-
assets,
|
|
634
|
-
algo,
|
|
635
|
-
computeEnv.id,
|
|
636
|
-
computeValidUntil,
|
|
637
|
-
providerUrl,
|
|
638
|
-
consumerAccount
|
|
639
|
-
)
|
|
640
651
|
```
|
|
652
|
+
|
|
641
653
|
<!--
|
|
642
|
-
|
|
654
|
+
// const providerInitializeComputeResults = await ProviderInstance.initializeCompute(
|
|
655
|
+
// assets,
|
|
656
|
+
// algo,
|
|
657
|
+
// computeEnv.id,
|
|
658
|
+
// computeValidUntil,
|
|
659
|
+
// providerUrl,
|
|
660
|
+
// consumerAccount
|
|
661
|
+
// )
|
|
662
|
+
// console.log('providerInitializeComputeResults = ', providerInitializeComputeResults)
|
|
663
|
+
//
|
|
664
|
+
//
|
|
665
|
+
// assert(!('error' in providerInitializeComputeResults), 'Cannot order algorithm')
|
|
666
|
+
//
|
|
667
|
+
//
|
|
668
|
+
// algo.transferTxId = await handleOrder(
|
|
669
|
+
// providerInitializeComputeResults.algorithm,
|
|
670
|
+
// resolvedAlgorithmDdo.services[0].datatokenAddress,
|
|
671
|
+
// consumerAccount,
|
|
672
|
+
// computeEnv.consumerAddress,
|
|
673
|
+
// 0
|
|
674
|
+
// )
|
|
675
|
+
// for (let i = 0; i < providerInitializeComputeResults.datasets.length; i++) {
|
|
676
|
+
// assets[i].transferTxId = await handleOrder(
|
|
677
|
+
// providerInitializeComputeResults.datasets[i],
|
|
678
|
+
// dtAddressArray[i],
|
|
679
|
+
// consumerAccount,
|
|
680
|
+
// computeEnv.consumerAddress,
|
|
681
|
+
// 0
|
|
682
|
+
// )
|
|
683
|
+
// }
|
|
643
684
|
-->
|
|
644
|
-
```Typescript
|
|
645
|
-
algo.transferTxId = await handleOrder(
|
|
646
|
-
providerInitializeComputeResults.algorithm,
|
|
647
|
-
resolvedAlgorithmDdo.services[0].datatokenAddress,
|
|
648
|
-
consumerAccount,
|
|
649
|
-
computeEnv.consumerAddress,
|
|
650
|
-
0
|
|
651
|
-
)
|
|
652
|
-
for (let i = 0; i < providerInitializeComputeResults.datasets.length; i++) {
|
|
653
|
-
assets[i].transferTxId = await handleOrder(
|
|
654
|
-
providerInitializeComputeResults.datasets[i],
|
|
655
|
-
dtAddressArray[i],
|
|
656
|
-
consumerAccount,
|
|
657
|
-
computeEnv.consumerAddress,
|
|
658
|
-
0
|
|
659
|
-
)
|
|
660
|
-
}
|
|
661
685
|
|
|
686
|
+
Let's start the free compute job
|
|
687
|
+
```Typescript
|
|
662
688
|
const computeJobs = await ProviderInstance.freeComputeStart(
|
|
663
689
|
providerUrl,
|
|
664
690
|
consumerAccount,
|
|
@@ -666,16 +692,19 @@ let's check the free compute environment
|
|
|
666
692
|
assets,
|
|
667
693
|
algo
|
|
668
694
|
)
|
|
669
|
-
|
|
670
695
|
```
|
|
696
|
+
|
|
671
697
|
<!--
|
|
672
698
|
assert(computeJobs, 'Cannot start compute job')
|
|
673
699
|
-->
|
|
700
|
+
|
|
674
701
|
Let's save the compute job it, we re going to use later
|
|
675
702
|
```Typescript
|
|
676
703
|
computeJobId = computeJobs[0].jobId
|
|
677
704
|
// eslint-disable-next-line prefer-destructuring
|
|
678
705
|
agreementId = computeJobs[0].agreementId
|
|
706
|
+
```
|
|
707
|
+
<!--
|
|
679
708
|
} else {
|
|
680
709
|
assert(
|
|
681
710
|
computeRoutePath === null,
|
|
@@ -683,17 +712,19 @@ let's check the free compute environment
|
|
|
683
712
|
)
|
|
684
713
|
hasFreeComputeSupport = false
|
|
685
714
|
}
|
|
686
|
-
|
|
687
|
-
|
|
715
|
+
}).timeout(40000)
|
|
716
|
+
-->
|
|
688
717
|
|
|
689
718
|
## 11. Check compute status and get download compute results URL
|
|
690
719
|
### 11.1 Check compute status
|
|
720
|
+
<!--
|
|
691
721
|
if (!hasFreeComputeSupport) {
|
|
692
722
|
assert(
|
|
693
723
|
computeRoutePath === null,
|
|
694
724
|
'Compute route path for free compute is not defined (perhaps because provider does not support it yet?)'
|
|
695
725
|
)
|
|
696
726
|
} else {
|
|
727
|
+
-->
|
|
697
728
|
You can also add various delays so you see the various states of the compute job
|
|
698
729
|
```Typescript
|
|
699
730
|
const jobStatus = await ProviderInstance.computeStatus(
|
|
@@ -709,17 +740,22 @@ let's check the free compute environment
|
|
|
709
740
|
Now, let's see the current status of the previously started computer job
|
|
710
741
|
```Typescript
|
|
711
742
|
console.log('Current status of the compute job: ', jobStatus)
|
|
743
|
+
```
|
|
744
|
+
<!--
|
|
712
745
|
}
|
|
713
|
-
|
|
714
|
-
|
|
746
|
+
}).timeout(40000)
|
|
747
|
+
-->
|
|
715
748
|
|
|
716
749
|
### 11.2 Get download compute results URL
|
|
750
|
+
<!--
|
|
717
751
|
if (!hasFreeComputeSupport) {
|
|
718
752
|
assert(
|
|
719
753
|
computeRoutePath === null,
|
|
720
754
|
'Compute route path for free compute is not defined (perhaps because provider does not support it yet?)'
|
|
721
755
|
)
|
|
722
756
|
} else {
|
|
757
|
+
-->
|
|
758
|
+
|
|
723
759
|
```Typescript
|
|
724
760
|
await sleep(10000)
|
|
725
761
|
const downloadURL = await ProviderInstance.getComputeResultUrl(
|
|
@@ -735,10 +771,12 @@ let's check the free compute environment
|
|
|
735
771
|
Let's check the compute results url for the specified index
|
|
736
772
|
```Typescript
|
|
737
773
|
console.log(`Compute results URL: ${downloadURL}`)
|
|
774
|
+
```
|
|
775
|
+
<!--
|
|
738
776
|
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
777
|
+
}).timeout(40000)
|
|
778
|
+
})
|
|
779
|
+
-->
|
|
742
780
|
|
|
743
781
|
## Editing this file
|
|
744
782
|
Please note that ComputeExamples.md is an autogenerated file, you should not edit it directly.
|