-
Notifications
You must be signed in to change notification settings - Fork 20.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ethclient: fix BlockReceipts parameter encoding #28087
Conversation
There is an issue. After marshaling rpc.BlockNumberOrHash we have e.g. {"jsonrpc":"2.0","id":3,"method":"eth_getBlockReceipts","params":[{"blockNumber":"0x2"}]} instead of {"jsonrpc":"2.0","id":3,"method":"eth_getBlockReceipts","params":["0x2"]} and invalid response.
internal/ethapi: Fix eth_getBlockReceipts
@@ -111,7 +111,7 @@ func (ec *Client) PeerCount(ctx context.Context) (uint64, error) { | |||
// BlockReceipts returns the receipts of a given block number or hash | |||
func (ec *Client) BlockReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]*types.Receipt, error) { | |||
var r []*types.Receipt | |||
err := ec.c.CallContext(ctx, &r, "eth_getBlockReceipts", blockNrOrHash) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, Please also add a test case
Afaict the method we provide |
Co-authored-by: Felix Lange <fjl@twurst.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
Doesn't this change result in block numbers being sent in decimal? ie it winds up executing Lines 222 to 225 in 9231770
latest now. So I think this now only works for block hashes.
unit test demonstrating this (add to func TestBlockNumberOrHash_WithNumber_StringAndUnmarshal(t *testing.T) {
tests := []struct {
name string
value BlockNumberOrHash
}{
{"max", BlockNumberOrHashWithNumber(math.MaxInt64)},
{"pending", BlockNumberOrHashWithNumber(PendingBlockNumber)},
{"latest", BlockNumberOrHashWithNumber(LatestBlockNumber)},
{"earliest", BlockNumberOrHashWithNumber(EarliestBlockNumber)},
{"0x20", BlockNumberOrHashWithNumber(32)},
{"hash", BlockNumberOrHashWithHash(common.Hash{0xaa}, false)},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
bnh := test.value
marshalled := []byte("\"" + bnh.String() + "\"")
var unmarshalled BlockNumberOrHash
err := json.Unmarshal(marshalled, &unmarshalled)
if err != nil {
t.Fatalf("cannot unmarshal (%v): %v", string(marshalled), err)
}
if !reflect.DeepEqual(bnh, unmarshalled) {
t.Fatalf("wrong result: expected %v, got %v", bnh, unmarshalled)
}
})
}
} |
Co-authored-by: Felix Lange <fjl@twurst.com>
…)" This reverts commit 2e3ba71.
…)" This reverts commit 2e3ba71.
Co-authored-by: Felix Lange <fjl@twurst.com>
* Copy ethereum/go-ethereum#27702 * Fix TestRPCGetBlockReceipts * Get ethclient compiling * Copy ethereum/go-ethereum#28087 * Copy ethereum/go-ethereum#28358
There is an issue. After marshaling rpc.BlockNumberOrHash we have e.g. {"jsonrpc":"2.0","id":3,"method":"eth_getBlockReceipts","params":[{"blockNumber":"0x2"}]} instead of {"jsonrpc":"2.0","id":3,"method":"eth_getBlockReceipts","params":["0x2"]} and invalid response.