Skip to content

Commit 09898ce

Browse files
committed
feat: allocate and unallocate in action queue
Signed-off-by: Tomás Migone <[email protected]>
1 parent 3d4562b commit 09898ce

File tree

14 files changed

+293
-104
lines changed

14 files changed

+293
-104
lines changed

packages/indexer-agent/src/agent.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ export class Agent {
252252
},
253253
)
254254

255+
// TODO HORIZON: Uncomment this
255256
// this.reconciliationLoop()
256257
return this
257258
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { Logger } from '@graphprotocol/common-ts'
2+
import { DataTypes, QueryInterface } from 'sequelize'
3+
4+
interface MigrationContext {
5+
queryInterface: QueryInterface
6+
logger: Logger
7+
}
8+
9+
interface Context {
10+
context: MigrationContext
11+
}
12+
13+
export async function up({ context }: Context): Promise<void> {
14+
const { queryInterface, logger } = context
15+
16+
logger.debug(`Checking if 'Actions' table exists`)
17+
const tables = await queryInterface.showAllTables()
18+
if (!tables.includes('Actions')) {
19+
logger.info(`Actions table does not exist, migration not necessary`)
20+
return
21+
}
22+
23+
logger.debug(`Checking if 'Actions' table needs to be migrated`)
24+
const table = await queryInterface.describeTable('Actions')
25+
const publicPOI = table.publicPOI
26+
const poiBlockNumber = table.poiBlockNumber
27+
if (publicPOI && poiBlockNumber) {
28+
logger.info(`'publicPOI' and 'poiBlockNumber' columns already exist, migration not necessary`)
29+
return
30+
}
31+
32+
logger.info(`Add 'publicPOI' and 'poiBlockNumber' columns to 'Actions' table`)
33+
await queryInterface.addColumn('Actions', 'publicPOI', {
34+
type: DataTypes.STRING,
35+
allowNull: true,
36+
})
37+
await queryInterface.addColumn('Actions', 'poiBlockNumber', {
38+
type: DataTypes.INTEGER,
39+
allowNull: true,
40+
})
41+
}
42+
43+
export async function down({ context }: Context): Promise<void> {
44+
const { queryInterface, logger } = context
45+
46+
return await queryInterface.sequelize.transaction({}, async transaction => {
47+
const tables = await queryInterface.showAllTables()
48+
49+
if (tables.includes('Actions')) {
50+
logger.info(`Remove 'publicPOI' and 'poiBlockNumber' columns`)
51+
await context.queryInterface.removeColumn('Actions', 'publicPOI', {
52+
transaction,
53+
})
54+
await context.queryInterface.removeColumn('Actions', 'poiBlockNumber', {
55+
transaction,
56+
})
57+
}
58+
})
59+
}

packages/indexer-cli/src/actions.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export async function buildActionInput(
3737
priority: number,
3838
protocolNetwork: string,
3939
): Promise<ActionInput> {
40-
// TODO HORIZON: validate publicPOI and blockNumber for unallocate and reallocate only for horizon allocations
4140
await validateActionInput(type, actionParams)
4241

4342
// TODO HORIZON: we could check isHorizon status here to set the proper value for isLegacy, but it requires multiNetworks
@@ -67,7 +66,7 @@ export async function buildActionInput(
6766
allocationID: actionParams.param1,
6867
poi: poi,
6968
publicPOI: actionParams.param5,
70-
blockNumber: actionParams.param6,
69+
poiBlockNumber: actionParams.param4 ? Number(actionParams.param4) : undefined,
7170
force: actionParams.param3 === 'true',
7271
type,
7372
source,
@@ -88,8 +87,8 @@ export async function buildActionInput(
8887
allocationID: actionParams.param1,
8988
amount: actionParams.param2?.toString(),
9089
poi: poi,
91-
publicPOI: actionParams.param5,
92-
blockNumber: actionParams.param6,
90+
publicPOI: actionParams.param6,
91+
poiBlockNumber: actionParams.param5 ? Number(actionParams.param5) : undefined,
9392
force: actionParams.param4 === 'true',
9493
type,
9594
source,
@@ -198,7 +197,7 @@ export async function queueActions(
198197
amount
199198
poi
200199
publicPOI
201-
blockNumber
200+
poiBlockNumber
202201
force
203202
source
204203
reason
@@ -227,7 +226,7 @@ const ACTION_PARAMS_PARSERS: Record<keyof ActionUpdateInput, (x: never) => any>
227226
amount: nullPassThrough(parseGRT),
228227
poi: nullPassThrough((x: string) => validatePOI(x)),
229228
publicPOI: nullPassThrough((x: string) => validatePOI(x)),
230-
blockNumber: nullPassThrough((x: string) => Number(x)),
229+
poiBlockNumber: nullPassThrough((x: string) => Number(x)),
231230
force: x => parseBoolean(x),
232231
type: x => validateActionType(x),
233232
status: x => validateActionStatus(x),
@@ -270,7 +269,7 @@ export async function executeApprovedActions(
270269
amount
271270
poi
272271
publicPOI
273-
blockNumber
272+
poiBlockNumber
274273
force
275274
source
276275
reason
@@ -307,7 +306,7 @@ export async function approveActions(
307306
amount
308307
poi
309308
publicPOI
310-
blockNumber
309+
poiBlockNumber
311310
force
312311
source
313312
reason
@@ -347,7 +346,7 @@ export async function cancelActions(
347346
amount
348347
poi
349348
publicPOI
350-
blockNumber
349+
poiBlockNumber
351350
force
352351
source
353352
reason
@@ -386,7 +385,7 @@ export async function fetchAction(
386385
amount
387386
poi
388387
publicPOI
389-
blockNumber
388+
poiBlockNumber
390389
force
391390
source
392391
reason
@@ -438,7 +437,7 @@ export async function fetchActions(
438437
amount
439438
poi
440439
publicPOI
441-
blockNumber
440+
poiBlockNumber
442441
force
443442
source
444443
reason
@@ -478,7 +477,7 @@ export async function deleteActions(
478477
amount
479478
poi
480479
publicPOI
481-
blockNumber
480+
poiBlockNumber
482481
force
483482
source
484483
reason
@@ -518,7 +517,7 @@ export async function updateActions(
518517
amount
519518
poi
520519
publicPOI
521-
blockNumber
520+
poiBlockNumber
522521
force
523522
source
524523
reason

packages/indexer-cli/src/allocations.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { SubgraphDeploymentID, formatGRT, commify } from '@graphprotocol/common-
22
import yaml from 'yaml'
33
import { GluegunPrint } from 'gluegun'
44
import { table, getBorderCharacters } from 'table'
5-
import { OutputFormat, parseOutputFormat, pickFields } from './command-helpers'
5+
import { OutputFormat, parseOutputFormat, pickFields, wrapCell } from './command-helpers'
66
import { IndexerManagementClient } from '@graphprotocol/indexer-common'
77
import gql from 'graphql-tag'
88
import {
@@ -121,16 +121,17 @@ export const printIndexerAllocations = (
121121
| Partial<IndexerAllocation>[]
122122
| null,
123123
keys: (keyof IndexerAllocation)[],
124+
wrapWidth: number = 0,
124125
): void => {
125126
parseOutputFormat(print, outputFormat)
126127
if (Array.isArray(allocationOrAllocations)) {
127128
const allocations = allocationOrAllocations.map(allocation =>
128129
formatIndexerAllocation(pickFields(allocation, keys)),
129130
)
130-
print.info(displayIndexerAllocations(outputFormat, allocations))
131+
print.info(displayIndexerAllocations(outputFormat, allocations, wrapWidth))
131132
} else if (allocationOrAllocations) {
132133
const allocation = formatIndexerAllocation(pickFields(allocationOrAllocations, keys))
133-
print.info(displayIndexerAllocation(outputFormat, allocation))
134+
print.info(displayIndexerAllocation(outputFormat, allocation, wrapWidth))
134135
} else {
135136
print.error(`No allocations found`)
136137
}
@@ -139,6 +140,7 @@ export const printIndexerAllocations = (
139140
export const displayIndexerAllocations = (
140141
outputFormat: OutputFormat,
141142
allocations: Partial<IndexerAllocation>[],
143+
wrapWidth: number,
142144
): string =>
143145
outputFormat === OutputFormat.Json
144146
? JSON.stringify(allocations, null, 2)
@@ -149,7 +151,7 @@ export const displayIndexerAllocations = (
149151
: table(
150152
[
151153
Object.keys(allocations[0]),
152-
...allocations.map(allocation => Object.values(allocation)),
154+
...allocations.map(allocation => Object.values(allocation).map(value => wrapCell(value, wrapWidth))),
153155
],
154156
{
155157
border: getBorderCharacters('norc'),
@@ -159,12 +161,13 @@ export const displayIndexerAllocations = (
159161
export const displayIndexerAllocation = (
160162
outputFormat: OutputFormat,
161163
allocation: Partial<IndexerAllocation>,
164+
wrapWidth: number,
162165
): string =>
163166
outputFormat === OutputFormat.Json
164167
? JSON.stringify(allocation, null, 2)
165168
: outputFormat === OutputFormat.Yaml
166169
? yaml.stringify(allocation).trim()
167-
: table([Object.keys(allocation), Object.values(allocation)], {
170+
: table([Object.keys(allocation), Object.values(allocation).map(value => wrapCell(value, wrapWidth))], {
168171
border: getBorderCharacters('norc'),
169172
}).trim()
170173

packages/indexer-cli/src/commands/indexer/actions/approve.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,14 @@ module.exports = {
114114
'allocationID',
115115
'amount',
116116
'poi',
117+
'publicPOI',
118+
'poiBlockNumber',
117119
'force',
118120
'priority',
119121
'status',
120122
'source',
121123
'reason',
124+
'isLegacy',
122125
])
123126
} catch (error) {
124127
actionSpinner.fail(error.toString())

packages/indexer-cli/src/commands/indexer/actions/cancel.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,14 @@ module.exports = {
8080
'allocationID',
8181
'amount',
8282
'poi',
83+
'publicPOI',
84+
'poiBlockNumber',
8385
'force',
8486
'priority',
8587
'status',
8688
'source',
8789
'reason',
90+
'isLegacy',
8891
])
8992
} catch (error) {
9093
actionSpinner.fail(error.toString())

packages/indexer-cli/src/commands/indexer/actions/execute.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,15 @@ module.exports = {
7474
'allocationID',
7575
'amount',
7676
'poi',
77+
'publicPOI',
78+
'poiBlockNumber',
7779
'force',
7880
'priority',
7981
'transaction',
8082
'failureReason',
8183
'source',
8284
'reason',
85+
'isLegacy',
8386
])
8487
} catch (error) {
8588
spinner.fail(error.toString())

packages/indexer-cli/src/commands/indexer/actions/get.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ ${chalk.dim('Options:')}
3232
--first [N] Fetch only the N first records (default: all records)
3333
--fields [field1,field2,...] Comma-separated names of the fields to display (no spaces allowed between fields)
3434
-o, --output table|json|yaml Choose the output format: table (default), JSON, or YAML
35+
-w, --wrap [N] Wrap the output to a specific width (default: 0, no wrapping)
3536
`
3637

3738
const actionFields: (keyof Action)[] = [
@@ -42,6 +43,8 @@ const actionFields: (keyof Action)[] = [
4243
'allocationID',
4344
'amount',
4445
'poi',
46+
'publicPOI',
47+
'poiBlockNumber',
4548
'force',
4649
'priority',
4750
'status',
@@ -90,12 +93,15 @@ module.exports = {
9093
output,
9194
first,
9295
fields,
96+
w,
97+
wrap,
9398
} = parameters.options
9499

95100
const [action] = fixParameters(parameters, { h, help }) || []
96101
let orderByParam = ActionParams.ID
97102
let orderDirectionValue = OrderDirection.DESC
98103
const outputFormat = o || output || 'table'
104+
const wrapWidth = w || wrap || 0
99105

100106
const protocolNetwork: string | undefined = extractProtocolNetworkOption(
101107
parameters.options,
@@ -224,7 +230,7 @@ module.exports = {
224230
action => (action.protocolNetwork = resolveChainAlias(action.protocolNetwork)),
225231
)
226232

227-
printObjectOrArray(print, outputFormat, actions, displayProperties)
233+
printObjectOrArray(print, outputFormat, actions, displayProperties, wrapWidth)
228234
} catch (error) {
229235
actionSpinner.fail(error.toString())
230236
process.exitCode = 1

packages/indexer-cli/src/commands/indexer/actions/queue.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ import {
1717
const HELP = `
1818
${chalk.bold(
1919
'graph indexer actions queue',
20-
)} [options] <ActionType> <targetDeployment> <param1> <param2> <param3> <param4>
20+
)} [options] <ActionType> <targetDeployment> <param1> <param2> <param3> <param4> <param5> <param6>
2121
${chalk.bold('graph indexer actions queue')} [options] allocate <deploymentID> <amount>
2222
${chalk.bold(
2323
'graph indexer actions queue',
24-
)} [options] unallocate <deploymentID> <allocationID> <poi> <force> <publicPOI> <blockNumber>
24+
)} [options] unallocate <deploymentID> <allocationID> <poi> <force> <blockNumber> <publicPOI>
2525
${chalk.bold(
2626
'graph indexer actions queue',
27-
)} [options] reallocate <deploymentID> <allocationID> <amount> <poi> <force> <publicPOI> <blockNumber>
27+
)} [options] reallocate <deploymentID> <allocationID> <amount> <poi> <force> <blockNumber> <publicPOI>
2828
2929
${chalk.dim('Options:')}
3030
@@ -119,11 +119,14 @@ module.exports = {
119119
'allocationID',
120120
'amount',
121121
'poi',
122+
'publicPOI',
123+
'poiBlockNumber',
122124
'force',
123125
'priority',
124126
'status',
125127
'source',
126128
'reason',
129+
'isLegacy',
127130
])
128131
} catch (error) {
129132
actionSpinner.fail(error.toString())

packages/indexer-cli/src/commands/indexer/actions/update.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,16 @@ module.exports = {
108108
'allocationID',
109109
'amount',
110110
'poi',
111+
'publicPOI',
112+
'poiBlockNumber',
111113
'force',
112114
'priority',
113115
'status',
114116
'source',
115117
'failureReason',
116118
'transaction',
117119
'reason',
120+
'isLegacy',
118121
]
119122

120123
// Format Actions 'protocolNetwork' field to display human-friendly chain aliases instead of CAIP2-IDs

0 commit comments

Comments
 (0)