-
Notifications
You must be signed in to change notification settings - Fork 0
/
params.go
99 lines (80 loc) · 1.75 KB
/
params.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
91
92
93
94
95
96
97
98
99
package quorum
import (
"errors"
"fmt"
"os"
"github.com/KalyCoinProject/kalychain/chain"
"github.com/KalyCoinProject/kalychain/command"
"github.com/KalyCoinProject/kalychain/command/helper"
"github.com/KalyCoinProject/kalychain/helper/common"
)
const (
fromFlag = "from"
chainFlag = "chain"
)
var (
params = &quorumParams{}
)
type quorumParams struct {
genesisConfig *chain.Chain
from uint64
genesisPath string
}
func (p *quorumParams) initChain() error {
cc, err := chain.Import(p.genesisPath)
if err != nil {
return fmt.Errorf(
"failed to load chain config from %s: %w",
p.genesisPath,
err,
)
}
p.genesisConfig = cc
return nil
}
func (p *quorumParams) initRawParams() error {
return p.initChain()
}
func (p *quorumParams) getRequiredFlags() []string {
return []string{
fromFlag,
}
}
func (p *quorumParams) updateGenesisConfig() error {
return appendIBFTQuorum(
p.genesisConfig,
p.from,
)
}
func (p *quorumParams) overrideGenesisConfig() error {
// Remove the current genesis configuration from disk
if err := os.Remove(p.genesisPath); err != nil {
return err
}
// Save the new genesis configuration
if err := helper.WriteGenesisConfigToDisk(
p.genesisConfig,
p.genesisPath,
); err != nil {
return err
}
return nil
}
func (p *quorumParams) getResult() command.CommandResult {
return &IBFTQuorumResult{
Chain: p.genesisPath,
From: common.JSONNumber{Value: p.from},
}
}
func appendIBFTQuorum(
cc *chain.Chain,
from uint64,
) error {
ibftConfig, ok := cc.Params.Engine["ibft"].(map[string]interface{})
if !ok {
return errors.New(`"ibft" setting doesn't exist in "engine" of genesis.json'`)
}
ibftConfig["quorumSizeBlockNum"] = from
cc.Params.Engine["ibft"] = ibftConfig
return nil
}