Skip to content
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

feat: implement method HeaderByHash and HeaderByNumberOrHash #93

Open
wants to merge 1 commit into
base: staging/03-30
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions ethereum/rpc/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,43 @@ func (b *BackendImpl) HeaderByNumber(_ context.Context, number rpc.BlockNumber)
}

func (b *BackendImpl) HeaderByHash(_ context.Context, hash common.Hash) (*ethtypes.Header, error) {
return nil, nil
resBlock, err := b.CosmosBlockByHash(hash)
if err != nil || resBlock == nil {
return nil, fmt.Errorf("failed to get block by hash %s, %w", hash.Hex(), err)
}

blockRes, err := b.CosmosBlockResultByNumber(&resBlock.Block.Height)
if err != nil {
return nil, fmt.Errorf("block result not found for height %d", resBlock.Block.Height)
}

bloom, err := b.blockBloom(blockRes)
if err != nil {
b.logger.Debug("HeaderByNumber BlockBloom failed", "height", resBlock.Block.Height)
}

baseFee, err := b.BaseFee(blockRes)
if err != nil {
// handle the error for pruned node.
b.logger.Error("failed to fetch Base Fee from prunned block. Check node prunning configuration", "height", resBlock.Block.Height, "error", err)
}

ethHeader := rpctypes.EthHeaderFromTendermint(resBlock.Block.Header, bloom, baseFee)
return ethHeader, nil
}

func (b *BackendImpl) HeaderByNumberOrHash(ctx context.Context,
blockNrOrHash rpc.BlockNumberOrHash,
) (*ethtypes.Header, error) {
return nil, errors.New("HeaderByNumberOrHash is not implemented")
if blockNr, ok := blockNrOrHash.Number(); ok {
return b.HeaderByNumber(ctx, blockNr)
}

if hash, ok := blockNrOrHash.Hash(); ok {
return b.HeaderByHash(ctx, hash)
}

return nil, errors.New("invalid arguments; neither block nor hash specified")
}

func (b *BackendImpl) CurrentHeader() *ethtypes.Header {
Expand Down