-
Notifications
You must be signed in to change notification settings - Fork 1
/
publish.ts
295 lines (259 loc) · 10.2 KB
/
publish.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
import {
AssetBuilder,
ConsumerParameterBuilder,
CredentialListTypes,
FileTypes,
Nautilus,
ServiceBuilder,
ServiceTypes,
UrlFile
} from '@deltadao/nautilus'
import { NetworkConfig } from 'config'
import { Wallet } from 'ethers'
export async function publishAccessDataset(
nautilus: Nautilus,
networkConfig: NetworkConfig,
pricingConfig: any,
wallet: Wallet
) {
const owner = await wallet.getAddress()
console.log(`publishing AccessDataset...`)
console.log(`Your address is ${owner}`)
const serviceBuilder = new ServiceBuilder({
serviceType: ServiceTypes.ACCESS,
fileType: FileTypes.URL
}) // access type dataset with URL data source
const urlFile: UrlFile = {
type: 'url', // there are multiple supported data source types, see https://docs.oceanprotocol.com/developers/storage
url: 'https://raw.githubusercontent.com/deltaDAO/nautilus-examples/main/example_publish_assets/example-dataset.json', // link to your file or api
method: 'GET' // HTTP request method
// headers: {
// Authorization: 'Basic XXX' // optional headers field e.g. for basic access control
// }
}
const service = serviceBuilder
.setServiceEndpoint(networkConfig.providerUri)
.setTimeout(600) // 10 minutes access to the service (timeout in seconds)
.addFile(urlFile)
.setPricing(pricingConfig.FREE)
.setDatatokenNameAndSymbol('Data Access Token', 'DAT') // important for following access token transactions in the explorer
.build()
const assetBuilder = new AssetBuilder()
const asset = assetBuilder
.setType('dataset')
.setName('Nautilus-Example: Access Dataset Name')
.setDescription('# Nautilus-Example Description \n\nThis asset has been published using the [nautilus-examples](https://github.com/deltaDAO/nautilus-examples) repository.')
.setAuthor('Company Name')
.setLicense('MIT')
.addService(service)
.setOwner(owner)
.addCredentialAddresses(CredentialListTypes.ALLOW, [owner]) // OPTIONAL Configure access control to only allow the owner-address (0xabc...) to access the asset
.build()
const result = await nautilus.publish(asset)
console.log(result)
}
export async function publishComputeDataset(
nautilus: Nautilus,
networkConfig: NetworkConfig,
pricingConfig: any,
wallet: Wallet
) {
const owner = await wallet.getAddress()
console.log(`Your address is ${owner}`)
const consumerParameterBuilder = new ConsumerParameterBuilder() // optional
const cunsumerParameter = consumerParameterBuilder // optional
.setType('number')
.setName('myNumberParam')
.setLabel('My Param Label')
.setDescription('A description of my param for the enduser.')
.setDefault('5')
.setRequired(false)
.build()
const serviceBuilder = new ServiceBuilder({
serviceType: ServiceTypes.COMPUTE,
fileType: FileTypes.URL
}) // compute type dataset with URL data source
const urlFile: UrlFile = {
type: 'url',
url: 'https://raw.githubusercontent.com/deltaDAO/nautilus-examples/main/example_publish_assets/example-dataset.json', // link to your file or api
method: 'GET'
// headers: {
// Authorization: 'Basic XXX' // optional headers field e.g. for basic access control
// }
}
const service = serviceBuilder
.setServiceEndpoint(networkConfig.providerUri)
.setTimeout(60)
.addFile(urlFile)
.setPricing(pricingConfig.FREE)
.setDatatokenNameAndSymbol('My Datatoken Name', 'SYMBOL') // important for following access token transactions in the explorer
.addConsumerParameter(cunsumerParameter) // optional
.build()
const assetBuilder = new AssetBuilder()
const asset = assetBuilder
.setType('dataset')
.setName('Nautilus-Example: Compute Dataset Name')
.setDescription(
'# Nautilus-Example Description \n\nThis asset has been published using the [nautilus-examples](https://github.com/deltaDAO/nautilus-examples) repository.'
)
.setAuthor('Company Name')
.setLicense('MIT')
.addService(service)
.setOwner(owner)
.build()
const result = await nautilus.publish(asset)
console.log(result)
}
export async function publishAccessAlgorithm(
nautilus: Nautilus,
networkConfig: NetworkConfig,
pricingConfig: any,
wallet: Wallet
) {
const owner = await wallet.getAddress()
console.log(`publishing AccessAlgorithm...`)
console.log(`Your address is ${owner}`)
const serviceBuilder = new ServiceBuilder({
serviceType: ServiceTypes.ACCESS,
fileType: FileTypes.URL
})
const urlFile: UrlFile = {
type: 'url',
url: 'https://raw.githubusercontent.com/deltaDAO/nautilus-examples/main/example_publish_assets/count-lines-algorithm.js', // link to your algorithm logic, will be run using the defined conatainer
method: 'GET'
}
const service = serviceBuilder
.setServiceEndpoint(networkConfig.providerUri)
.setTimeout(3600)
.addFile(urlFile)
.setPricing(pricingConfig.FIXED_EUROE)
.setDatatokenNameAndSymbol('Algorithm Access Token', 'AAT')
.build()
const algoMetadata = {
language: 'Node.js',
version: '1.0.0',
container: {
// https://hub.docker.com/layers/library/node/18.17.1/images/sha256-91e37377b960d0b15d3c15d15321084163bc8d950e14f77bbc84ab23cf3d6da7?context=explore
entrypoint: 'node $ALGO',
image: 'node',
tag: '18.17.1',
checksum:
'sha256:91e37377b960d0b15d3c15d15321084163bc8d950e14f77bbc84ab23cf3d6da7'
}
}
const assetBuilder = new AssetBuilder()
const asset = assetBuilder
.setType('algorithm')
.setName('Nautilus-Example: Access Algorithm Name')
.setDescription(
`# Nautilus-Example Description \n\nThis asset has been published using the [nautilus-examples](https://github.com/deltaDAO/nautilus-examples) repository.`
) // supports markdown
.setAuthor('Your Company Name')
.setLicense('MIT')
.setAlgorithm(algoMetadata)
.addService(service)
.setOwner(owner)
.addCredentialAddresses(CredentialListTypes.ALLOW, [owner]) // OPTIONAL Configure access control to only allow the owner-address (0xabc...) to access the asset
.build()
const result = await nautilus.publish(asset)
console.log(result)
}
export async function publishComputeAlgorithm(
nautilus: Nautilus,
networkConfig: NetworkConfig,
pricingConfig: any,
wallet: Wallet
) {
const owner = await wallet.getAddress()
console.log(`Your address is ${owner}`)
const serviceBuilder = new ServiceBuilder({
serviceType: ServiceTypes.COMPUTE,
fileType: FileTypes.URL
})
const urlFile: UrlFile = {
type: 'url',
url: 'https://raw.githubusercontent.com/deltaDAO/nautilus-examples/main/example_publish_assets/count-lines-algorithm.js', // link to your algorithm logic, will be run using the defined conatainer
method: 'GET'
}
const service = serviceBuilder
.setServiceEndpoint(networkConfig.providerUri)
.setTimeout(86400)
.addFile(urlFile)
.setPricing(pricingConfig.FIXED_OCEAN)
.setDatatokenNameAndSymbol('My Datatoken Name', 'SYMBOL')
.build()
const algoMetadata = {
language: 'Node.js',
version: '1.0.0',
container: {
// https://hub.docker.com/layers/library/node/18.17.1/images/sha256-91e37377b960d0b15d3c15d15321084163bc8d950e14f77bbc84ab23cf3d6da7?context=explore
entrypoint: 'node $ALGO',
image: 'node',
tag: '18.17.1',
checksum:
'sha256:91e37377b960d0b15d3c15d15321084163bc8d950e14f77bbc84ab23cf3d6da7'
}
}
const assetBuilder = new AssetBuilder()
const asset = assetBuilder
.setType('algorithm')
.setName('Nautilus-Example: Compute Algorithm Name')
.setDescription(
`# Nautilus-Example Description \n\nThis asset has been published using the [nautilus-examples](https://github.com/deltaDAO/nautilus-examples) repository.`
) // supports markdown
.setAuthor('Your Company Name')
.setLicense('MIT')
.setAlgorithm(algoMetadata)
.addService(service)
.setOwner(owner)
.build()
const result = await nautilus.publish(asset)
console.log(result)
}
export async function publishSaaSOffer(
nautilus: Nautilus,
networkConfig: NetworkConfig,
pricingConfig: any,
wallet: Wallet
) {
const owner = await wallet.getAddress()
console.log(`publishing SaaS Offer...`)
console.log(`Your address is ${owner}`)
const serviceBuilder = new ServiceBuilder({
serviceType: ServiceTypes.ACCESS,
fileType: FileTypes.URL
}) // access type dataset with URL data source
const urlFile: UrlFile = {
type: 'url', // there are multiple supported data source types, see https://docs.oceanprotocol.com/developers/storage
url: 'https://raw.githubusercontent.com/deltaDAO/nautilus-examples/main/example_publish_assets/example-dataset.json', // This is a dummy dataset which needs to be reachable
method: 'GET' // HTTP request method
}
const service = serviceBuilder
.setServiceEndpoint(networkConfig.providerUri)
.setTimeout(3600) // 1 hour access to the service (timeout in seconds)
.addFile(urlFile) // dummy file
.setPricing(pricingConfig.FIXED_EUROE) // use preconfigured pricing for EUROe
.setDatatokenNameAndSymbol('SaaS Access Token', 'SaaS-AT') // important for following access token transactions in the explorer
.build()
const assetBuilder = new AssetBuilder()
const asset = assetBuilder
.setType('dataset') // use 'dataset' for SaaS offerings
.setName('Nautilus-Example: SaaS')
.setDescription(
`# Nautilus-Example Description \n\nThis asset has been published using the [nautilus-examples](https://github.com/deltaDAO/nautilus-examples) repository.`
) // supports markdown
.setAuthor('Company Name')
.setLicense('MIT')
.addAdditionalInformation({
saas: {
redirectUrl: 'https://your-saas-app.com/login', // redirect URL for your SaaS
paymentMode: 'subscription' // payment mode (either 'payperuse' or 'subscription') Subscription is using the timeout from .setTimeout as the subscription period
}
})
.addService(service)
.setOwner(owner)
.addCredentialAddresses(CredentialListTypes.ALLOW, [owner]) // OPTIONAL Configure access control to only allow the owner-address (0xabc...) to access the asset
.build()
const result = await nautilus.publish(asset)
console.log(result)
}