graphql: fix block resolving for parent field (#24191)

Fixes #24161
This commit is contained in:
Sina Mahmoodi 2022-01-05 16:22:46 +01:00 committed by GitHub
parent c20de3c4bd
commit 3ccd6b6dbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 b.header == nil || b.header.Number.Uint64() < 1 {
return nil, nil
}
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
}
return nil, nil
}
func (b *Block) Difficulty(ctx context.Context) (hexutil.Big, error) {