Skip to content

Commit

Permalink
graphql: fix block resolving for parent field (ethereum#24191)
Browse files Browse the repository at this point in the history
  • Loading branch information
s1na authored and JacekGlen committed May 26, 2022
1 parent d932a6d commit d369b1d
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions graphql/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,21 +599,18 @@ func (b *Block) BaseFeePerGas(ctx context.Context) (*hexutil.Big, error) {
}

func (b *Block) Parent(ctx context.Context) (*Block, error) {
// If the block header hasn't been fetched, and we'll need it, fetch it.
if b.numberOrHash == nil && b.header == nil {
if _, err := b.resolveHeader(ctx); err != nil {
return nil, err
}
if _, err := b.resolveHeader(ctx); err != nil {
return nil, err
}
if b.header != nil && b.header.Number.Uint64() > 0 {
num := rpc.BlockNumberOrHashWithNumber(rpc.BlockNumber(b.header.Number.Uint64() - 1))
return &Block{
backend: b.backend,
numberOrHash: &num,
hash: b.header.ParentHash,
}, nil
if b.header == nil || b.header.Number.Uint64() < 1 {
return nil, nil
}
return nil, nil
num := rpc.BlockNumberOrHashWithNumber(rpc.BlockNumber(b.header.Number.Uint64() - 1))
return &Block{
backend: b.backend,
numberOrHash: &num,
hash: b.header.ParentHash,
}, nil
}

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

0 comments on commit d369b1d

Please sign in to comment.