-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathcommands.ts
More file actions
316 lines (282 loc) · 8.37 KB
/
commands.ts
File metadata and controls
316 lines (282 loc) · 8.37 KB
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
import { ValidateParams } from '../components/httpRoutes/validateCommands.js'
import { P2PCommandResponse } from './OceanNode'
import { DDO } from '@oceanprotocol/ddo-js'
import type {
ComputeAsset,
ComputeAlgorithm,
ComputeResourceRequest,
DBComputeJobMetadata
} from './C2D/C2D.js'
import { FileObjectType, StorageObject, EncryptMethod } from './fileObject'
export interface Command {
command: string // command name
node?: string // if not present it means current node
authorization?: string
caller?: string | string[] // added by our node for rate limiting
}
export interface GetP2PPeerCommand extends Command {
peerId: string
}
export interface FindPeerCommand extends Command {
peerId: string
timeout?: string
}
export interface GetP2PPeersCommand extends Command {}
export interface GetP2PNetworkStatsCommand extends Command {}
export interface SignedCommand extends Command {
nonce: string
signature: string
address: string
}
export interface AdminCollectFeesHandlerResponse {
tx: string
message: string
}
export interface DownloadURLCommand extends Command {
fileObject: any
aes_encrypted_key?: string // if not present it means download without encryption
}
export interface DownloadCommand extends Command {
fileIndex: number
documentId: string
serviceId: string
transferTxId: string
nonce: string
consumerAddress: string
signature: string
aes_encrypted_key?: string // if not present it means download without encryption
policyServer?: any // object to pass to policy server
userData?: Record<string, any>
}
export interface FileInfoCommand extends Command {
type?: FileObjectType
did?: string
serviceId?: string
fileIndex?: number
file?: StorageObject
checksum?: boolean
}
// group these 2
export interface DDOCommand extends Command {
id: string
}
export interface GetDdoCommand extends DDOCommand {}
export interface FindDDOCommand extends DDOCommand {
force?: boolean
}
// this one gets the raw ddo
// https://github.com/oceanprotocol/ocean-node/issues/47
export interface ValidateDDOCommand extends Command {
ddo: DDO
publisherAddress?: string
nonce?: string
signature?: string
message?: string
policyServer?: any // object to pass to policy server
}
export interface StatusCommand extends Command {
detailed?: boolean
}
export interface DetailedStatusCommand extends StatusCommand {}
export interface EchoCommand extends Command {}
export interface QueryCommand extends Command {
query: Record<string, any>
maxResultsPerPage?: number
pageNumber?: number
}
export interface ReindexCommand extends Command {
txId: string
chainId: number
eventIndex?: number
}
export interface DecryptDDOCommand extends Command {
decrypterAddress: string
chainId: number
transactionId?: string
dataNftAddress?: string
encryptedDocument?: string
flags?: number
documentHash?: string
nonce: string
signature: string
}
export interface EncryptCommand extends Command {
nonce: string
consumerAddress: string
signature: string
blob: string
encoding?: string
encryptionType?: EncryptMethod.AES | EncryptMethod.ECIES
policyServer?: any // object to pass to policy server
}
export interface EncryptFileCommand extends Command {
nonce: string
consumerAddress: string
signature: string
encryptionType?: EncryptMethod.AES | EncryptMethod.ECIES
files?: StorageObject
rawData?: Buffer
policyServer?: any // object to pass to policy server
}
export interface NonceCommand extends Command {
address: string // consumer address
}
export interface GetFeesCommand extends Command {
ddoId: string
serviceId: string
consumerAddress?: string
validUntil?: number // this allows a user to request a fee that is valid only for a limited period of time, less than service.timeout
policyServer?: any // object to pass to policyServer
}
// admin commands
export interface AdminStopNodeCommand extends SignedCommand {}
export interface AdminReindexTxCommand extends SignedCommand {
chainId: number
txId: string
}
export interface AdminCollectFeesCommand extends SignedCommand {
tokenAddress: string
chainId: number
tokenAmount?: number
destinationAddress: string
}
export interface AdminReindexChainCommand extends SignedCommand {
chainId: number
block?: number
}
export interface AdminFetchConfigCommand extends SignedCommand {}
export interface AdminPushConfigCommand extends SignedCommand {
config: Record<string, any>
}
export interface AdminGetLogsCommand extends SignedCommand {
logId?: string
startTime?: string
endTime?: string
maxLogs?: number
moduleName?: string
level?: string
page?: number
}
/* eslint-disable no-unused-vars */
export enum IndexingCommand {
STOP_THREAD = 'STOP_THREAD',
START_THREAD = 'START_THREAD'
}
export interface StartStopIndexingCommand extends SignedCommand {
chainId?: number
action: IndexingCommand
}
export interface ICommandHandler {
handle(command: Command): Promise<P2PCommandResponse>
verifyParamsAndRateLimits(task: Command): Promise<P2PCommandResponse>
}
export interface IValidateCommandHandler extends ICommandHandler {
validate(command: Command): ValidateParams
}
export interface IValidateAdminCommandHandler extends ICommandHandler {
validate(command: SignedCommand): Promise<ValidateParams>
}
export interface ComputeGetEnvironmentsCommand extends Command {
chainId?: number
}
export interface ComputePayment {
chainId: number
token: string
resources?: ComputeResourceRequest[] // only used in initializeCompute
}
export interface ComputeInitializeCommand extends Command {
datasets: ComputeAsset[]
algorithm: ComputeAlgorithm
environment: string
payment: ComputePayment
consumerAddress: string
signature?: string
maxJobDuration: number
policyServer?: any // object to pass to policy server
queueMaxWaitTime?: number // max time in seconds a job can wait in the queue before being started
encryptedDockerRegistryAuth?: string
output?: string // this is always an ECIES encrypted string, that decodes to ComputeOutput interface
}
export interface FreeComputeStartCommand extends Command {
consumerAddress: string
signature: string
nonce: string
environment: string
algorithm: ComputeAlgorithm
datasets?: ComputeAsset[]
output?: string // this is always an ECIES encrypted string, that decodes to ComputeOutput interface
resources?: ComputeResourceRequest[]
maxJobDuration?: number
policyServer?: any // object to pass to policy server
metadata?: DBComputeJobMetadata
additionalViewers?: string[] // addresses of additional addresses that can get results
queueMaxWaitTime?: number // max time in seconds a job can wait in the queue before being started
encryptedDockerRegistryAuth?: string
}
export interface PaidComputeStartCommand extends FreeComputeStartCommand {
payment: ComputePayment
}
export interface ComputeStopCommand extends Command {
consumerAddress: string
signature: string
nonce: string
jobId: string
agreementId?: string
}
export interface ComputeGetResultCommand extends Command {
consumerAddress: string
signature: string
nonce: string
jobId: string
index: number
offset?: number
}
export interface ComputeGetStreamableLogsCommand extends Command {
consumerAddress: string
signature: string
nonce: string
jobId: string
}
export interface ComputeGetStatusCommand extends Command {
consumerAddress?: string
jobId?: string
agreementId?: string
}
export interface ValidateChainId {
validation: boolean
networkRpc: string
}
/* eslint-disable no-unused-vars */
export enum CommandStatus {
DELIVERED = 'DELIVERED', // command was delivered successfully
PENDING = 'PENDING', // command is pending excution or still running
FAILURE = 'FAILURE', // command execution failed
SUCCESS = 'SUCCESS' // command execution succeeded
}
export interface JobStatus {
command: string
timestamp: string
jobId: string
status: CommandStatus
hash: string
}
export interface PolicyServerPassthroughCommand extends Command {
policyServerPassthrough?: any
}
export interface PolicyServerInitializeCommand extends Command {
documentId?: string
serviceId?: string
consumerAddress?: string
policyServer?: any
}
export interface CreateAuthTokenCommand extends Command {
address: string
signature: string
validUntil?: number | null
}
export interface GetJobsCommand extends Command {
environments?: string[]
fromTimestamp?: string
consumerAddrs?: string[]
runningJobs?: boolean
}