Skip to content

Commit

Permalink
Add accesors for block information.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Sep 8, 2023
1 parent 10dd09f commit 4596638
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion spec/block.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2021, 2022 Attestant Limited.
// Copyright © 2021 - 2023 Attestant Limited.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -441,6 +441,43 @@ func (b *Block) Uncles() []types.Hash {
}
}

// Withdrawals returns the withdrawals of the block.
// This is not available in all forks, so also returns a presence flag.
func (b *Block) Withdrawals() ([]*Withdrawal, bool) {
switch b.Fork {
case ForkShanghai:
return b.Shanghai.Withdrawals, true
case ForkCancun:
return b.Cancun.Withdrawals, true
default:
return nil, false
}
}

// WithdrawalsRoot returns the withdrawals root of the block.
// This is not available in all forks, so also returns a presence flag.
func (b *Block) WithdrawalsRoot() (types.Root, bool) {
switch b.Fork {
case ForkShanghai:
return b.Shanghai.WithdrawalsRoot, true
case ForkCancun:
return b.Cancun.WithdrawalsRoot, true
default:
return types.Root{}, false
}
}

// ParentBeaconBlockRoot returns the parent beacon block root of the block.
// This is not available in all forks, so also returns a presence flag.
func (b *Block) ParentBeaconBlockHash() (types.Root, bool) {
switch b.Fork {
case ForkCancun:
return b.Cancun.ParentBeaconBlockRoot, true
default:
return types.Root{}, false
}
}

// String returns a string version of the structure.
func (b *Block) String() string {
data, err := json.Marshal(b)
Expand Down

0 comments on commit 4596638

Please sign in to comment.