-
Notifications
You must be signed in to change notification settings - Fork 175
/
params.go
73 lines (57 loc) · 1.62 KB
/
params.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
61
62
63
64
65
66
67
68
69
70
71
72
73
package badger
import (
"fmt"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/storage/badger/operation"
)
type Params struct {
state *State
}
func (p *Params) ChainID() (flow.ChainID, error) {
// retrieve root header
root, err := p.Root()
if err != nil {
return "", fmt.Errorf("could not get root: %w", err)
}
return root.ChainID, nil
}
func (p *Params) Root() (*flow.Header, error) {
// retrieve the root height
var height uint64
err := p.state.db.View(operation.RetrieveRootHeight(&height))
if err != nil {
return nil, fmt.Errorf("could not retrieve root height: %w", err)
}
// look up root header
var rootID flow.Identifier
err = p.state.db.View(operation.LookupBlockHeight(height, &rootID))
if err != nil {
return nil, fmt.Errorf("could not look up root header: %w", err)
}
// retrieve root header
header, err := p.state.headers.ByBlockID(rootID)
if err != nil {
return nil, fmt.Errorf("could not retrieve root header: %w", err)
}
return header, nil
}
func (p *Params) Seal() (*flow.Seal, error) {
// retrieve the root height
var height uint64
err := p.state.db.View(operation.RetrieveRootHeight(&height))
if err != nil {
return nil, fmt.Errorf("could not retrieve root height: %w", err)
}
// look up root header
var rootID flow.Identifier
err = p.state.db.View(operation.LookupBlockHeight(height, &rootID))
if err != nil {
return nil, fmt.Errorf("could not look up root header: %w", err)
}
// retrieve the root seal
seal, err := p.state.seals.ByBlockID(rootID)
if err != nil {
return nil, fmt.Errorf("could not retrieve root seal: %w", err)
}
return seal, nil
}