-
Notifications
You must be signed in to change notification settings - Fork 178
/
file.go
61 lines (50 loc) · 1.59 KB
/
file.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
package utils
import (
"encoding/json"
"fmt"
"path/filepath"
"github.com/onflow/flow-go/engine/common/rpc/convert"
model "github.com/onflow/flow-go/model/bootstrap"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/state/protocol/inmem"
io "github.com/onflow/flow-go/utils/io"
)
func ReadRootProtocolSnapshot(bootDir string) (*inmem.Snapshot, error) {
// default path root snapshot is written to
snapshotPath := filepath.Join(bootDir, model.PathRootProtocolStateSnapshot)
// read snapshot file bytes
bz, err := io.ReadFile(snapshotPath)
if err != nil {
return nil, fmt.Errorf("could not read snapshot: %w", err)
}
// convert bytes to snapshot struct
snapshot, err := convert.BytesToInmemSnapshot(bz)
if err != nil {
return nil, fmt.Errorf("could not convert bytes to snapshot: %w", err)
}
return snapshot, nil
}
func ReadRootBlock(rootBlockDataPath string) (*flow.Block, error) {
bytes, err := io.ReadFile(rootBlockDataPath)
if err != nil {
return nil, fmt.Errorf("could not read root block: %w", err)
}
var encodable flow.Block
err = json.Unmarshal(bytes, &encodable)
if err != nil {
return nil, fmt.Errorf("could not unmarshal root block: %w", err)
}
return &encodable, nil
}
func ReadDKGData(dkgDataPath string) (*inmem.EncodableFullDKG, error) {
bytes, err := io.ReadFile(dkgDataPath)
if err != nil {
return nil, fmt.Errorf("could not read dkg data: %w", err)
}
var encodable inmem.EncodableFullDKG
err = json.Unmarshal(bytes, &encodable)
if err != nil {
return nil, fmt.Errorf("could not unmarshal dkg data: %w", err)
}
return &encodable, nil
}