-
Notifications
You must be signed in to change notification settings - Fork 92
/
util.go
90 lines (79 loc) · 1.72 KB
/
util.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2017 Factom Foundation
// Use of this source code is governed by the MIT license
// that can be found in the LICENSE file.
package main
import (
"fmt"
"os"
"github.com/FactomProject/factomd/common/interfaces"
. "github.com/FactomProject/factomd/database/blockExtractor"
"github.com/FactomProject/factomd/state"
"github.com/FactomProject/factomd/util"
)
const level string = "level"
const bolt string = "bolt"
func main() {
fmt.Println("Usage:")
fmt.Println("BlockExtractor level/bolt [ChainID-To-Extract]")
fmt.Println("Leave out the last one to export basic chains (A, D, EC, F)")
if len(os.Args) < 1 {
fmt.Println("\nNot enough arguments passed")
os.Exit(1)
}
if len(os.Args) > 2 {
fmt.Println("\nToo many arguments passed")
os.Exit(1)
}
levelBolt := os.Args[1]
if levelBolt != level && levelBolt != bolt {
fmt.Println("\nFirst argument should be `level` or `bolt`")
os.Exit(1)
}
chainID := ""
if len(os.Args) == 3 {
chainID = os.Args[2]
}
be := new(BlockExtractor)
state := new(state.State)
state.Cfg = util.ReadConfig("")
if levelBolt == level {
err := state.InitLevelDB()
if err != nil {
panic(err)
}
}
if levelBolt == bolt {
err := state.InitBoltDB()
if err != nil {
panic(err)
}
}
dbo := state.GetDB().(interfaces.DBOverlay)
if chainID != "" {
err := be.ExportEChain(chainID, dbo)
if err != nil {
panic(err)
}
} else {
err := be.ExportDChain(dbo)
if err != nil {
panic(err)
}
err = be.ExportECChain(dbo)
if err != nil {
panic(err)
}
err = be.ExportAChain(dbo)
if err != nil {
panic(err)
}
err = be.ExportFctChain(dbo)
if err != nil {
panic(err)
}
err = be.ExportDirBlockInfo(dbo)
if err != nil {
panic(err)
}
}
}