@sentio/cli 4.0.1-rc.2 → 4.0.1-rc.4

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.
@@ -1,4 +1,15 @@
1
- import { ProcessorExtService, ProcessorService } from '@sentio/api'
1
+ import { ProcessorService, ProcessorServiceExt } from '@sentio/api'
2
+ import {
3
+ ActivatePendingRequestSchema,
4
+ GetProcessorStatusRequestV2Schema,
5
+ GetProcessorStatusResponseSchema
6
+ } from '@sentio/api/gen/service/processor/protos/processor_service_pb.js'
7
+ import {
8
+ GetProcessorSourceFilesRequestSchema,
9
+ GetProcessorSourceFilesResponseSchema
10
+ } from '@sentio/api/gen/service/processor/ext_protos/processor_service_ext_pb.js'
11
+ import { fromJson, toJson } from '@bufbuild/protobuf'
12
+ import { EmptySchema } from '@bufbuild/protobuf/wkt'
2
13
  import { Command, InvalidArgumentError } from '@commander-js/extra-typings'
3
14
  import chalk from 'chalk'
4
15
  import process from 'process'
@@ -6,9 +17,9 @@ import yaml from 'yaml'
6
17
  import {
7
18
  CliError,
8
19
  createApiContext,
20
+ getServiceClient,
9
21
  handleCommandError,
10
22
  resolveProjectRef,
11
- unwrapApiResult,
12
23
  postApiJson,
13
24
  putApiJson
14
25
  } from '../api.js'
@@ -181,34 +192,30 @@ async function runProcessorStatus(options: ProcessorStatusOptions) {
181
192
  const project = await resolveProjectRef(options, context, { ownerSlug: true })
182
193
  const requestedVersion = normalizeVersionSelector(options.version)
183
194
  const apiVersion = typeof requestedVersion === 'number' ? 'ALL' : (requestedVersion ?? 'ALL')
184
- const response = await ProcessorService.getProcessorStatusV2({
185
- path: {
186
- owner: project.owner,
187
- slug: project.slug
188
- },
189
- query: {
195
+ const client = getServiceClient(ProcessorService, context)
196
+ const res = await client.getProcessorStatusV2(
197
+ fromJson(GetProcessorStatusRequestV2Schema, {
198
+ projectOwner: project.owner,
199
+ projectSlug: project.slug,
190
200
  version: apiVersion
191
- },
192
- headers: context.headers
193
- })
194
- const data = unwrapApiResult(response)
201
+ })
202
+ )
203
+ const data = toJson(GetProcessorStatusResponseSchema, res)
195
204
  printOutput(options, shapeProcessorStatusOutput(data, requestedVersion))
196
205
  }
197
206
 
198
207
  async function runProcessorSource(options: ProcessorSourceOptions) {
199
208
  const context = createApiContext(options)
200
209
  const project = await resolveProjectRef(options, context, { ownerSlug: true })
201
- const response = await ProcessorExtService.getProcessorSourceFiles({
202
- path: {
203
- owner: project.owner,
204
- slug: project.slug
205
- },
206
- query: {
207
- version: options.version
208
- },
209
- headers: context.headers
210
- })
211
- const data = unwrapApiResult(response)
210
+ const client = getServiceClient(ProcessorServiceExt, context)
211
+ const res = await client.getProcessorSourceFiles(
212
+ fromJson(GetProcessorSourceFilesRequestSchema, {
213
+ projectOwner: project.owner,
214
+ projectSlug: project.slug,
215
+ ...(options.version !== undefined ? { version: options.version } : {})
216
+ })
217
+ )
218
+ const data = toJson(GetProcessorSourceFilesResponseSchema, res)
212
219
  if (options.path && Array.isArray(data.sourceFiles)) {
213
220
  const sourceFile = data.sourceFiles.find((entry) => entry.path === options.path)
214
221
  if (!sourceFile) {
@@ -224,15 +231,15 @@ async function runActivatePending(options: ProcessorOptions & { yes?: boolean })
224
231
  const context = createApiContext(options)
225
232
  const project = await resolveProjectRef(options, context, { ownerSlug: true })
226
233
 
227
- const statusResponse = await ProcessorService.getProcessorStatusV2({
228
- path: {
229
- owner: project.owner,
230
- slug: project.slug
231
- },
232
- query: { version: 'ALL' },
233
- headers: context.headers
234
- })
235
- const data = unwrapApiResult(statusResponse)
234
+ const client = getServiceClient(ProcessorService, context)
235
+ const statusResponse = await client.getProcessorStatusV2(
236
+ fromJson(GetProcessorStatusRequestV2Schema, {
237
+ projectOwner: project.owner,
238
+ projectSlug: project.slug,
239
+ version: 'ALL'
240
+ })
241
+ )
242
+ const data = toJson(GetProcessorStatusResponseSchema, statusResponse)
236
243
  const processors = Array.isArray(data.processors) ? data.processors : []
237
244
 
238
245
  const activeProcessor = processors.find((p) => asString(p.versionState) === 'ACTIVE')
@@ -255,16 +262,15 @@ async function runActivatePending(options: ProcessorOptions & { yes?: boolean })
255
262
  }
256
263
  }
257
264
 
258
- const response = await ProcessorService.activatePendingVersion({
259
- path: {
260
- owner: project.owner,
261
- slug: project.slug
262
- },
263
- headers: context.headers
264
- })
265
+ const response = await client.activatePendingVersion(
266
+ fromJson(ActivatePendingRequestSchema, {
267
+ projectOwner: project.owner,
268
+ projectSlug: project.slug
269
+ })
270
+ )
265
271
  printOutput(options, {
266
272
  project: `${project.owner}/${project.slug}`,
267
- ...(unwrapApiResult(response) as Record<string, unknown>)
273
+ ...(toJson(EmptySchema, response) as Record<string, unknown>)
268
274
  })
269
275
  }
270
276
 
@@ -279,15 +285,15 @@ async function resolveAndConfirmProcessor(
279
285
 
280
286
  if (!resolvedProcessorId) {
281
287
  const project = await resolveProjectRef(options, context, { ownerSlug: true })
282
- const statusResponse = await ProcessorService.getProcessorStatusV2({
283
- path: {
284
- owner: project.owner,
285
- slug: project.slug
286
- },
287
- query: { version: 'ACTIVE' },
288
- headers: context.headers
289
- })
290
- const data = unwrapApiResult(statusResponse)
288
+ const client = getServiceClient(ProcessorService, context)
289
+ const statusResponse = await client.getProcessorStatusV2(
290
+ fromJson(GetProcessorStatusRequestV2Schema, {
291
+ projectOwner: project.owner,
292
+ projectSlug: project.slug,
293
+ version: 'ACTIVE'
294
+ })
295
+ )
296
+ const data = toJson(GetProcessorStatusResponseSchema, statusResponse)
291
297
  const processors = Array.isArray(data.processors) ? data.processors : []
292
298
  const activeProcessor = processors.find((p) => asString(p.versionState) === 'ACTIVE')
293
299
 
@@ -354,12 +360,15 @@ async function resolveProcessorId(processorId: string | undefined, options: Proc
354
360
  if (processorId) return processorId
355
361
  const context = createApiContext(options)
356
362
  const project = await resolveProjectRef(options, context, { ownerSlug: true })
357
- const statusResponse = await ProcessorService.getProcessorStatusV2({
358
- path: { owner: project.owner, slug: project.slug },
359
- query: { version: 'ACTIVE' },
360
- headers: context.headers
361
- })
362
- const data = unwrapApiResult(statusResponse)
363
+ const client = getServiceClient(ProcessorService, context)
364
+ const statusResponse = await client.getProcessorStatusV2(
365
+ fromJson(GetProcessorStatusRequestV2Schema, {
366
+ projectOwner: project.owner,
367
+ projectSlug: project.slug,
368
+ version: 'ACTIVE'
369
+ })
370
+ )
371
+ const data = toJson(GetProcessorStatusResponseSchema, statusResponse)
363
372
  const processors = Array.isArray(data.processors) ? data.processors : []
364
373
  const activeProcessor = processors.find((p) => asString(p.versionState) === 'ACTIVE')
365
374
  if (!activeProcessor || !activeProcessor.processorId) {
@@ -1,14 +1,30 @@
1
1
  import { Command, InvalidArgumentError } from '@commander-js/extra-typings'
2
2
  import process from 'process'
3
3
  import yaml from 'yaml'
4
- import { DebugAndSimulationService } from '@sentio/api'
4
+ import { SolidityAPIService } from '@sentio/api'
5
+ import {
6
+ GetSimulationBundleInProjectRequestSchema,
7
+ GetSimulationInProjectRequestSchema,
8
+ GetSimulationsInProjectRequestSchema,
9
+ SimulateTransactionBundleInProjectRequestSchema,
10
+ SimulateTransactionInProjectRequestSchema
11
+ } from '@sentio/api/gen/service/solidity/protos/solidity_api_service_pb.js'
12
+ import {
13
+ GetSimulationBundleResponseSchema,
14
+ GetSimulationResponseSchema,
15
+ GetSimulationsResponseSchema,
16
+ SimulateTransactionBundleResponseSchema,
17
+ SimulateTransactionResponseSchema
18
+ } from '@sentio/api/gen/service/solidity/protos/solidity_service_pb.js'
19
+ import { fromJson, toJson } from '@bufbuild/protobuf'
5
20
  import {
6
21
  CliError,
7
22
  createApiContext,
23
+ fetchApiJson,
24
+ getServiceClient,
8
25
  handleCommandError,
9
26
  loadJsonInput,
10
- resolveProjectRef,
11
- unwrapApiResult
27
+ resolveProjectRef
12
28
  } from '../api.js'
13
29
 
14
30
  interface SimulationOptions {
@@ -213,47 +229,45 @@ function createSimulationTraceByTxCommand() {
213
229
  async function runSimulationList(options: SimulationListOptions) {
214
230
  const context = createApiContext(options)
215
231
  const project = await resolveProjectRef(options, context, { ownerSlug: true })
216
- const response = await DebugAndSimulationService.getSimulations({
217
- path: {
218
- owner: project.owner,
219
- slug: project.slug
220
- },
221
- query: {
222
- labelContains: options.labelContains,
223
- page: options.page,
224
- pageSize: options.pageSize
225
- },
226
- headers: context.headers
227
- })
228
- printOutput(options, unwrapApiResult(response))
232
+ const client = getServiceClient(SolidityAPIService, context)
233
+ const res = await client.getSimulations(
234
+ fromJson(GetSimulationsInProjectRequestSchema, {
235
+ projectOwner: project.owner,
236
+ projectSlug: project.slug,
237
+ ...(options.labelContains !== undefined ? { labelContains: options.labelContains } : {}),
238
+ ...(options.page !== undefined ? { page: options.page } : {}),
239
+ ...(options.pageSize !== undefined ? { pageSize: options.pageSize } : {})
240
+ })
241
+ )
242
+ printOutput(options, toJson(GetSimulationsResponseSchema, res))
229
243
  }
230
244
 
231
245
  async function runSimulationGet(simulationId: string, options: SimulationOptions) {
232
246
  const context = createApiContext(options)
233
247
  const project = await resolveProjectRef(options, context, { ownerSlug: true })
234
- const response = await DebugAndSimulationService.getSimulation({
235
- path: {
236
- owner: project.owner,
237
- slug: project.slug,
248
+ const client = getServiceClient(SolidityAPIService, context)
249
+ const res = await client.getSimulation(
250
+ fromJson(GetSimulationInProjectRequestSchema, {
251
+ projectOwner: project.owner,
252
+ projectSlug: project.slug,
238
253
  simulationId
239
- },
240
- headers: context.headers
241
- })
242
- printOutput(options, unwrapApiResult(response))
254
+ })
255
+ )
256
+ printOutput(options, toJson(GetSimulationResponseSchema, res))
243
257
  }
244
258
 
245
259
  async function runSimulationBundleGet(bundleId: string, options: SimulationOptions) {
246
260
  const context = createApiContext(options)
247
261
  const project = await resolveProjectRef(options, context, { ownerSlug: true })
248
- const response = await DebugAndSimulationService.getSimulationBundleInProject({
249
- path: {
250
- owner: project.owner,
251
- slug: project.slug,
262
+ const client = getServiceClient(SolidityAPIService, context)
263
+ const res = await client.getSimulationBundleInProject(
264
+ fromJson(GetSimulationBundleInProjectRequestSchema, {
265
+ projectOwner: project.owner,
266
+ projectSlug: project.slug,
252
267
  bundleId
253
- },
254
- headers: context.headers
255
- })
256
- printOutput(options, unwrapApiResult(response))
268
+ })
269
+ )
270
+ printOutput(options, toJson(GetSimulationBundleResponseSchema, res))
257
271
  }
258
272
 
259
273
  async function runSimulation(options: SimulationRunOptions) {
@@ -266,16 +280,22 @@ async function runSimulation(options: SimulationRunOptions) {
266
280
  }
267
281
  const context = createApiContext(options)
268
282
  const project = await resolveProjectRef(options, context, { ownerSlug: true })
269
- const response = await DebugAndSimulationService.simulateTransaction({
270
- path: {
271
- owner: project.owner,
272
- slug: project.slug,
273
- chainId: options.chainId
274
- },
275
- body: body as never,
276
- headers: context.headers
277
- })
278
- printOutput(options, unwrapApiResult(response))
283
+ const client = getServiceClient(SolidityAPIService, context)
284
+ // 1.x body was { simulation: Simulation } and chainId rode in the URL path; in
285
+ // 2.x both live on the request message and chainId is a field of the simulation.
286
+ const bodyJson = body as Record<string, unknown>
287
+ const simulation = {
288
+ chainId: options.chainId,
289
+ ...((bodyJson.simulation as Record<string, unknown> | undefined) ?? {})
290
+ }
291
+ const res = await client.simulateTransaction(
292
+ fromJson(SimulateTransactionInProjectRequestSchema, {
293
+ projectOwner: project.owner,
294
+ projectSlug: project.slug,
295
+ simulation
296
+ })
297
+ )
298
+ printOutput(options, toJson(SimulateTransactionResponseSchema, res))
279
299
  }
280
300
 
281
301
  async function runSimulationBundle(options: SimulationRunOptions) {
@@ -286,86 +306,66 @@ async function runSimulationBundle(options: SimulationRunOptions) {
286
306
  if (!options.chainId) {
287
307
  throw new CliError('Chain id is required. Use --chain-id <id>.')
288
308
  }
309
+ const chainId = options.chainId
289
310
  const context = createApiContext(options)
290
311
  const project = await resolveProjectRef(options, context, { ownerSlug: true })
291
- const response = await DebugAndSimulationService.simulateTransactionBundle({
292
- path: {
293
- owner: project.owner,
294
- slug: project.slug,
295
- chainId: options.chainId
296
- },
297
- body: body as never,
298
- headers: context.headers
299
- })
300
- printOutput(options, unwrapApiResult(response))
312
+ const client = getServiceClient(SolidityAPIService, context)
313
+ // 1.x body was { simulations: Simulation[] } and chainId rode in the URL path;
314
+ // in 2.x both live on the request message and chainId is a field of each simulation.
315
+ const bodyJson = body as Record<string, unknown>
316
+ const inputSimulations = Array.isArray(bodyJson.simulations)
317
+ ? (bodyJson.simulations as Array<Record<string, unknown>>)
318
+ : []
319
+ const simulations = inputSimulations.map((simulation) => ({
320
+ chainId,
321
+ ...simulation
322
+ }))
323
+ const res = await client.simulateTransactionBundle(
324
+ fromJson(SimulateTransactionBundleInProjectRequestSchema, {
325
+ projectOwner: project.owner,
326
+ projectSlug: project.slug,
327
+ simulations
328
+ })
329
+ )
330
+ printOutput(options, toJson(SimulateTransactionBundleResponseSchema, res))
301
331
  }
302
332
 
303
333
  async function runTraceBySimulation(simulationId: string, options: SimulationTraceOptions) {
304
- await runTrace(options, (project, context) =>
305
- DebugAndSimulationService.getCallTraceBySimulation({
306
- path: {
307
- owner: project.owner,
308
- slug: project.slug,
309
- chainId: options.chainId!,
310
- simulationId
311
- },
312
- query: buildTraceQuery(options),
313
- headers: context.headers
314
- })
315
- )
334
+ await runTrace('simulation', simulationId, options)
316
335
  }
317
336
 
318
337
  async function runTraceByBundle(bundleId: string, options: SimulationTraceOptions) {
319
- await runTrace(options, (project, context) =>
320
- DebugAndSimulationService.getCallTraceByBundle({
321
- path: {
322
- owner: project.owner,
323
- slug: project.slug,
324
- chainId: options.chainId!,
325
- bundleId
326
- },
327
- query: buildTraceQuery(options),
328
- headers: context.headers
329
- })
330
- )
338
+ await runTrace('bundle', bundleId, options)
331
339
  }
332
340
 
333
341
  async function runTraceByTransaction(txHash: string, options: SimulationTraceOptions) {
334
- await runTrace(options, (project, context) =>
335
- DebugAndSimulationService.getCallTraceByTransaction({
336
- path: {
337
- owner: project.owner,
338
- slug: project.slug,
339
- chainId: options.chainId!,
340
- txHash
341
- },
342
- query: buildTraceQuery(options),
343
- headers: context.headers
344
- })
345
- )
342
+ await runTrace('transaction', txHash, options)
346
343
  }
347
344
 
345
+ // The call-trace-by-id endpoints are keyed by chainId + the simulation/bundle/tx
346
+ // id, but the 2.x public proto (GetCallTraceInProjectRequest) does not carry those
347
+ // fields. Call the REST gateway route directly — the same dialect the connect
348
+ // client speaks — so the id and chainId can still be forwarded.
348
349
  async function runTrace(
349
- options: SimulationTraceOptions,
350
- operation: (
351
- project: Awaited<ReturnType<typeof resolveProjectRef>>,
352
- context: ReturnType<typeof createApiContext>
353
- ) => Promise<unknown>
350
+ resource: 'simulation' | 'bundle' | 'transaction',
351
+ id: string,
352
+ options: SimulationTraceOptions
354
353
  ) {
355
354
  if (!options.chainId) {
356
355
  throw new CliError('Chain id is required. Use --chain-id <id>.')
357
356
  }
358
357
  const context = createApiContext(options)
359
358
  const project = await resolveProjectRef(options, context, { ownerSlug: true })
360
- const data = unwrapApiResult((await operation(project, context)) as never)
359
+ const path = `/api/v1/solidity/${project.owner}/${project.slug}/${options.chainId}/${resource}/${encodeURIComponent(id)}/call_trace`
360
+ const data = await fetchApiJson<unknown>(path, context, buildTraceQuery(options))
361
361
  printOutput(options, data)
362
362
  }
363
363
 
364
364
  function buildTraceQuery(options: SimulationTraceOptions) {
365
365
  return {
366
- withInternalCalls: options.withInternalCalls,
367
- disableOptimizer: options.disableOptimizer,
368
- ignoreGasCost: options.ignoreGasCost
366
+ ...(options.withInternalCalls !== undefined ? { withInternalCalls: options.withInternalCalls } : {}),
367
+ ...(options.disableOptimizer !== undefined ? { disableOptimizer: options.disableOptimizer } : {}),
368
+ ...(options.ignoreGasCost !== undefined ? { ignoreGasCost: options.ignoreGasCost } : {})
369
369
  }
370
370
  }
371
371