Skip to content

Commit

Permalink
cli: add a --network option for the actions approve command
Browse files Browse the repository at this point in the history
  • Loading branch information
tilacog committed Sep 25, 2023
1 parent 9e3c4e0 commit 9b7568a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/indexer-cli/src/commands/indexer/actions/approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ import {
fixParameters,
printObjectOrArray,
parseOutputFormat,
extractProtocolNetworkOption,
} from '../../../command-helpers'
import { approveActions, fetchActions } from '../../../actions'
import { ActionStatus, resolveChainAlias } from '@graphprotocol/indexer-common'

const HELP = `
${chalk.bold('graph indexer actions approve')} [options] [<actionID1> ...]
${chalk.bold('graph indexer actions approve')} [options] queued
${chalk.bold('graph indexer actions approve')} [options] queued --network <networkName>
${chalk.dim('Options:')}
-h, --help Show usage information
-n, --network <STRING> Filter action selection by their protocol network (mainnet, arbitrum-one, goerli, arbitrum-goerli)
-o, --output table|json|yaml Choose the output format: table (default), JSON, or YAML
`

Expand Down Expand Up @@ -45,6 +47,7 @@ module.exports = {
return
}

const protocolNetwork = extractProtocolNetworkOption(parameters.options)
let numericActionIDs: number[]

const config = loadValidatedConfig()
Expand All @@ -56,12 +59,19 @@ module.exports = {

// If actionIDs is 'queued', then populate actionIDs with actions that are queued
if (actionIDs.join() == 'queued') {
if (!protocolNetwork) {
throw new Error(
`Missing required option for approving queued actions: --network`,
)
}
const queuedActions = await fetchActions(client, {
status: ActionStatus.QUEUED,
protocolNetwork,
})

numericActionIDs = queuedActions.map(action => action.id)
if (numericActionIDs.length === 0) {
throw Error(`No 'queued' actions found`)
throw Error(`No 'queued' actions found for network '${protocolNetwork}'`)
}
} else {
numericActionIDs = actionIDs.map(action => +action)
Expand Down

0 comments on commit 9b7568a

Please sign in to comment.