github.com/aergoio/aergo@v1.3.1/config/config.go (about)

     1  /**
     2   *  @file
     3   *  @copyright defined in aergo/LICENSE.txt
     4   */
     5  
     6  package config
     7  
     8  import (
     9  	"runtime"
    10  
    11  	"github.com/aergoio/aergo/types"
    12  
    13  	"github.com/aergoio/aergo-lib/config"
    14  	//	"github.com/aergoio/aergo/types"
    15  )
    16  
    17  type ServerContext struct {
    18  	config.BaseContext
    19  }
    20  
    21  func NewServerContext(homePath string, configFilePath string) *ServerContext {
    22  	serverCxt := &ServerContext{}
    23  	serverCxt.BaseContext = config.NewBaseContext(serverCxt, homePath, configFilePath, EnvironmentPrefix)
    24  	serverCxt.Vc.SetDefault("blockchain.zerofee", serverCxt.GetDefaultBlockchainConfig().ZeroFee)
    25  	serverCxt.Vc.SetDefault("sql.maxdbsize", serverCxt.GetDefaultSQLConfig().MaxDbSize)
    26  	return serverCxt
    27  }
    28  
    29  func (ctx *ServerContext) GetHomePath() string {
    30  	return defaultAergoHomePath
    31  }
    32  
    33  func (ctx *ServerContext) GetConfigFileName() string {
    34  	return defaultAergoConfigFileName
    35  }
    36  
    37  func (ctx *ServerContext) GetTemplate() string {
    38  	return tomlConfigFileTemplate
    39  }
    40  
    41  func (ctx *ServerContext) GetDefaultConfig() interface{} {
    42  	return &Config{
    43  		BaseConfig: ctx.GetDefaultBaseConfig(),
    44  		RPC:        ctx.GetDefaultRPCConfig(),
    45  		P2P:        ctx.GetDefaultP2PConfig(),
    46  		Blockchain: ctx.GetDefaultBlockchainConfig(),
    47  		Mempool:    ctx.GetDefaultMempoolConfig(),
    48  		Consensus:  ctx.GetDefaultConsensusConfig(),
    49  		Monitor:    ctx.GetDefaultMonitorConfig(),
    50  		Account:    ctx.GetDefaultAccountConfig(),
    51  		Auth:       ctx.GetDefaultAuthConfig(),
    52  		Polaris:    ctx.GetDefaultPolarisConfig(),
    53  		SQL:        ctx.GetDefaultSQLConfig(),
    54  	}
    55  }
    56  
    57  func (ctx *ServerContext) GetDefaultBaseConfig() BaseConfig {
    58  	return BaseConfig{
    59  		DataDir:        ctx.ExpandPathEnv("$HOME/data"),
    60  		DbType:         "badgerdb",
    61  		EnableProfile:  false,
    62  		ProfilePort:    6060,
    63  		EnableTestmode: false,
    64  		Personal:       true,
    65  		AuthDir:        ctx.ExpandPathEnv("$HOME/auth"),
    66  	}
    67  }
    68  
    69  func (ctx *ServerContext) GetDefaultRPCConfig() *RPCConfig {
    70  	return &RPCConfig{
    71  		NetServiceAddr:  "127.0.0.1",
    72  		NetServicePort:  7845,
    73  		NetServiceTrace: false,
    74  		NSKey:           "",
    75  	}
    76  }
    77  
    78  func (ctx *ServerContext) GetDefaultP2PConfig() *P2PConfig {
    79  	return &P2PConfig{
    80  		NetProtocolAddr: "",
    81  		NetProtocolPort: 7846,
    82  		NPBindAddr:      "",
    83  		NPBindPort:      -1,
    84  		NPEnableTLS:     false,
    85  		NPCert:          "",
    86  		NPKey:           "",
    87  		NPAddPeers:      nil,
    88  		NPDiscoverPeers: true,
    89  		NPMaxPeers:      100,
    90  		NPPeerPool:      100,
    91  		NPUsePolaris:    true,
    92  		NPExposeSelf:    true,
    93  	}
    94  }
    95  
    96  func (ctx *ServerContext) GetDefaultAuthConfig() *AuthConfig {
    97  	return &AuthConfig{
    98  		EnableLocalConf: false,
    99  	}
   100  }
   101  
   102  func (ctx *ServerContext) GetDefaultPolarisConfig() *PolarisConfig {
   103  	return &PolarisConfig{
   104  		GenesisFile:     "",
   105  		AllowPrivate:    false,
   106  		EnableBlacklist: true,
   107  	}
   108  }
   109  
   110  func (ctx *ServerContext) GetDefaultBlockchainConfig() *BlockchainConfig {
   111  	return &BlockchainConfig{
   112  		MaxBlockSize:     types.DefaultMaxBlockSize,
   113  		CoinbaseAccount:  "",
   114  		MaxAnchorCount:   20,
   115  		VerifierCount:    types.DefaultVerifierCnt,
   116  		ForceResetHeight: 0,
   117  		ZeroFee:          true,
   118  		StateTrace:       0,
   119  	}
   120  }
   121  
   122  func (ctx *ServerContext) GetDefaultMempoolConfig() *MempoolConfig {
   123  	return &MempoolConfig{
   124  		ShowMetrics:    false,
   125  		EnableFadeout:  false,
   126  		FadeoutPeriod:  types.DefaultEvictPeriod,
   127  		VerifierNumber: runtime.NumCPU(),
   128  		DumpFilePath:   ctx.ExpandPathEnv("$HOME/mempool.dump"),
   129  	}
   130  }
   131  
   132  func (ctx *ServerContext) GetDefaultConsensusConfig() *ConsensusConfig {
   133  	return &ConsensusConfig{
   134  		BlockInterval: 1,
   135  	}
   136  }
   137  
   138  func (ctx *ServerContext) GetDefaultMonitorConfig() *MonitorConfig {
   139  	return &MonitorConfig{
   140  		ServerProtocol: "",
   141  		ServerEndpoint: "",
   142  	}
   143  }
   144  
   145  func (ctx *ServerContext) GetDefaultAccountConfig() *AccountConfig {
   146  	return &AccountConfig{
   147  		UnlockTimeout: 60,
   148  	}
   149  }
   150  
   151  func (ctx *ServerContext) GetDefaultSQLConfig() *SQLConfig {
   152  	return &SQLConfig{
   153  		MaxDbSize: 20,
   154  	}
   155  }