mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 07:37:20 +00:00
ethclient: restore BlockReceipts support for BlockNumberOrHash objects (#33242)
- pass `rpc.BlockNumberOrHash` directly to `eth_getBlockReceipts` so `requireCanonical` and other fields survive - aligns `BlockReceipts` with other `ethclient` methods and re-enables canonical-only receipt queries
This commit is contained in:
parent
b993cb6f38
commit
4eb5b66d9e
2 changed files with 44 additions and 1 deletions
|
|
@ -124,7 +124,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.String())
|
||||
err := ec.c.CallContext(ctx, &r, "eth_getBlockReceipts", blockNrOrHash)
|
||||
if err == nil && r == nil {
|
||||
return nil, ethereum.NotFound
|
||||
}
|
||||
|
|
|
|||
|
|
@ -687,6 +687,49 @@ func testTransactionSender(t *testing.T, client *rpc.Client) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBlockReceiptsPreservesCanonicalFlag(t *testing.T) {
|
||||
srv := rpc.NewServer()
|
||||
service := &blockReceiptsTestService{calls: make(chan rpc.BlockNumberOrHash, 1)}
|
||||
if err := srv.RegisterName("eth", service); err != nil {
|
||||
t.Fatalf("failed to register service: %v", err)
|
||||
}
|
||||
defer srv.Stop()
|
||||
|
||||
client := rpc.DialInProc(srv)
|
||||
defer client.Close()
|
||||
|
||||
ec := ethclient.NewClient(client)
|
||||
defer ec.Close()
|
||||
|
||||
hash := common.HexToHash("0x01")
|
||||
ref := rpc.BlockNumberOrHashWithHash(hash, true)
|
||||
|
||||
if _, err := ec.BlockReceipts(context.Background(), ref); err != nil {
|
||||
t.Fatalf("BlockReceipts returned error: %v", err)
|
||||
}
|
||||
|
||||
select {
|
||||
case call := <-service.calls:
|
||||
if call.BlockHash == nil || *call.BlockHash != hash {
|
||||
t.Fatalf("unexpected block hash: got %v, want %v", call.BlockHash, hash)
|
||||
}
|
||||
if !call.RequireCanonical {
|
||||
t.Fatalf("requireCanonical flag was lost: %+v", call)
|
||||
}
|
||||
default:
|
||||
t.Fatal("service was not called")
|
||||
}
|
||||
}
|
||||
|
||||
type blockReceiptsTestService struct {
|
||||
calls chan rpc.BlockNumberOrHash
|
||||
}
|
||||
|
||||
func (s *blockReceiptsTestService) GetBlockReceipts(ctx context.Context, block rpc.BlockNumberOrHash) ([]*types.Receipt, error) {
|
||||
s.calls <- block
|
||||
return []*types.Receipt{}, nil
|
||||
}
|
||||
|
||||
func newCanceledContext() context.Context {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
|
|
|||
Loading…
Reference in a new issue