Skip to content

Commit 3ccd6b6

Browse files
authored
graphql: fix block resolving for parent field (#24191)
Fixes #24161
1 parent c20de3c commit 3ccd6b6

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

graphql/graphql.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -599,21 +599,18 @@ func (b *Block) BaseFeePerGas(ctx context.Context) (*hexutil.Big, error) {
599599
}
600600

601601
func (b *Block) Parent(ctx context.Context) (*Block, error) {
602-
// If the block header hasn't been fetched, and we'll need it, fetch it.
603-
if b.numberOrHash == nil && b.header == nil {
604-
if _, err := b.resolveHeader(ctx); err != nil {
605-
return nil, err
606-
}
602+
if _, err := b.resolveHeader(ctx); err != nil {
603+
return nil, err
607604
}
608-
if b.header != nil && b.header.Number.Uint64() > 0 {
609-
num := rpc.BlockNumberOrHashWithNumber(rpc.BlockNumber(b.header.Number.Uint64() - 1))
610-
return &Block{
611-
backend: b.backend,
612-
numberOrHash: &num,
613-
hash: b.header.ParentHash,
614-
}, nil
605+
if b.header == nil || b.header.Number.Uint64() < 1 {
606+
return nil, nil
615607
}
616-
return nil, nil
608+
num := rpc.BlockNumberOrHashWithNumber(rpc.BlockNumber(b.header.Number.Uint64() - 1))
609+
return &Block{
610+
backend: b.backend,
611+
numberOrHash: &num,
612+
hash: b.header.ParentHash,
613+
}, nil
617614
}
618615

619616
func (b *Block) Difficulty(ctx context.Context) (hexutil.Big, error) {

0 commit comments

Comments
 (0)