-
Notifications
You must be signed in to change notification settings - Fork 178
/
backend_block_details.go
60 lines (48 loc) · 1.23 KB
/
backend_block_details.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package backend
import (
"context"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/state/protocol"
"github.com/onflow/flow-go/storage"
)
type backendBlockDetails struct {
blocks storage.Blocks
state protocol.State
}
func (b *backendBlockDetails) GetLatestBlock(_ context.Context, isSealed bool) (*flow.Block, error) {
var header *flow.Header
var err error
if isSealed {
// get the latest seal header from storage
header, err = b.state.Sealed().Head()
} else {
// get the finalized header from state
header, err = b.state.Final().Head()
}
if err != nil {
err = convertStorageError(err)
return nil, err
}
block, err := b.blocks.ByID(header.ID())
if err != nil {
err = convertStorageError(err)
return nil, err
}
return block, nil
}
func (b *backendBlockDetails) GetBlockByID(_ context.Context, id flow.Identifier) (*flow.Block, error) {
block, err := b.blocks.ByID(id)
if err != nil {
err = convertStorageError(err)
return nil, err
}
return block, nil
}
func (b *backendBlockDetails) GetBlockByHeight(_ context.Context, height uint64) (*flow.Block, error) {
block, err := b.blocks.ByHeight(height)
if err != nil {
err = convertStorageError(err)
return nil, err
}
return block, nil
}