Skip to content

Commit a9b4b15

Browse files
committed
manifest-schema,subgraph: Update blockHandler block struct selecting api
- Update field name: input -> blockFormat - Define and use string conversion from manifest formatted blockFormat values to struct names. Reporting an error with suggestions if an unsupported value is used.
1 parent 5eaba3f commit a9b4b15

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

manifest-schema.graphql

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type EthereumContractAbi {
4242

4343
type EthereumBlockHandler {
4444
handler: String!
45-
input: String
45+
blockFormat: String
4646
filter: EthereumBlockFilter
4747
}
4848

src/subgraph.js

+29-7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ const throwCombinedError = (filename, errors) => {
2424
)
2525
}
2626

27+
// Define conversions from a 'blockFormat' value in the manifest to its corresponding struct name
28+
const blockFormatToStructName = immutable.Map({
29+
'block-only': 'Block',
30+
'block-with-transactions': 'BlockWithTransactions',
31+
'block-with-receipts': 'BlockWithReceipts',
32+
})
33+
2734
const buildCombinedWarning = (filename, warnings) =>
2835
warnings.size > 0
2936
? warnings.reduce(
@@ -343,7 +350,7 @@ ${abiFunctions
343350
)
344351

345352
// Ensure each blockHandler has a corresponding mapping handler
346-
// with a compatible function signature
353+
// with a compatible function signature and uses a supported `blockFormat` value.
347354
return errors.concat(
348355
blockHandlers.reduce(
349356
(errors, handler, index) =>
@@ -358,28 +365,43 @@ ${abiFunctions
358365
functionDeclaration =>
359366
functionDeclaration.name.text === handler.get('handler') &&
360367
functionDeclaration.signature.parameters.length === 1 &&
361-
functionDeclaration.signature.parameters[0].name.text ==
362-
'block' &&
363368
functionDeclaration.signature.parameters[0].type.name.identifier
364369
.text === 'ethereum' &&
365370
functionDeclaration.signature.parameters[0].type.name.next
366-
.identifier.text === handler.get('input', 'Block') &&
371+
.identifier.text ===
372+
blockFormatToStructName.get(
373+
handler.get('blockFormat', 'block-only'),
374+
) &&
367375
functionDeclaration.signature.parameters[0].type.name.next
368376
.next === null &&
369377
functionDeclaration.signature.returnType.name.identifier.text ===
370378
'void',
371379
),
372380
)
373381
? errors
374-
: errors.push(
382+
: blockFormatToStructName.get(handler.get('blockFormat', 'block-only'))
383+
? errors.push(
375384
immutable.fromJS({
376385
path: [...path, index],
377386
message: `\
378387
Matching mapping handler not found in '${mappingFile}' for blockHandler: '${handler.get(
379388
'handler',
380389
)}'.
381-
Signature:
382-
${handler.get('handler')}(block: ethereum.${handler.get('input', 'Block')}): void`,
390+
Signature:
391+
${handler.get('handler')}(block: ethereum.${blockFormatToStructName.get(
392+
handler.get('blockFormat', 'block-only'),
393+
)}): void`,
394+
}),
395+
)
396+
: errors.push(
397+
immutable.fromJS({
398+
path: [...path, index],
399+
message: `Unsupported blockFormat, '${handler.get(
400+
'blockFormat',
401+
)}', specified for the '${handler.get('handler')}' blockHandler.
402+
Please use one of the supported blockFormats: ${JSON.stringify(
403+
blockFormatToStructName.keySeq(),
404+
)}`,
383405
}),
384406
),
385407
immutable.List(),

0 commit comments

Comments
 (0)