Skip to content

Commit 8e84738

Browse files
committed
change part of the code structure
* change global conf struct and rename struct * upd mod file * rm unused code * add tool blockid
1 parent 3101b5f commit 8e84738

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1166
-1455
lines changed

build.sh

100644100755
File mode changed.

cmd/config.go

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var configCmd = &cobra.Command{
3131
}
3232

3333
if configPath == "" {
34-
configPath = filepath.Join(conf.Config.DataDir, consts.DefaultConfigFile)
34+
configPath = filepath.Join(conf.Config.DirPathConf.DataDir, consts.DefaultConfigFile)
3535
}
3636
err = viper.Unmarshal(&conf.Config)
3737
if err != nil {
@@ -52,6 +52,32 @@ func init() {
5252
// Command flags
5353
cmdFlags.String("path", "", "Generate config to (default dataDir/config.toml)")
5454

55+
// Etc
56+
cmdFlags.StringVar(&conf.Config.DirPathConf.PidFilePath, "pid", "",
57+
fmt.Sprintf("ibax pid file name (default dataDir/%s)", consts.DefaultPidFilename),
58+
)
59+
cmdFlags.StringVar(&conf.Config.DirPathConf.LockFilePath, "lock", "",
60+
fmt.Sprintf("ibax lock file name (default dataDir/%s)", consts.DefaultLockFilename),
61+
)
62+
cmdFlags.StringVar(&conf.Config.DirPathConf.KeysDir, "keysDir", "", "Keys directory (default dataDir)")
63+
cmdFlags.StringVar(&conf.Config.DirPathConf.DataDir, "dataDir", "", "Data directory (default cwd/data)")
64+
cmdFlags.StringVar(&conf.Config.DirPathConf.TempDir, "tempDir", "", "Temporary directory (default temporary directory of OS)")
65+
cmdFlags.StringVar(&conf.Config.DirPathConf.FirstBlockPath, "firstBlock", "", "First block path (default dataDir/1block)")
66+
67+
// tls
68+
cmdFlags.BoolVar(&conf.Config.TLSConf.Enabled, "tlsEnable", false, "Enable https")
69+
cmdFlags.StringVar(&conf.Config.TLSConf.TLSCert, "tlsCert", "", "Filepath to the fullchain of certificates")
70+
cmdFlags.StringVar(&conf.Config.TLSConf.TLSKey, "tlsKey", "", "Filepath to the private key")
71+
72+
//Bootstrap
73+
cmdFlags.StringSliceVar(&conf.Config.BootNodes.NodesAddr, "bootNodes", []string{}, "List of addresses for downloading blockchain")
74+
75+
//LocalConf
76+
cmdFlags.Int64Var(&conf.Config.LocalConf.MaxPageGenerationTime, "mpgt", 3000, "Max page generation time in ms")
77+
cmdFlags.Int64Var(&conf.Config.LocalConf.HTTPServerMaxBodySize, "mbs", 1<<20, "Max server body size in byte")
78+
cmdFlags.Int64Var(&conf.Config.LocalConf.NetworkID, "networkID", 1, "Network ID")
79+
cmdFlags.StringVar(&conf.Config.LocalConf.RunNodeMode, "runMode", consts.NoneOBS, "running node mode, example NONE|OBS|OBSMaster|SubNode")
80+
5581
// TCP Server
5682
cmdFlags.StringVar(&conf.Config.TCPServer.Host, "tcpHost", "127.0.0.1", "Node TCP host")
5783
cmdFlags.IntVar(&conf.Config.TCPServer.Port, "tcpPort", 7078, "Node TCP port")
@@ -72,11 +98,11 @@ func init() {
7298
cmdFlags.IntVar(&conf.Config.DB.MaxOpenConns, "dbMaxOpenConns", 100, "sets the maximum number of open connections to the database")
7399

74100
//Redis
75-
cmdFlags.BoolVar(&conf.Config.Redis.Enable, "redisenable", false, "enable redis")
76-
cmdFlags.StringVar(&conf.Config.Redis.Host, "redishost", "localhost", "redis host")
77-
cmdFlags.StringVar(&conf.Config.Redis.Port, "redisport", "6379", "redis port")
78-
cmdFlags.IntVar(&conf.Config.Redis.DbName, "redisdb", 0, "redis db")
79-
cmdFlags.StringVar(&conf.Config.Redis.Password, "redispassword", "123456", "redis password")
101+
cmdFlags.BoolVar(&conf.Config.Redis.Enable, "redisEnable", false, "enable redis")
102+
cmdFlags.StringVar(&conf.Config.Redis.Host, "redisHost", "localhost", "redis host")
103+
cmdFlags.IntVar(&conf.Config.Redis.Port, "redisPort", 6379, "redis port")
104+
cmdFlags.IntVar(&conf.Config.Redis.DbName, "redisDb", 0, "redis db")
105+
cmdFlags.StringVar(&conf.Config.Redis.Password, "redisPassword", "123456", "redis password")
80106

81107
// StatsD
82108
cmdFlags.StringVar(&conf.Config.StatsD.Host, "statsdHost", "127.0.0.1", "StatsD host")
@@ -108,29 +134,9 @@ func init() {
108134
cmdFlags.IntVar(&conf.Config.BanKey.BanTime, "banTime", 15, "Ban time in minutes")
109135
cmdFlags.IntVar(&conf.Config.BanKey.BadTx, "badTx", 5, "Maximum bad tx during badTime minutes")
110136

111-
// Etc
112-
cmdFlags.StringVar(&conf.Config.PidFilePath, "pid", "",
113-
fmt.Sprintf("ibax pid file name (default dataDir/%s)", consts.DefaultPidFilename),
114-
)
115-
cmdFlags.StringVar(&conf.Config.LockFilePath, "lock", "",
116-
fmt.Sprintf("ibax lock file name (default dataDir/%s)", consts.DefaultLockFilename),
117-
)
118-
cmdFlags.StringVar(&conf.Config.KeysDir, "keysDir", "", "Keys directory (default dataDir)")
119-
cmdFlags.StringVar(&conf.Config.DataDir, "dataDir", "", "Data directory (default cwd/data)")
120-
cmdFlags.StringVar(&conf.Config.TempDir, "tempDir", "", "Temporary directory (default temporary directory of OS)")
121-
cmdFlags.StringVar(&conf.Config.FirstBlockPath, "firstBlock", "", "First block path (default dataDir/1block)")
122-
cmdFlags.BoolVar(&conf.Config.TLS, "tls", false, "Enable https")
123-
cmdFlags.StringVar(&conf.Config.TLSCert, "tls-cert", "", "Filepath to the fullchain of certificates")
124-
cmdFlags.StringVar(&conf.Config.TLSKey, "tls-key", "", "Filepath to the private key")
125-
cmdFlags.Int64Var(&conf.Config.MaxPageGenerationTime, "mpgt", 3000, "Max page generation time in ms")
126-
cmdFlags.Int64Var(&conf.Config.HTTPServerMaxBodySize, "mbs", 1<<20, "Max server body size in byte")
127-
cmdFlags.StringSliceVar(&conf.Config.NodesAddr, "nodesAddr", []string{}, "List of addresses for downloading blockchain")
128-
cmdFlags.Int64Var(&conf.Config.NetworkID, "networkID", 1, "Network ID")
129-
cmdFlags.StringVar(&conf.Config.OBSMode, "obsMode", consts.NoneOBS, "OBS running mode")
130-
131-
// GFiles
132-
cmdFlags.BoolVar(&conf.Config.GFiles.GFiles, "gfs", false, "Enable GFiles")
133-
cmdFlags.StringVar(&conf.Config.GFiles.Host, "gFilesHost", "127.0.0.1:5001", "GFiles host")
137+
// IPFS
138+
cmdFlags.BoolVar(&conf.Config.IpfsConf.Enabled, "ipfsEnable", false, "Enable IPFS")
139+
cmdFlags.StringVar(&conf.Config.IpfsConf.Host, "ipfsHost", "127.0.0.1:5001", "IPFS host")
134140

135141
// CryptoSettings
136142
cmdFlags.StringVar(&conf.Config.CryptoSettings.Hasher, "hasher", "SHA256", "Hash Algorithm")

cmd/generateFirstBlock.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"github.com/IBAX-io/go-ibax/packages/converter"
2020
"github.com/IBAX-io/go-ibax/packages/crypto"
2121
"github.com/IBAX-io/go-ibax/packages/types"
22-
"github.com/IBAX-io/go-ibax/packages/utils"
2322

2423
log "github.com/sirupsen/logrus"
2524
)
@@ -38,7 +37,7 @@ var generateFirstBlockCmd = &cobra.Command{
3837
if err != nil {
3938
log.WithFields(log.Fields{"type": consts.MarshallingError, "error": err}).Fatal("first block marshalling")
4039
}
41-
os.WriteFile(conf.Config.FirstBlockPath, block, 0644)
40+
os.WriteFile(conf.Config.DirPathConf.FirstBlockPath, block, 0644)
4241
log.Info("first block generated")
4342
},
4443
}
@@ -51,7 +50,7 @@ func init() {
5150

5251
func genesisBlock() ([]byte, error) {
5352
now := time.Now().Unix()
54-
header := &utils.BlockData{
53+
header := &types.BlockData{
5554
BlockID: 1,
5655
Time: now,
5756
EcosystemID: 0,
@@ -61,7 +60,7 @@ func genesisBlock() ([]byte, error) {
6160
}
6261

6362
decodeKeyFile := func(kName string) []byte {
64-
filepath := filepath.Join(conf.Config.KeysDir, kName)
63+
filepath := filepath.Join(conf.Config.DirPathConf.KeysDir, kName)
6564
data, err := os.ReadFile(filepath)
6665
if err != nil {
6766
log.WithError(err).WithFields(log.Fields{"key": kName, "filepath": filepath}).Fatal("Reading key data")
@@ -78,7 +77,7 @@ func genesisBlock() ([]byte, error) {
7877
var stopNetworkCert []byte
7978
if len(stopNetworkBundleFilepath) > 0 {
8079
var err error
81-
fp := filepath.Join(conf.Config.KeysDir, stopNetworkBundleFilepath)
80+
fp := filepath.Join(conf.Config.DirPathConf.KeysDir, stopNetworkBundleFilepath)
8281
if stopNetworkCert, err = os.ReadFile(fp); err != nil {
8382
log.WithError(err).WithFields(log.Fields{"filepath": fp}).Fatal("Reading cert data")
8483
}
@@ -116,7 +115,7 @@ func genesisBlock() ([]byte, error) {
116115
log.WithFields(log.Fields{"type": consts.MarshallingError, "error": err}).Fatal("first block body bin marshalling")
117116
}
118117

119-
return block.MarshallBlock(header, [][]byte{tx}, &utils.BlockData{
118+
return block.MarshallBlock(header, [][]byte{tx}, &types.BlockData{
120119
Hash: []byte(`0`),
121120
RollbacksHash: []byte(`0`),
122121
}, "")

cmd/generateKeys.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import (
1111
"path/filepath"
1212
"strconv"
1313

14-
"github.com/pkg/errors"
15-
log "github.com/sirupsen/logrus"
16-
"github.com/spf13/cobra"
1714
"github.com/IBAX-io/go-ibax/packages/conf"
1815
"github.com/IBAX-io/go-ibax/packages/consts"
1916
"github.com/IBAX-io/go-ibax/packages/crypto"
17+
"github.com/pkg/errors"
18+
log "github.com/sirupsen/logrus"
19+
"github.com/spf13/cobra"
2020
)
2121

2222
const fileMode = 0600
@@ -28,23 +28,23 @@ var generateKeysCmd = &cobra.Command{
2828
PreRun: loadConfig,
2929
Run: func(cmd *cobra.Command, args []string) {
3030
_, publicKey, err := createKeyPair(
31-
filepath.Join(conf.Config.KeysDir, consts.PrivateKeyFilename),
32-
filepath.Join(conf.Config.KeysDir, consts.PublicKeyFilename),
31+
filepath.Join(conf.Config.DirPathConf.KeysDir, consts.PrivateKeyFilename),
32+
filepath.Join(conf.Config.DirPathConf.KeysDir, consts.PublicKeyFilename),
3333
)
3434
if err != nil {
3535
log.WithFields(log.Fields{"error": err}).Fatal("generating user keys")
3636
return
3737
}
3838
_, _, err = createKeyPair(
39-
filepath.Join(conf.Config.KeysDir, consts.NodePrivateKeyFilename),
40-
filepath.Join(conf.Config.KeysDir, consts.NodePublicKeyFilename),
39+
filepath.Join(conf.Config.DirPathConf.KeysDir, consts.NodePrivateKeyFilename),
40+
filepath.Join(conf.Config.DirPathConf.KeysDir, consts.NodePublicKeyFilename),
4141
)
4242
if err != nil {
4343
log.WithFields(log.Fields{"error": err}).Fatal("generating node keys")
4444
return
4545
}
4646
address := crypto.Address(publicKey)
47-
keyIDPath := filepath.Join(conf.Config.KeysDir, consts.KeyIDFilename)
47+
keyIDPath := filepath.Join(conf.Config.DirPathConf.KeysDir, consts.KeyIDFilename)
4848
err = createFile(keyIDPath, []byte(strconv.FormatInt(address, 10)))
4949
if err != nil {
5050
log.WithFields(log.Fields{"error": err, "path": keyIDPath}).Fatal("generating node keys")

cmd/rollback.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,10 @@ var rollbackCmd = &cobra.Command{
2525
Short: "Rollback blockchain to blockID",
2626
PreRun: loadConfigWKey,
2727
Run: func(cmd *cobra.Command, args []string) {
28-
f := utils.LockOrDie(conf.Config.LockFilePath)
28+
f := utils.LockOrDie(conf.Config.DirPathConf.LockFilePath)
2929
defer f.Unlock()
3030

31-
if err := model.GormInit(
32-
conf.Config.DB.Host,
33-
conf.Config.DB.Port,
34-
conf.Config.DB.User,
35-
conf.Config.DB.Password,
36-
conf.Config.DB.Name,
37-
); err != nil {
31+
if err := model.GormInit(conf.Config.DB); err != nil {
3832
log.WithError(err).Fatal("init db")
3933
return
4034
}

cmd/stopNetwork.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var stopNetworkCmd = &cobra.Command{
2929
Short: "Sending a special transaction to stop the network",
3030
PreRun: loadConfigWKey,
3131
Run: func(cmd *cobra.Command, args []string) {
32-
fp := filepath.Join(conf.Config.KeysDir, stopNetworkCertFilepath)
32+
fp := filepath.Join(conf.Config.DirPathConf.KeysDir, stopNetworkCertFilepath)
3333
stopNetworkCert, err := os.ReadFile(fp)
3434
if err != nil {
3535
log.WithFields(log.Fields{"error": err, "type": consts.IOError, "filepath": fp}).Fatal("Reading cert data")

0 commit comments

Comments
 (0)