mirror of
https://github.com/status-im/status-go.git
synced 2025-02-18 01:37:22 +00:00
This PR refactors CLI API, removes obsolete commands and splits status code into smaller pieces: * get rid of subcommands API (no ./status <command>) * get rid of custom cli app package * use stdlib flag package for handling command line flags * move cross-compilation / mobile related code to lib/ package * move wnode command into separate binary (cmd/node-status, name is subject to discuss) * remove faucet command as obsolete * update/add docs/READMES/wikis for new command line flags It makes statusd code much simpler and smaller, separates concerns (lib, wnode and statusd are different things).
114 lines
3.1 KiB
Go
114 lines
3.1 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"path/filepath"
|
|
|
|
"github.com/status-im/status-go/geth/params"
|
|
)
|
|
|
|
// makeNodeConfig creates node configuration object from flags
|
|
func makeNodeConfig() (*params.NodeConfig, error) {
|
|
devMode := !*prodMode
|
|
nodeConfig, err := params.NewNodeConfig(*dataDir, uint64(*networkID), devMode)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// TODO(divan): move this logic into params package?
|
|
if *nodeKeyFile != "" {
|
|
nodeConfig.NodeKeyFile = *nodeKeyFile
|
|
}
|
|
|
|
// disable log
|
|
nodeConfig.LogLevel = "CRIT"
|
|
nodeConfig.LogFile = ""
|
|
|
|
// disable les and swarm for wnode
|
|
nodeConfig.LightEthConfig.Enabled = false
|
|
nodeConfig.SwarmConfig.Enabled = false
|
|
|
|
nodeConfig.RPCEnabled = *httpEnabled
|
|
|
|
// whisper configuration
|
|
whisperConfig := nodeConfig.WhisperConfig
|
|
|
|
whisperConfig.Enabled = true
|
|
whisperConfig.IdentityFile = *identity
|
|
whisperConfig.PasswordFile = *password
|
|
whisperConfig.EchoMode = *echo
|
|
whisperConfig.BootstrapNode = *bootstrap
|
|
whisperConfig.ForwarderNode = *forward
|
|
whisperConfig.NotificationServerNode = *notify
|
|
whisperConfig.MailServerNode = *mailserver
|
|
whisperConfig.Port = *port
|
|
whisperConfig.TTL = *ttl
|
|
whisperConfig.MinimumPoW = *pow
|
|
|
|
if whisperConfig.MailServerNode && whisperConfig.PasswordFile == "" {
|
|
return nil, errors.New("mail server requires -password to be specified")
|
|
}
|
|
|
|
if whisperConfig.NotificationServerNode && whisperConfig.IdentityFile == "" {
|
|
return nil, errors.New("notification server requires either -identity file to be specified")
|
|
}
|
|
|
|
if whisperConfig.PasswordFile != "" {
|
|
if err := verifyPasswordFile(whisperConfig); err != nil {
|
|
return nil, fmt.Errorf("read password file: %v", err)
|
|
}
|
|
}
|
|
|
|
if whisperConfig.IdentityFile != "" {
|
|
if err := verifyIdentityFile(whisperConfig); err != nil {
|
|
return nil, fmt.Errorf("read identity file: %v", err)
|
|
}
|
|
}
|
|
|
|
// firebase configuration
|
|
firebaseConfig := whisperConfig.FirebaseConfig
|
|
firebaseConfig.AuthorizationKeyFile = *firebaseAuth
|
|
if len(firebaseConfig.AuthorizationKeyFile) > 0 { // make sure authorization key can be loaded
|
|
if firebaseConfig.AuthorizationKeyFile, err = filepath.Abs(firebaseConfig.AuthorizationKeyFile); err != nil {
|
|
return nil, err
|
|
}
|
|
if _, err := firebaseConfig.ReadAuthorizationKeyFile(); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
// RPC configuration
|
|
if !*httpEnabled {
|
|
nodeConfig.HTTPHost = "" // HTTP RPC is disabled
|
|
}
|
|
nodeConfig.HTTPPort = *httpPort
|
|
nodeConfig.IPCEnabled = *ipcEnabled
|
|
|
|
return nodeConfig, nil
|
|
}
|
|
|
|
// verifyPasswordFile verifies that we can load password file
|
|
func verifyPasswordFile(config *params.WhisperConfig) error {
|
|
// TODO(divan): why do we need it here?
|
|
absPath, err := filepath.Abs(config.PasswordFile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
config.PasswordFile = absPath
|
|
_, err = config.ReadPasswordFile()
|
|
return err
|
|
}
|
|
|
|
// verifyIdentityFile verifies that we can load identity file
|
|
func verifyIdentityFile(config *params.WhisperConfig) error {
|
|
// TODO(divan): why do we need it here?
|
|
absPath, err := filepath.Abs(config.IdentityFile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
config.IdentityFile = absPath
|
|
_, err = config.ReadIdentityFile()
|
|
return err
|
|
}
|