From 6f5083ff7c46a4f44b4f9599d3a5a6c7d4e7eb30 Mon Sep 17 00:00:00 2001 From: Ford Date: Mon, 18 Nov 2024 14:41:09 -0800 Subject: [PATCH] cli: Add filtering of action updates by syncing and protocol networks - Add optional --network and --syncing options to `indexer actions update ...` so user can filter the actions to be updated by protocol network or syncing network. --- packages/indexer-cli/src/actions.ts | 8 +++++ .../src/commands/indexer/actions/update.ts | 34 +++++++++++++++---- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/packages/indexer-cli/src/actions.ts b/packages/indexer-cli/src/actions.ts index c70e42d90..97fb2ec23 100644 --- a/packages/indexer-cli/src/actions.ts +++ b/packages/indexer-cli/src/actions.ts @@ -145,6 +145,8 @@ export function buildActionFilter( status: string | undefined, source: string | undefined, reason: string | undefined, + protocolNetwork: string | undefined, + syncingNetwork: string | undefined, ): ActionFilter { const filter: ActionFilter = {} if (id) { @@ -162,6 +164,12 @@ export function buildActionFilter( if (reason) { filter.reason = reason } + if (protocolNetwork) { + filter.protocolNetwork = protocolNetwork + } + if (syncingNetwork) { + filter.syncingNetwork = syncingNetwork + } if (Object.keys(filter).length === 0) { throw Error( `No action filter provided, please specify at least one filter using ['--id', '--type', '--status', '--source', '--reason']`, diff --git a/packages/indexer-cli/src/commands/indexer/actions/update.ts b/packages/indexer-cli/src/commands/indexer/actions/update.ts index 6ea470cac..9c1307ddd 100644 --- a/packages/indexer-cli/src/commands/indexer/actions/update.ts +++ b/packages/indexer-cli/src/commands/indexer/actions/update.ts @@ -9,7 +9,12 @@ import { } from '@graphprotocol/indexer-common' import { loadValidatedConfig } from '../../../config' import { createIndexerManagementClient } from '../../../client' -import { fixParameters, printObjectOrArray } from '../../../command-helpers' +import { + extractProtocolNetworkOption, + extractSyncingNetworkOption, + fixParameters, + printObjectOrArray, +} from '../../../command-helpers' import { buildActionFilter, parseActionUpdateInput, @@ -22,7 +27,9 @@ ${chalk.bold('graph indexer actions update')} [options] [ ...] ${chalk.dim('Options:')} - -h, --help Show usage information + -h, --help Show usage information + -n, --network Filter by protocol network (mainnet, arbitrum-one, sepolia, arbitrum-sepolia) + -s, --syncing Filter by the syncing network (see https://thegraph.com/networks/ for supported networks) --id Filter by actionID --type allocate|unallocate|reallocate Filter by type --status queued|approved|pending|success|failed|canceled Filter by status @@ -47,6 +54,8 @@ module.exports = { let actionFilter: ActionFilter = {} const outputFormat = o || output || 'table' + let protocolNetwork: string | undefined = undefined + let syncingNetwork: string | undefined = undefined // eslint-disable-next-line @typescript-eslint/no-explicit-any if (help || h) { @@ -54,6 +63,9 @@ module.exports = { return } try { + protocolNetwork = extractProtocolNetworkOption(parameters.options) + + syncingNetwork = extractSyncingNetworkOption(parameters.options) if (!['json', 'yaml', 'table'].includes(outputFormat)) { throw Error( `Invalid output format "${outputFormat}" must be one of ['json', 'yaml' or 'table']`, @@ -74,7 +86,15 @@ module.exports = { ...Object.fromEntries([...partition(2, 2, kvs)]), }) - actionFilter = buildActionFilter(id, type, status, source, reason) + actionFilter = buildActionFilter( + id, + type, + status, + source, + reason, + protocolNetwork, + syncingNetwork, + ) inputSpinner.succeed('Processed input parameters') } catch (error) { @@ -104,6 +124,7 @@ module.exports = { 'id', 'type', 'protocolNetwork', + 'syncingNetwork', 'deploymentID', 'allocationID', 'amount', @@ -118,9 +139,10 @@ module.exports = { ] // Format Actions 'protocolNetwork' field to display human-friendly chain aliases instead of CAIP2-IDs - actionsUpdated.forEach( - action => (action.protocolNetwork = resolveChainAlias(action.protocolNetwork)), - ) + actionsUpdated.forEach(action => { + action.protocolNetwork = resolveChainAlias(action.protocolNetwork) + action.syncingNetwork = resolveChainAlias(action.syncingNetwork) + }) printObjectOrArray(print, outputFormat, actionsUpdated, displayProperties) } catch (error) {