Unverified Commit 3ccd6b6d authored by Sina Mahmoodi's avatar Sina Mahmoodi Committed by GitHub

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

Fixes #24161
parent c20de3c4
...@@ -599,21 +599,18 @@ func (b *Block) BaseFeePerGas(ctx context.Context) (*hexutil.Big, error) { ...@@ -599,21 +599,18 @@ func (b *Block) BaseFeePerGas(ctx context.Context) (*hexutil.Big, error) {
} }
func (b *Block) Parent(ctx context.Context) (*Block, 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 _, err := b.resolveHeader(ctx); err != nil {
if b.numberOrHash == nil && b.header == nil { return nil, err
if _, err := b.resolveHeader(ctx); err != nil {
return nil, err
}
} }
if b.header != nil && b.header.Number.Uint64() > 0 { if b.header == nil || b.header.Number.Uint64() < 1 {
num := rpc.BlockNumberOrHashWithNumber(rpc.BlockNumber(b.header.Number.Uint64() - 1)) return nil, nil
return &Block{
backend: b.backend,
numberOrHash: &num,
hash: b.header.ParentHash,
}, 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) { func (b *Block) Difficulty(ctx context.Context) (hexutil.Big, error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment