Skip to content

Commit

Permalink
Wrap rpc errors on /block/*
Browse files Browse the repository at this point in the history
  • Loading branch information
mcortesi committed Mar 30, 2020
1 parent cec3f84 commit 237af3a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/api_block_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (b *BlockApiService) BlockHeader(ctx context.Context, blockIdentifier Parti
hash := common.HexToHash(*blockIdentifier.Hash)
blockHeader, err = b.celoClient.Eth.ExtendedHeaderByHash(ctx, hash)
if err != nil {
err = client.WrapRpcError(err)
return nil, ErrCantFetchBlockHeader(err)
}

Expand All @@ -54,11 +55,13 @@ func (b *BlockApiService) BlockHeader(ctx context.Context, blockIdentifier Parti
} else if blockIdentifier.Index != nil {
blockHeader, err = b.celoClient.Eth.ExtendedHeaderByNumber(ctx, big.NewInt(*blockIdentifier.Index))
if err != nil {
err = client.WrapRpcError(err)
return nil, ErrCantFetchBlockHeader(err)
}
} else {
blockHeader, err = b.celoClient.Eth.ExtendedHeaderByNumber(ctx, nil)
if err != nil {
err = client.WrapRpcError(err)
return nil, ErrCantFetchBlockHeader(err)
}
}
Expand Down Expand Up @@ -126,6 +129,8 @@ func (s *BlockApiService) BlockTransaction(ctx context.Context, request BlockTra
}
operations = RewardsToOperations(rewards)
} else {
// Normal transaction

if !HeaderContainsTx(blockHeader, txHash) {
return nil, ErrMissingTxInBlock
}
Expand Down

0 comments on commit 237af3a

Please sign in to comment.