Skip to content

Commit 65f6fd2

Browse files
committed
fix: action update serialization bug for bigints
Signed-off-by: Tomás Migone <[email protected]>
1 parent 09898ce commit 65f6fd2

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

packages/indexer-cli/src/actions.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import { validatePOI, validateRequiredParams } from './command-helpers'
1616
import gql from 'graphql-tag'
1717
import { hexlify } from 'ethers'
18-
import { parseGRT } from '@graphprotocol/common-ts'
18+
import { formatGRT, parseGRT } from '@graphprotocol/common-ts'
1919

2020
export interface GenericActionInputParams {
2121
targetDeployment: string
@@ -235,6 +235,25 @@ const ACTION_PARAMS_PARSERS: Record<keyof ActionUpdateInput, (x: never) => any>
235235
isLegacy: x => parseBoolean(x),
236236
}
237237

238+
const ACTION_CONVERTERS_TO_GRAPHQL: Record<
239+
keyof ActionUpdateInput,
240+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
241+
(x: never) => any
242+
> = {
243+
deploymentID: x => x,
244+
allocationID: x => x,
245+
amount: nullPassThrough((x: bigint) => formatGRT(x)),
246+
poi: x => x,
247+
publicPOI: x => x,
248+
poiBlockNumber: nullPassThrough((x: number) => x),
249+
force: x => x,
250+
type: x => x,
251+
status: x => x,
252+
reason: x => x,
253+
protocolNetwork: x => x,
254+
isLegacy: x => x,
255+
}
256+
238257
/**
239258
* Parses a user-provided action update input into a normalized form.
240259
*/
@@ -252,6 +271,22 @@ export const parseActionUpdateInput = (input: object): ActionUpdateInput => {
252271
return obj as ActionUpdateInput
253272
}
254273

274+
/**
275+
* Converts a normalized action to a representation
276+
* compatible with the indexer management GraphQL API.
277+
*/
278+
export const actionToGraphQL = (
279+
action: Partial<ActionUpdateInput>,
280+
): Partial<ActionUpdateInput> => {
281+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
282+
const obj = {} as any
283+
for (const [key, value] of Object.entries(action)) {
284+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
285+
obj[key] = (ACTION_CONVERTERS_TO_GRAPHQL as any)[key](value)
286+
}
287+
return obj as Partial<ActionUpdateInput>
288+
}
289+
255290
export async function executeApprovedActions(
256291
client: IndexerManagementClient,
257292
): Promise<ActionResult[]> {
@@ -530,7 +565,7 @@ export async function updateActions(
530565
}
531566
}
532567
`,
533-
{ filter, action },
568+
{ filter, action: actionToGraphQL(action) },
534569
)
535570
.toPromise()
536571

packages/indexer-common/src/indexer-management/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ const SCHEMA_SDL = gql`
165165
id: Int
166166
deploymentID: String
167167
allocationID: String
168-
amount: Int
168+
amount: String
169169
poi: String
170170
publicPOI: String
171171
poiBlockNumber: Int

0 commit comments

Comments
 (0)