-
Notifications
You must be signed in to change notification settings - Fork 52
/
config.go
139 lines (128 loc) · 4.27 KB
/
config.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package config
import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"math/big"
"os"
"time"
)
const (
DefaultConfigFilename = "./config.json"
MINGENBLOCKTIME = 2
DEFAULTGENBLOCKTIME = 6
)
var (
Parameters configParams
Version string
mainNet = &ChainParams{
Name: "MainNet",
PowLimit: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 255), big.NewInt(1)),
PowLimitBits: 0x1f0008ff,
TargetTimespan: time.Second * 60 * 2 * 720,
TargetTimePerBlock: time.Second * 60 * 2,
AdjustmentFactor: int64(4),
MaxOrphanBlocks: 10000,
MinMemoryNodes: 20160,
SpendCoinbaseSpan: 100,
}
testNet = &ChainParams{
Name: "TestNet",
PowLimit: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 255), big.NewInt(1)),
PowLimitBits: 0x1e1da5ff,
TargetTimespan: time.Second * 10 * 10,
TargetTimePerBlock: time.Second * 10,
AdjustmentFactor: int64(4),
MaxOrphanBlocks: 10000,
MinMemoryNodes: 20160,
SpendCoinbaseSpan: 100,
}
regNet = &ChainParams{
Name: "RegNet",
PowLimit: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 255), big.NewInt(1)),
PowLimitBits: 0x207fffff,
TargetTimespan: time.Second * 1 * 10,
TargetTimePerBlock: time.Second * 1,
AdjustmentFactor: int64(4),
MaxOrphanBlocks: 10000,
MinMemoryNodes: 20160,
SpendCoinbaseSpan: 100,
}
)
type PowConfiguration struct {
PayToAddr string `json:"PayToAddr"`
AutoMining bool `json:"AutoMining"`
MinerInfo string `json:"MinerInfo"`
MinTxFee int `json:"MinTxFee"`
ActiveNet string `json:"ActiveNet"`
}
type Configuration struct {
Magic uint32 `json:"Magic"`
Version int `json:"Version"`
SeedList []string `json:"SeedList"`
HttpRestPort int `json:"HttpRestPort"`
RestCertPath string `json:"RestCertPath"`
RestKeyPath string `json:"RestKeyPath"`
HttpInfoPort uint16 `json:"HttpInfoPort"`
HttpInfoStart bool `json:"HttpInfoStart"`
HttpWsPort int `json:"HttpWsPort"`
WsHeartbeatInterval time.Duration `json:"WsHeartbeatInterval"`
HttpJsonPort int `json:"HttpJsonPort"`
OauthServerUrl string `json:"OauthServerUrl"`
NoticeServerUrl string `json:"NoticeServerUrl"`
NodePort int `json:"NodePort"`
WebSocketPort int `json:"WebSocketPort"`
PrintLevel int `json:"PrintLevel"`
IsTLS bool `json:"IsTLS"`
CertPath string `json:"CertPath"`
KeyPath string `json:"KeyPath"`
CAPath string `json:"CAPath"`
MultiCoreNum uint `json:"MultiCoreNum"`
MaxLogSize int64 `json:"MaxLogSize"`
MaxTxInBlock int `json:"MaxTransactionInBlock"`
MaxBlockSize int `json:"MaxBlockSize"`
PowConfiguration PowConfiguration `json:"PowConfiguration"`
}
type ConfigFile struct {
ConfigFile Configuration `json:"Configuration"`
}
type ChainParams struct {
Name string
PowLimit *big.Int
PowLimitBits uint32
TargetTimespan time.Duration
TargetTimePerBlock time.Duration
AdjustmentFactor int64
MaxOrphanBlocks int
MinMemoryNodes uint32
SpendCoinbaseSpan uint32
}
type configParams struct {
*Configuration
ChainParam *ChainParams
}
func init() {
file, e := ioutil.ReadFile(DefaultConfigFilename)
if e != nil {
log.Fatalf("File error: %v\n", e)
os.Exit(1)
}
// Remove the UTF-8 Byte Order Mark
file = bytes.TrimPrefix(file, []byte("\xef\xbb\xbf"))
config := ConfigFile{}
e = json.Unmarshal(file, &config)
if e != nil {
log.Fatalf("Unmarshal json file erro %v", e)
os.Exit(1)
}
// Parameters = &(config.ConfigFile)
Parameters.Configuration = &(config.ConfigFile)
if Parameters.PowConfiguration.ActiveNet == "MainNet" {
Parameters.ChainParam = mainNet
} else if Parameters.PowConfiguration.ActiveNet == "TestNet" {
Parameters.ChainParam = testNet
} else if Parameters.PowConfiguration.ActiveNet == "RegNet" {
Parameters.ChainParam = regNet
}
}