Skip to content

Commit cef7c8c

Browse files
ryanioholgerd77
authored andcommitted
improve blockOption validator
1 parent bf98e2e commit cef7c8c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/client/lib/rpc/validation.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,18 @@ export const validators = {
129129

130130
if (!['latest', 'earliest', 'pending'].includes(blockOption)) {
131131
if (blockOption.substr(0, 2) === '0x') {
132-
// valid block integer or hash
133-
return
132+
const hash = this.blockHash([blockOption], 0)
133+
// todo: make integer validator?
134+
const integer = this.hex([blockOption], 0)
135+
// valid if undefined
136+
if (hash === undefined || integer === undefined) {
137+
// valid
138+
return
139+
}
134140
}
135141
return {
136142
code: INVALID_PARAMS,
137-
message: `invalid argument ${index}: block option must be value "latest", "earliest" or "pending"`,
143+
message: `invalid argument ${index}: block option must be a valid 0x-prefixed block hash or hex integer, or "latest", "earliest" or "pending"`,
138144
}
139145
}
140146
},

0 commit comments

Comments
 (0)