-
Notifications
You must be signed in to change notification settings - Fork 119
/
sifgen.go
83 lines (69 loc) · 1.84 KB
/
sifgen.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
package sifgen
import (
"fmt"
"io/ioutil"
"log"
"github.com/MakeNowJust/heredoc"
"github.com/Sifchain/sifnode/tools/sifgen/key"
"github.com/Sifchain/sifnode/tools/sifgen/network"
"github.com/Sifchain/sifnode/tools/sifgen/node"
"github.com/Sifchain/sifnode/tools/sifgen/utils"
)
type Sifgen struct {
chainID *string
}
func NewSifgen(chainID *string) Sifgen {
return Sifgen{
chainID: chainID,
}
}
func (s Sifgen) NewNetwork(keyringBackend string) *network.Network {
return &network.Network{
ChainID: *s.chainID,
CLI: utils.NewCLI(*s.chainID, keyringBackend),
}
}
func (s Sifgen) NetworkCreate(count int, outputDir, startingIPAddress string, outputFile string) {
net := network.NewNetwork(*s.chainID)
summary, err := net.Build(count, outputDir, startingIPAddress)
if err != nil {
log.Fatal(err)
return
}
if err = ioutil.WriteFile(outputFile, []byte(*summary), 0600); err != nil {
log.Fatal(err)
return
}
}
func (s Sifgen) NetworkReset(networkDir string) {
if err := network.Reset(*s.chainID, networkDir); err != nil {
log.Fatal(err)
}
}
func (s Sifgen) NewNode(keyringBackend string) *node.Node {
return &node.Node{
ChainID: *s.chainID,
CLI: utils.NewCLI(*s.chainID, keyringBackend),
}
}
func (s Sifgen) NodeReset(nodeHomeDir *string) {
if err := node.Reset(*s.chainID, nodeHomeDir); err != nil {
log.Fatal(err)
}
}
func (s Sifgen) KeyGenerateMnemonic(name, password string) {
newKey := key.NewKey(name, password)
newKey.GenerateMnemonic()
fmt.Println(newKey.Mnemonic)
}
func (s Sifgen) KeyRecoverFromMnemonic(mnemonic string) {
newKey := key.NewKey("", "")
if err := newKey.RecoverFromMnemonic(mnemonic); err != nil {
log.Fatal(err)
}
fmt.Println(heredoc.Doc(`
Address: ` + newKey.Address + `
Validator Address: ` + newKey.ValidatorAddress + `
Consensus Address: ` + newKey.ConsensusAddress + `
`))
}