Update GQL API to return empty result when header not found for hash

This commit is contained in:
Prathamesh Musale 2022-07-15 15:23:49 +05:30
parent 4525140286
commit 86dfc775c2
3 changed files with 9 additions and 6 deletions

View File

@ -37,7 +37,6 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth/filters"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/statediff"
@ -1098,13 +1097,13 @@ func (pea *PublicEthAPI) writeStateDiffFor(blockHash common.Hash) {
func (pea *PublicEthAPI) rpcMarshalBlock(b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) {
fields, err := RPCMarshalBlock(b, inclTx, fullTx)
if err != nil {
log.Error("error RPC marshalling block with hash", b.Hash().String(), err)
logrus.Error("error RPC marshalling block with hash", b.Hash().String(), err)
return nil, err
}
if inclTx {
td, err := pea.B.GetTd(b.Hash())
if err != nil {
log.Error("error getting td for block with hash and number", b.Hash().String(), b.Number().String(), err)
logrus.Error("error getting td for block with hash and number", b.Hash().String(), b.Number().String(), err)
return nil, err
}
fields["totalDifficulty"] = (*hexutil.Big)(td)

View File

@ -722,6 +722,7 @@ func (ecr *CIDRetriever) RetrieveHeaderAndTxCIDsByBlockHash(blockHash common.Has
err := ecr.gormDB.Preload("TransactionCIDs", func(tx *gorm.DB) *gorm.DB {
return tx.Select("cid", "tx_hash", "index", "src", "dst", "header_id", "block_number")
}).Joins("IPLD").Find(&headerCIDs, "block_hash = ?", blockHash.String()).Error
if err != nil {
log.Error("header cid retrieval error")
return HeaderCIDRecord{}, err

View File

@ -23,6 +23,7 @@ import (
"database/sql"
"errors"
"fmt"
"strings"
"time"
"github.com/ethereum/go-ethereum/common"
@ -1268,10 +1269,12 @@ func (r *Resolver) AllEthHeaderCids(ctx context.Context, args struct {
if args.Condition.BlockHash != nil {
headerCID, err := r.backend.Retriever.RetrieveHeaderAndTxCIDsByBlockHash(common.HexToHash(*args.Condition.BlockHash))
if err != nil {
return nil, err
if !strings.Contains(err.Error(), "not found") {
return nil, err
}
} else {
headerCIDs = append(headerCIDs, headerCID)
}
headerCIDs = append(headerCIDs, headerCID)
} else if args.Condition.BlockNumber != nil {
headerCIDs, err = r.backend.Retriever.RetrieveHeaderAndTxCIDsByBlockNumber(args.Condition.BlockNumber.ToInt().Int64())
if err != nil {