From 5a984fdf8886bcb41a2ec450c4f7535e2ee3669f Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 25 Mar 2020 18:30:21 +0300 Subject: [PATCH] config: move config.go out of config/ closes #423 --- cli/main.go | 2 +- cli/server/server.go | 2 +- config/config.go | 196 --------------------------- integration/performance_test.go | 2 +- pkg/config/application_config.go | 30 ++++ pkg/config/config.go | 58 ++++++++ pkg/config/protocol_config.go | 90 ++++++++++++ pkg/consensus/consensus.go | 3 +- pkg/consensus/consensus_test.go | 5 +- pkg/core/blockchain.go | 2 +- pkg/core/blockchainer.go | 2 +- pkg/core/helper_test.go | 2 +- pkg/core/util.go | 2 +- pkg/core/util_test.go | 2 +- pkg/network/helper_test.go | 2 +- pkg/network/message.go | 2 +- pkg/network/server_config.go | 7 +- pkg/rpc/rpc_config.go | 26 ++++ pkg/rpc/server/server.go | 7 +- pkg/rpc/server/server_helper_test.go | 2 +- pkg/wallet/wallet_config.go | 7 + 21 files changed, 234 insertions(+), 217 deletions(-) delete mode 100644 config/config.go create mode 100644 pkg/config/application_config.go create mode 100644 pkg/config/config.go create mode 100644 pkg/config/protocol_config.go create mode 100644 pkg/rpc/rpc_config.go create mode 100644 pkg/wallet/wallet_config.go diff --git a/cli/main.go b/cli/main.go index 45dbe7bff..c9f919a58 100644 --- a/cli/main.go +++ b/cli/main.go @@ -7,7 +7,7 @@ import ( "github.com/nspcc-dev/neo-go/cli/smartcontract" "github.com/nspcc-dev/neo-go/cli/vm" "github.com/nspcc-dev/neo-go/cli/wallet" - "github.com/nspcc-dev/neo-go/config" + "github.com/nspcc-dev/neo-go/pkg/config" "github.com/urfave/cli" ) diff --git a/cli/server/server.go b/cli/server/server.go index e3f1a5f3b..a4e0f0b96 100644 --- a/cli/server/server.go +++ b/cli/server/server.go @@ -6,7 +6,7 @@ import ( "os" "os/signal" - "github.com/nspcc-dev/neo-go/config" + "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/core" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/storage" diff --git a/config/config.go b/config/config.go deleted file mode 100644 index 177c500ef..000000000 --- a/config/config.go +++ /dev/null @@ -1,196 +0,0 @@ -package config - -import ( - "fmt" - "io/ioutil" - "os" - "time" - - "github.com/go-yaml/yaml" - "github.com/nspcc-dev/neo-go/pkg/core/storage" - "github.com/nspcc-dev/neo-go/pkg/core/transaction" - "github.com/nspcc-dev/neo-go/pkg/network/metrics" - "github.com/nspcc-dev/neo-go/pkg/util" - "github.com/pkg/errors" -) - -const ( - userAgentFormat = "/NEO-GO:%s/" - - // ModeMainNet contains magic code used in the NEO main official network. - ModeMainNet NetMode = 0x00746e41 // 7630401 - // ModeTestNet contains magic code used in the NEO testing network. - ModeTestNet NetMode = 0x74746e41 // 1953787457 - // ModePrivNet contains magic code usually used for NEO private networks. - ModePrivNet NetMode = 56753 // docker privnet - // ModeUnitTestNet is a stub magic code used for testing purposes. - ModeUnitTestNet NetMode = 0 -) - -var ( - // Version the version of the node, set at build time. - Version string -) - -type ( - // Config top level struct representing the config - // for the node. - Config struct { - ProtocolConfiguration ProtocolConfiguration `yaml:"ProtocolConfiguration"` - ApplicationConfiguration ApplicationConfiguration `yaml:"ApplicationConfiguration"` - } - - // ProtocolConfiguration represents the protocol config. - ProtocolConfiguration struct { - Magic NetMode `yaml:"Magic"` - AddressVersion byte `yaml:"AddressVersion"` - SecondsPerBlock int `yaml:"SecondsPerBlock"` - LowPriorityThreshold float64 `yaml:"LowPriorityThreshold"` - MaxTransactionsPerBlock int `yaml:"MaxTransactionsPerBlock"` - MemPoolSize int `yaml:"MemPoolSize"` - StandbyValidators []string `yaml:"StandbyValidators"` - SeedList []string `yaml:"SeedList"` - SystemFee SystemFee `yaml:"SystemFee"` - // Whether to verify received blocks. - VerifyBlocks bool `yaml:"VerifyBlocks"` - // Whether to verify transactions in received blocks. - VerifyTransactions bool `yaml:"VerifyTransactions"` - // FreeGasLimit is an amount of GAS which can be spent for free. - FreeGasLimit util.Fixed8 `yaml:"FreeGasLimit"` - // SaveStorageBatch enables storage batch saving before every persist. - SaveStorageBatch bool `yaml:"SaveStorageBatch"` - // Maximum number of low priority transactions accepted into block. - MaxFreeTransactionsPerBlock int `yaml:"MaxFreeTransactionsPerBlock"` - // Maximum size of low priority transaction in bytes. - MaxFreeTransactionSize int `yaml:"MaxFreeTransactionSize"` - // FeePerExtraByte sets the expected per-byte fee for - // transactions exceeding the MaxFreeTransactionSize. - FeePerExtraByte float64 `yaml:"FeePerExtraByte"` - } - - // SystemFee fees related to system. - SystemFee struct { - EnrollmentTransaction int64 `yaml:"EnrollmentTransaction"` - IssueTransaction int64 `yaml:"IssueTransaction"` - PublishTransaction int64 `yaml:"PublishTransaction"` - RegisterTransaction int64 `yaml:"RegisterTransaction"` - } - - // ApplicationConfiguration config specific to the node. - ApplicationConfiguration struct { - LogPath string `yaml:"LogPath"` - DBConfiguration storage.DBConfiguration `yaml:"DBConfiguration"` - Address string `yaml:"Address"` - NodePort uint16 `yaml:"NodePort"` - Relay bool `yaml:"Relay"` - DialTimeout time.Duration `yaml:"DialTimeout"` - ProtoTickInterval time.Duration `yaml:"ProtoTickInterval"` - PingInterval time.Duration `yaml:"PingInterval"` - PingTimeout time.Duration `yaml:"PingTimeout"` - MaxPeers int `yaml:"MaxPeers"` - AttemptConnPeers int `yaml:"AttemptConnPeers"` - MinPeers int `yaml:"MinPeers"` - Prometheus metrics.Config `yaml:"Prometheus"` - Pprof metrics.Config `yaml:"Pprof"` - RPC RPCConfig `yaml:"RPC"` - UnlockWallet WalletConfig `yaml:"UnlockWallet"` - } - - // WalletConfig is a wallet info. - WalletConfig struct { - Path string `yaml:"Path"` - Password string `yaml:"Password"` - } - - // RPCConfig is an RPC service configuration information (to be moved to the rpc package, see #423). - RPCConfig struct { - Enabled bool `yaml:"Enabled"` - EnableCORSWorkaround bool `yaml:"EnableCORSWorkaround"` - Address string `yaml:"Address"` - Port uint16 `yaml:"Port"` - // MaxGasInvoke is a maximum amount of gas which - // can be spent during RPC call. - MaxGasInvoke util.Fixed8 `yaml:"MaxGasInvoke"` - TLSConfig TLSConfig `yaml:"TLSConfig"` - } - - // TLSConfig describes SSL/TLS configuration. - TLSConfig struct { - Enabled bool `yaml:"Enabled"` - Address string `yaml:"Address"` - Port uint16 `yaml:"Port"` - CertFile string `yaml:"CertFile"` - KeyFile string `yaml:"KeyFile"` - } - - // NetMode describes the mode the blockchain will operate on. - NetMode uint32 -) - -// String implements the stringer interface. -func (n NetMode) String() string { - switch n { - case ModePrivNet: - return "privnet" - case ModeTestNet: - return "testnet" - case ModeMainNet: - return "mainnet" - case ModeUnitTestNet: - return "unit_testnet" - default: - return "net unknown" - } -} - -// GenerateUserAgent creates user agent string based on build time environment. -func (c Config) GenerateUserAgent() string { - return fmt.Sprintf(userAgentFormat, Version) -} - -// Load attempts to load the config from the given -// path for the given netMode. -func Load(path string, netMode NetMode) (Config, error) { - configPath := fmt.Sprintf("%s/protocol.%s.yml", path, netMode) - if _, err := os.Stat(configPath); os.IsNotExist(err) { - return Config{}, errors.Wrap(err, "Unable to load config") - } - - configData, err := ioutil.ReadFile(configPath) - if err != nil { - return Config{}, errors.Wrap(err, "Unable to read config") - } - - config := Config{ - ProtocolConfiguration: ProtocolConfiguration{ - SystemFee: SystemFee{}, - }, - ApplicationConfiguration: ApplicationConfiguration{ - PingInterval: 30, - PingTimeout: 90, - }, - } - - err = yaml.Unmarshal(configData, &config) - if err != nil { - return Config{}, errors.Wrap(err, "Problem unmarshaling config json data") - } - - return config, nil -} - -// TryGetValue returns the system fee base on transaction type. -func (s SystemFee) TryGetValue(txType transaction.TXType) util.Fixed8 { - switch txType { - case transaction.EnrollmentType: - return util.Fixed8FromInt64(s.EnrollmentTransaction) - case transaction.IssueType: - return util.Fixed8FromInt64(s.IssueTransaction) - case transaction.PublishType: - return util.Fixed8FromInt64(s.PublishTransaction) - case transaction.RegisterType: - return util.Fixed8FromInt64(s.RegisterTransaction) - default: - return util.Fixed8FromInt64(0) - } -} diff --git a/integration/performance_test.go b/integration/performance_test.go index e3a4ba329..1c65ab4bb 100644 --- a/integration/performance_test.go +++ b/integration/performance_test.go @@ -4,7 +4,7 @@ import ( "math/rand" "testing" - "github.com/nspcc-dev/neo-go/config" + "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/core" "github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/core/transaction" diff --git a/pkg/config/application_config.go b/pkg/config/application_config.go new file mode 100644 index 000000000..21637c887 --- /dev/null +++ b/pkg/config/application_config.go @@ -0,0 +1,30 @@ +package config + +import ( + "time" + + "github.com/nspcc-dev/neo-go/pkg/core/storage" + "github.com/nspcc-dev/neo-go/pkg/network/metrics" + "github.com/nspcc-dev/neo-go/pkg/rpc" + "github.com/nspcc-dev/neo-go/pkg/wallet" +) + +// ApplicationConfiguration config specific to the node. +type ApplicationConfiguration struct { + Address string `yaml:"Address"` + AttemptConnPeers int `yaml:"AttemptConnPeers"` + DBConfiguration storage.DBConfiguration `yaml:"DBConfiguration"` + DialTimeout time.Duration `yaml:"DialTimeout"` + LogPath string `yaml:"LogPath"` + MaxPeers int `yaml:"MaxPeers"` + MinPeers int `yaml:"MinPeers"` + NodePort uint16 `yaml:"NodePort"` + PingInterval time.Duration `yaml:"PingInterval"` + PingTimeout time.Duration `yaml:"PingTimeout"` + Pprof metrics.Config `yaml:"Pprof"` + Prometheus metrics.Config `yaml:"Prometheus"` + ProtoTickInterval time.Duration `yaml:"ProtoTickInterval"` + Relay bool `yaml:"Relay"` + RPC rpc.Config `yaml:"RPC"` + UnlockWallet wallet.Config `yaml:"UnlockWallet"` +} diff --git a/pkg/config/config.go b/pkg/config/config.go new file mode 100644 index 000000000..999656ffb --- /dev/null +++ b/pkg/config/config.go @@ -0,0 +1,58 @@ +package config + +import ( + "fmt" + "io/ioutil" + "os" + + "github.com/go-yaml/yaml" + "github.com/pkg/errors" +) + +const userAgentFormat = "/NEO-GO:%s/" + +// Version the version of the node, set at build time. +var Version string + +// Config top level struct representing the config +// for the node. +type Config struct { + ProtocolConfiguration ProtocolConfiguration `yaml:"ProtocolConfiguration"` + ApplicationConfiguration ApplicationConfiguration `yaml:"ApplicationConfiguration"` +} + +// GenerateUserAgent creates user agent string based on build time environment. +func (c Config) GenerateUserAgent() string { + return fmt.Sprintf(userAgentFormat, Version) +} + +// Load attempts to load the config from the given +// path for the given netMode. +func Load(path string, netMode NetMode) (Config, error) { + configPath := fmt.Sprintf("%s/protocol.%s.yml", path, netMode) + if _, err := os.Stat(configPath); os.IsNotExist(err) { + return Config{}, errors.Wrap(err, "Unable to load config") + } + + configData, err := ioutil.ReadFile(configPath) + if err != nil { + return Config{}, errors.Wrap(err, "Unable to read config") + } + + config := Config{ + ProtocolConfiguration: ProtocolConfiguration{ + SystemFee: SystemFee{}, + }, + ApplicationConfiguration: ApplicationConfiguration{ + PingInterval: 30, + PingTimeout: 90, + }, + } + + err = yaml.Unmarshal(configData, &config) + if err != nil { + return Config{}, errors.Wrap(err, "Problem unmarshaling config json data") + } + + return config, nil +} diff --git a/pkg/config/protocol_config.go b/pkg/config/protocol_config.go new file mode 100644 index 000000000..c84de79a2 --- /dev/null +++ b/pkg/config/protocol_config.go @@ -0,0 +1,90 @@ +package config + +import ( + "github.com/nspcc-dev/neo-go/pkg/core/transaction" + "github.com/nspcc-dev/neo-go/pkg/util" +) + +const ( + // ModeMainNet contains magic code used in the NEO main official network. + ModeMainNet NetMode = 0x00746e41 // 7630401 + // ModeTestNet contains magic code used in the NEO testing network. + ModeTestNet NetMode = 0x74746e41 // 1953787457 + // ModePrivNet contains magic code usually used for NEO private networks. + ModePrivNet NetMode = 56753 // docker privnet + // ModeUnitTestNet is a stub magic code used for testing purposes. + ModeUnitTestNet NetMode = 0 +) + +// ProtocolConfiguration represents the protocol config. +type ( + ProtocolConfiguration struct { + AddressVersion byte `yaml:"AddressVersion"` + // FeePerExtraByte sets the expected per-byte fee for + // transactions exceeding the MaxFreeTransactionSize. + FeePerExtraByte float64 `yaml:"FeePerExtraByte"` + // FreeGasLimit is an amount of GAS which can be spent for free. + FreeGasLimit util.Fixed8 `yaml:"FreeGasLimit"` + LowPriorityThreshold float64 `yaml:"LowPriorityThreshold"` + Magic NetMode `yaml:"Magic"` + MaxTransactionsPerBlock int `yaml:"MaxTransactionsPerBlock"` + // Maximum size of low priority transaction in bytes. + MaxFreeTransactionSize int `yaml:"MaxFreeTransactionSize"` + // Maximum number of low priority transactions accepted into block. + MaxFreeTransactionsPerBlock int `yaml:"MaxFreeTransactionsPerBlock"` + MemPoolSize int `yaml:"MemPoolSize"` + // SaveStorageBatch enables storage batch saving before every persist. + SaveStorageBatch bool `yaml:"SaveStorageBatch"` + SecondsPerBlock int `yaml:"SecondsPerBlock"` + SeedList []string `yaml:"SeedList"` + StandbyValidators []string `yaml:"StandbyValidators"` + SystemFee SystemFee `yaml:"SystemFee"` + // Whether to verify received blocks. + VerifyBlocks bool `yaml:"VerifyBlocks"` + // Whether to verify transactions in received blocks. + VerifyTransactions bool `yaml:"VerifyTransactions"` + } + + // SystemFee fees related to system. + SystemFee struct { + EnrollmentTransaction int64 `yaml:"EnrollmentTransaction"` + IssueTransaction int64 `yaml:"IssueTransaction"` + PublishTransaction int64 `yaml:"PublishTransaction"` + RegisterTransaction int64 `yaml:"RegisterTransaction"` + } + + // NetMode describes the mode the blockchain will operate on. + NetMode uint32 +) + +// String implements the stringer interface. +func (n NetMode) String() string { + switch n { + case ModePrivNet: + return "privnet" + case ModeTestNet: + return "testnet" + case ModeMainNet: + return "mainnet" + case ModeUnitTestNet: + return "unit_testnet" + default: + return "net unknown" + } +} + +// TryGetValue returns the system fee base on transaction type. +func (s SystemFee) TryGetValue(txType transaction.TXType) util.Fixed8 { + switch txType { + case transaction.EnrollmentType: + return util.Fixed8FromInt64(s.EnrollmentTransaction) + case transaction.IssueType: + return util.Fixed8FromInt64(s.IssueTransaction) + case transaction.PublishType: + return util.Fixed8FromInt64(s.PublishTransaction) + case transaction.RegisterType: + return util.Fixed8FromInt64(s.RegisterTransaction) + default: + return util.Fixed8FromInt64(0) + } +} diff --git a/pkg/consensus/consensus.go b/pkg/consensus/consensus.go index d5abb4501..25b16b7c7 100644 --- a/pkg/consensus/consensus.go +++ b/pkg/consensus/consensus.go @@ -10,7 +10,6 @@ import ( "github.com/nspcc-dev/dbft/block" "github.com/nspcc-dev/dbft/crypto" "github.com/nspcc-dev/dbft/payload" - "github.com/nspcc-dev/neo-go/config" "github.com/nspcc-dev/neo-go/pkg/core" coreb "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/mempool" @@ -85,7 +84,7 @@ type Config struct { // TimePerBlock minimal time that should pass before next block is accepted. TimePerBlock time.Duration // Wallet is a local-node wallet configuration. - Wallet *config.WalletConfig + Wallet *wallet.Config } // NewService returns new consensus.Service instance. diff --git a/pkg/consensus/consensus_test.go b/pkg/consensus/consensus_test.go index c5304b987..502d98eb1 100644 --- a/pkg/consensus/consensus_test.go +++ b/pkg/consensus/consensus_test.go @@ -5,12 +5,13 @@ import ( "github.com/nspcc-dev/dbft/block" "github.com/nspcc-dev/dbft/payload" - "github.com/nspcc-dev/neo-go/config" + "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/core" "github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/util" + "github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/stretchr/testify/require" "go.uber.org/zap/zaptest" ) @@ -181,7 +182,7 @@ func newTestService(t *testing.T) *service { Broadcast: func(*Payload) {}, Chain: newTestChain(t), RequestTx: func(...util.Uint256) {}, - Wallet: &config.WalletConfig{ + Wallet: &wallet.Config{ Path: "./testdata/wallet1.json", Password: "one", }, diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index c47a97283..ea84cf0eb 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -9,7 +9,7 @@ import ( "sync/atomic" "time" - "github.com/nspcc-dev/neo-go/config" + "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/mempool" "github.com/nspcc-dev/neo-go/pkg/core/state" diff --git a/pkg/core/blockchainer.go b/pkg/core/blockchainer.go index 57ee04f11..d6f6040ce 100644 --- a/pkg/core/blockchainer.go +++ b/pkg/core/blockchainer.go @@ -1,7 +1,7 @@ package core import ( - "github.com/nspcc-dev/neo-go/config" + "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/mempool" "github.com/nspcc-dev/neo-go/pkg/core/state" diff --git a/pkg/core/helper_test.go b/pkg/core/helper_test.go index 763ffb6eb..307b6856f 100644 --- a/pkg/core/helper_test.go +++ b/pkg/core/helper_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/nspcc-dev/neo-go/config" + "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/storage" "github.com/nspcc-dev/neo-go/pkg/core/transaction" diff --git a/pkg/core/util.go b/pkg/core/util.go index 864f60bd4..22e2f8709 100644 --- a/pkg/core/util.go +++ b/pkg/core/util.go @@ -3,7 +3,7 @@ package core import ( "time" - "github.com/nspcc-dev/neo-go/config" + "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" diff --git a/pkg/core/util_test.go b/pkg/core/util_test.go index ff59855f0..41674c161 100644 --- a/pkg/core/util_test.go +++ b/pkg/core/util_test.go @@ -3,7 +3,7 @@ package core import ( "testing" - "github.com/nspcc-dev/neo-go/config" + "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/pkg/network/helper_test.go b/pkg/network/helper_test.go index 08e72adc8..3864440be 100644 --- a/pkg/network/helper_test.go +++ b/pkg/network/helper_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/nspcc-dev/neo-go/config" + "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/mempool" "github.com/nspcc-dev/neo-go/pkg/core/state" diff --git a/pkg/network/message.go b/pkg/network/message.go index 1d651fd71..a8bedc96c 100644 --- a/pkg/network/message.go +++ b/pkg/network/message.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - "github.com/nspcc-dev/neo-go/config" + "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/consensus" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/transaction" diff --git a/pkg/network/server_config.go b/pkg/network/server_config.go index 42a2a1613..edd6731b7 100644 --- a/pkg/network/server_config.go +++ b/pkg/network/server_config.go @@ -3,7 +3,8 @@ package network import ( "time" - "github.com/nspcc-dev/neo-go/config" + "github.com/nspcc-dev/neo-go/pkg/config" + "github.com/nspcc-dev/neo-go/pkg/wallet" "go.uber.org/zap/zapcore" ) @@ -61,7 +62,7 @@ type ( LogLevel zapcore.Level // Wallet is a wallet configuration. - Wallet *config.WalletConfig + Wallet *wallet.Config // TimePerBlock is an interval which should pass between two successive blocks. TimePerBlock time.Duration @@ -74,7 +75,7 @@ func NewServerConfig(cfg config.Config) ServerConfig { appConfig := cfg.ApplicationConfiguration protoConfig := cfg.ProtocolConfiguration - var wc *config.WalletConfig + var wc *wallet.Config if appConfig.UnlockWallet.Path != "" { wc = &appConfig.UnlockWallet } diff --git a/pkg/rpc/rpc_config.go b/pkg/rpc/rpc_config.go new file mode 100644 index 000000000..30ecbf236 --- /dev/null +++ b/pkg/rpc/rpc_config.go @@ -0,0 +1,26 @@ +package rpc + +import "github.com/nspcc-dev/neo-go/pkg/util" + +type ( + // Config is an RPC service configuration information + Config struct { + Address string `yaml:"Address"` + Enabled bool `yaml:"Enabled"` + EnableCORSWorkaround bool `yaml:"EnableCORSWorkaround"` + // MaxGasInvoke is a maximum amount of gas which + // can be spent during RPC call. + MaxGasInvoke util.Fixed8 `yaml:"MaxGasInvoke"` + Port uint16 `yaml:"Port"` + TLSConfig TLSConfig `yaml:"TLSConfig"` + } + + // TLSConfig describes SSL/TLS configuration. + TLSConfig struct { + Address string `yaml:"Address"` + CertFile string `yaml:"CertFile"` + Enabled bool `yaml:"Enabled"` + Port uint16 `yaml:"Port"` + KeyFile string `yaml:"KeyFile"` + } +) diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index f6c0dc58b..72e1c5274 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -10,7 +10,8 @@ import ( "net/http" "strconv" - "github.com/nspcc-dev/neo-go/config" + "github.com/nspcc-dev/neo-go/pkg/rpc" + "github.com/nspcc-dev/neo-go/pkg/core" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/state" @@ -35,7 +36,7 @@ type ( Server struct { *http.Server chain core.Blockchainer - config config.RPCConfig + config rpc.Config coreServer *network.Server log *zap.Logger https *http.Server @@ -80,7 +81,7 @@ var invalidBlockHeightError = func(index int, height int) error { } // New creates a new Server struct. -func New(chain core.Blockchainer, conf config.RPCConfig, coreServer *network.Server, log *zap.Logger) Server { +func New(chain core.Blockchainer, conf rpc.Config, coreServer *network.Server, log *zap.Logger) Server { httpServer := &http.Server{ Addr: conf.Address + ":" + strconv.FormatUint(uint64(conf.Port), 10), } diff --git a/pkg/rpc/server/server_helper_test.go b/pkg/rpc/server/server_helper_test.go index 85f464dda..1263c0dcd 100644 --- a/pkg/rpc/server/server_helper_test.go +++ b/pkg/rpc/server/server_helper_test.go @@ -5,7 +5,7 @@ import ( "os" "testing" - "github.com/nspcc-dev/neo-go/config" + "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/core" "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/storage" diff --git a/pkg/wallet/wallet_config.go b/pkg/wallet/wallet_config.go new file mode 100644 index 000000000..8b5d790b6 --- /dev/null +++ b/pkg/wallet/wallet_config.go @@ -0,0 +1,7 @@ +package wallet + +// Config is a wallet info. +type Config struct { + Path string `yaml:"Path"` + Password string `yaml:"Password"` +}