forked from hyperledger-archives/burrow
/
restore.go
54 lines (40 loc) · 1.52 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
45
46
47
48
49
50
51
52
53
54
package commands
import (
"github.com/hyperledger/burrow/core"
cli "github.com/jawher/mow.cli"
)
func Restore(output Output) func(cmd *cli.Cmd) {
return func(cmd *cli.Cmd) {
genesisOpt := cmd.StringOpt("g genesis", "",
"Use the specified genesis JSON file rather than a key in the main config, use - to read from STDIN")
configOpt := cmd.StringOpt("c config", "", "Use the specified burrow config file")
filename := cmd.StringArg("FILE", "", "Restore from this dump")
cmd.Spec = "[--config=<config file>] [--genesis=<genesis json file>] [FILE]"
configOpts := addConfigOptions(cmd)
cmd.Action = func() {
conf, err := obtainBurrowConfig(*configOpt, *genesisOpt)
if err != nil {
output.Fatalf("could not obtain config: %v", err)
}
err = configOpts.configure(conf)
if err != nil {
output.Fatalf("could not update burrow config: %v", err)
}
if conf.ValidatorAddress == nil {
output.Fatalf("could not finalise validator address - please provide one in config or via --validator-address")
}
output.Logf("Using validator address: %s", *conf.ValidatorAddress)
kern, err := core.NewKernel(conf.BurrowDir)
if err != nil {
output.Fatalf("could not create Burrow kernel: %v", err)
}
if err = kern.LoadLoggerFromConfig(conf.Logging); err != nil {
output.Fatalf("could not create Burrow kernel: %v", err)
}
if err = kern.LoadDump(conf.GenesisDoc, *filename); err != nil {
output.Fatalf("could not create Burrow kernel: %v", err)
}
kern.ShutdownAndExit()
}
}
}