Skip to content

Commit

Permalink
eth: minor change in error-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman committed Mar 13, 2023
1 parent 4c8e217 commit e0881c0
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,20 @@ func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumb
if number == rpc.LatestBlockNumber {
return b.eth.blockchain.CurrentBlock(), nil
}
if !b.eth.Merger().TDDReached() && (number == rpc.FinalizedBlockNumber || number == rpc.SafeBlockNumber) {
return nil, errors.New("finalized/safe is not supported on pre-merge network")
}
if number == rpc.FinalizedBlockNumber {
if !b.eth.Merger().TDDReached() {
return nil, errors.New("'finalized' tag not supported on pre-merge network")
}
block := b.eth.blockchain.CurrentFinalBlock()
if block != nil {
return block, nil
}
return nil, errors.New("finalized block not found")
}
if number == rpc.SafeBlockNumber {
if !b.eth.Merger().TDDReached() {
return nil, errors.New("'safe' tag not supported on pre-merge network")
}
block := b.eth.blockchain.CurrentSafeBlock()
if block != nil {
return block, nil
Expand Down Expand Up @@ -126,14 +129,17 @@ func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumbe
header := b.eth.blockchain.CurrentBlock()
return b.eth.blockchain.GetBlock(header.Hash(), header.Number.Uint64()), nil
}
if !b.eth.Merger().TDDReached() && (number == rpc.FinalizedBlockNumber || number == rpc.SafeBlockNumber) {
return nil, errors.New("finalized/safe is not supported on pre-merge network")
}
if number == rpc.FinalizedBlockNumber {
if !b.eth.Merger().TDDReached() {
return nil, errors.New("'finalized' tag not supported on pre-merge network")
}
header := b.eth.blockchain.CurrentFinalBlock()
return b.eth.blockchain.GetBlock(header.Hash(), header.Number.Uint64()), nil
}
if number == rpc.SafeBlockNumber {
if !b.eth.Merger().TDDReached() {
return nil, errors.New("'safe' tag not supported on pre-merge network")
}
header := b.eth.blockchain.CurrentSafeBlock()
return b.eth.blockchain.GetBlock(header.Hash(), header.Number.Uint64()), nil
}
Expand Down

0 comments on commit e0881c0

Please sign in to comment.