Skip to content

Commit

Permalink
client: fix validation logic for optional params in rpc (#2358)
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 authored Oct 14, 2022
1 parent 9204b57 commit 6eb5a85
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/client/lib/rpc/modules/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export class Eth {

this.chainId = middleware(this.chainId.bind(this), 0, [])

this.estimateGas = middleware(this.estimateGas.bind(this), 2, [
this.estimateGas = middleware(this.estimateGas.bind(this), 1, [
[validators.transaction()],
[validators.blockOption],
])
Expand Down
9 changes: 6 additions & 3 deletions packages/client/lib/rpc/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ export function middleware(method: any, requiredParamsCount: number, validators:
for (let i = 0; i < validators.length; i++) {
if (validators[i] !== undefined) {
for (let j = 0; j < validators[i].length; j++) {
const error = validators[i][j](params, i)
if (error !== undefined) {
return reject(error)
// Only apply validators if params[i] is a required parameter or exists
if (i < requiredParamsCount || params[i] !== undefined) {
const error = validators[i][j](params, i)
if (error !== undefined) {
return reject(error)
}
}
}
}
Expand Down

0 comments on commit 6eb5a85

Please sign in to comment.