forked from hyperledger-archives/burrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restore.go
44 lines (35 loc) · 1.2 KB
/
restore.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
package commands
import (
"github.com/hyperledger/burrow/core"
cli "github.com/jawher/mow.cli"
)
// Restore reads a state file and saves into a runnable dir
func Restore(output Output) func(cmd *cli.Cmd) {
return func(cmd *cli.Cmd) {
configOpts := addConfigOptions(cmd)
silentOpt := cmd.BoolOpt("s silent", false, "If state already exists don't throw error")
filename := cmd.StringArg("FILE", "", "Restore from this dump")
cmd.Spec += "[--silent] [FILE]"
cmd.Action = func() {
conf, err := configOpts.obtainBurrowConfig()
if err != nil {
output.Fatalf("could not set up config: %v", err)
}
if err := conf.Verify(); err != nil {
output.Fatalf("cannot continue with config: %v", err)
}
output.Logf("Using validator address: %s", *conf.ValidatorAddress)
kern, err := core.NewKernel(conf.BurrowDir)
if err != nil {
output.Fatalf("could not create Burrow kernel: %w", err)
}
if err = kern.LoadLoggerFromConfig(conf.Logging); err != nil {
output.Fatalf("could not load logger: %w", err)
}
if err = kern.LoadDump(conf.GenesisDoc, *filename, *silentOpt); err != nil {
output.Fatalf("could not load dump: %v", err)
}
kern.ShutdownAndExit()
}
}
}