-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcommands.ts
234 lines (210 loc) · 5.79 KB
/
commands.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
import { ValidateParams } from '../components/httpRoutes/validateCommands.js'
import { DDO } from './DDO/DDO'
import { P2PCommandResponse } from './OceanNode'
import type { ComputeAsset, ComputeAlgorithm, ComputeOutput } from './C2D/C2D.js'
import {
ArweaveFileObject,
FileObjectType,
EncryptMethod,
IpfsFileObject,
UrlFileObject,
BaseFileObject
} from './fileObject'
export interface Command {
command: string // command name
node?: string // if not present it means current node
}
export interface AdminCommand extends Command {
expiryTimestamp: number
signature: 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
}
export interface FileInfoCommand extends Command {
type?: FileObjectType
did?: string
serviceId?: string
fileIndex?: number
file?: UrlFileObject | ArweaveFileObject | IpfsFileObject
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
}
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 {
blob: string
encoding?: string
encryptionType?: EncryptMethod.AES | EncryptMethod.ECIES
}
export interface EncryptFileCommand extends Command {
encryptionType?: EncryptMethod.AES | EncryptMethod.ECIES
files?: BaseFileObject
rawData?: Buffer
// UrlFileObject | ArweaveFileObject | IpfsFileObject
}
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 AdminCommand {}
export interface AdminReindexTxCommand extends AdminCommand {
chainId: number
txId: string
}
export interface AdminCollectFeesCommand extends AdminCommand {
tokenAddress: string
chainId: number
tokenAmount?: number
destinationAddress: string
}
export interface AdminReindexChainCommand extends AdminCommand {
chainId: number
}
export interface ICommandHandler {
handle(command: Command): Promise<P2PCommandResponse>
validate(command: Command): ValidateParams
}
export interface ComputeGetEnvironmentsCommand extends Command {
chainId?: number
}
export interface ComputeDetails {
env: string // with hash
validUntil: number
}
export interface ComputeInitializeCommand extends Command {
datasets: [ComputeAsset]
algorithm: ComputeAlgorithm
compute: ComputeDetails
consumerAddress: string
}
export interface ComputeStartCommand extends Command {
consumerAddress: string
signature: string
nonce: string
environment: string
algorithm: ComputeAlgorithm
datasets?: ComputeAsset[]
output?: ComputeOutput
}
export interface FreeComputeStartCommand extends Command {
consumerAddress: string
signature: string
nonce: string
algorithm: ComputeAlgorithm
datasets?: ComputeAsset[]
output?: ComputeOutput
}
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
}
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 enum IndexingCommand {
STOP_THREAD = 'start',
START_THREAD = 'stop'
}
export interface StartStopIndexingCommand extends AdminCommand {
chainId?: number
action: IndexingCommand
}
export interface PolicyServerPassthroughCommand extends Command {
policyServerPassthrough?: any
}