Skip to content

Commit

Permalink
cli: Add filtering of action updates by syncing and protocol networks
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
fordN committed Nov 18, 2024
1 parent 40091ff commit 6f5083f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
8 changes: 8 additions & 0 deletions packages/indexer-cli/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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']`,
Expand Down
34 changes: 28 additions & 6 deletions packages/indexer-cli/src/commands/indexer/actions/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -22,7 +27,9 @@ ${chalk.bold('graph indexer actions update')} [options] [<key1> <value1> ...]
${chalk.dim('Options:')}
-h, --help Show usage information
-h, --help Show usage information
-n, --network <networkName> Filter by protocol network (mainnet, arbitrum-one, sepolia, arbitrum-sepolia)
-s, --syncing <networkName> Filter by the syncing network (see https://thegraph.com/networks/ for supported networks)
--id <actionID> Filter by actionID
--type allocate|unallocate|reallocate Filter by type
--status queued|approved|pending|success|failed|canceled Filter by status
Expand All @@ -47,13 +54,18 @@ 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) {
inputSpinner.stopAndPersist({ symbol: '💁', text: HELP })
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']`,
Expand All @@ -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) {
Expand Down Expand Up @@ -104,6 +124,7 @@ module.exports = {
'id',
'type',
'protocolNetwork',
'syncingNetwork',
'deploymentID',
'allocationID',
'amount',
Expand All @@ -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) {
Expand Down

0 comments on commit 6f5083f

Please sign in to comment.