rpc: reject block parameter with neither number nor hash (#35271)

This commit is contained in:
Stavros Vlachakis 2026-07-03 09:31:53 +03:00 committed by GitHub
parent 3d50e3eb0e
commit d617f4fcdb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 0 deletions

View file

@ -158,6 +158,9 @@ func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error {
if e.BlockNumber != nil && e.BlockHash != nil {
return errors.New("cannot specify both BlockHash and BlockNumber, choose one or the other")
}
if e.BlockNumber == nil && e.BlockHash == nil {
return errors.New("must specify either BlockHash or BlockNumber")
}
bnh.BlockNumber = e.BlockNumber
bnh.BlockHash = e.BlockHash
bnh.RequireCanonical = e.RequireCanonical

View file

@ -109,6 +109,8 @@ func TestBlockNumberOrHash_UnmarshalJSON(t *testing.T) {
27: {`{"blockNumber":"safe"}`, false, BlockNumberOrHashWithNumber(SafeBlockNumber)},
28: {`{"blockNumber":"finalized"}`, false, BlockNumberOrHashWithNumber(FinalizedBlockNumber)},
29: {`{"blockNumber":"0x1", "blockHash":"0x0000000000000000000000000000000000000000000000000000000000000000"}`, true, BlockNumberOrHash{}},
30: {`{}`, true, BlockNumberOrHash{}},
31: {`{"requireCanonical":true}`, true, BlockNumberOrHash{}},
}
for i, test := range tests {