diff --git a/cmd/common.go b/cmd/common.go index f01d296a..90be835d 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -42,12 +42,18 @@ func addNitroFlags(command *cobra.Command) { command.PersistentFlags().String("nitro-pk", "", "nitro pk") command.PersistentFlags().String("nitro-chain-pk", "", "nitro chainPk") - command.PersistentFlags().String("nitro-chain-url", "", "nitro chainUrl") + command.PersistentFlags().String("nitro-chain-url", "ws://127.0.0.1:8545", "nitro chainUrl") command.PersistentFlags().String("nitro-na-address", "", "nitro naAddress") command.PersistentFlags().String("nitro-vpa-address", "", "nitro vpaAddress") command.PersistentFlags().String("nitro-ca-address", "", "nitro caAddress") command.PersistentFlags().Bool("nitro-use-durable-store", false, "nitro useDurableStore") command.PersistentFlags().String("nitro-durable-store-folder", "", "nitro durableStoreFolder") + command.PersistentFlags().Int("nitro-msg-port", 3005, "nitro msgPort") + command.PersistentFlags().Int("nitro-rpc-port", 4005, "nitro rpcPort") + command.PersistentFlags().Int("nitro-ws-msg-port", 5005, "nitro wsMsgPort") + command.PersistentFlags().Uint("nitro-chain-start-block", 0, "nitro chainStartBlock") + command.PersistentFlags().String("nitro-tls-cert-filepath", "./nitroTLS/statechannels.org.pem", "nitro tlsCertFilepath") + command.PersistentFlags().String("nitro-tls-key-filepath", "./nitroTLS/statechannels.org_key.pem", "nitro tlsKeyFilepath") command.PersistentFlags().String("nitro-endpoint", "", "nitro endpoint") @@ -62,6 +68,12 @@ func addNitroFlags(command *cobra.Command) { viper.BindPFlag("nitro.inProcesssNode.caAddress", command.PersistentFlags().Lookup("nitro-ca-address")) viper.BindPFlag("nitro.inProcesssNode.useDurableStore", command.PersistentFlags().Lookup("nitro-use-durable-store")) viper.BindPFlag("nitro.inProcesssNode.durableStoreFolder", command.PersistentFlags().Lookup("nitro-durable-store")) + viper.BindPFlag("nitro.inProcesssNode.msgPort", command.PersistentFlags().Lookup("nitro-msg-port")) + viper.BindPFlag("nitro.inProcesssNode.rpcPort", command.PersistentFlags().Lookup("nitro-rpc-port")) + viper.BindPFlag("nitro.inProcesssNode.wsMsgPort", command.PersistentFlags().Lookup("nitro-ws-msg-port")) + viper.BindPFlag("nitro.inProcesssNode.chainStartBlock", command.PersistentFlags().Lookup("nitro-chain-start-block")) + viper.BindPFlag("nitro.inProcesssNode.tlsCertFilepath", command.PersistentFlags().Lookup("nitro-tls-cert-filepath")) + viper.BindPFlag("nitro.inProcesssNode.tlsKeyFilepath", command.PersistentFlags().Lookup("nitro-tls-key-filepath")) viper.BindPFlag("nitro.remoteNode.nitroEndpoint", command.PersistentFlags().Lookup("nitro-endpoint")) } diff --git a/cmd/serve.go b/cmd/serve.go index f7482c74..c96ae855 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -111,10 +111,9 @@ func serve() { pm.Start(wg) defer pm.Stop() - // TODO: Read from config file - rpcPort := 4005 - tlsCertFilepath := "" - tlsKeyFilepath := "" + rpcPort := nitroConfig.InProcessNode.RpcPort + tlsCertFilepath := nitroConfig.InProcessNode.TlsCertFilepath + tlsKeyFilepath := nitroConfig.InProcessNode.TlsKeyFilepath var cert *tls.Certificate if tlsCertFilepath != "" && tlsKeyFilepath != "" { @@ -422,14 +421,13 @@ func init() { // https://github.com/cerc-io/go-nitro/blob/release-v0.1.1-ts-port-0.1.7/internal/node/node.go#L17 func initNitroNode(config *s.InProcessNitroNodeConfig) (*nitroNode.Node, error) { - // TODO: Read from config file pkString := config.Pk useDurableStore := config.UseDurableStore durableStoreFolder := config.DurableStoreFolder - msgPort := 3005 - wsMsgPort := 5005 + msgPort := config.MsgPort + wsMsgPort := config.WsMsgPort chainUrl := config.ChainUrl - chainStartBlock := uint64(0) + chainStartBlock := config.ChainStartBlock chainPk := config.ChainPk naAddress := config.NaAddress vpaAddress := config.VpaAddress diff --git a/environments/example.toml b/environments/example.toml index 232ade55..ef16a43c 100644 --- a/environments/example.toml +++ b/environments/example.toml @@ -44,6 +44,12 @@ caAddress = "" # NITRO_CA_ADDRESS useDurableStore = true # NITRO_USE_DURABLE_STORE durableStoreFolder = "./data/nitronode" # NITRO_DURABLE_STORE_FOLDER + msgPort = 3005 + rpcPort = 4005 + wsMsgPort = 5005 + chainStartBlock = 0 + tlsCertFilepath = "./nitroTLS/statechannels.org.pem" + tlsKeyFilepath = "./nitroTLS/statechannels.org_key.pem" [nitro.remoteNode] nitroEndpoint = "127.0.0.1:4005/api/v1" # NITRO_ENDPOINT diff --git a/pkg/serve/config.go b/pkg/serve/config.go index e1d0f732..4049512f 100644 --- a/pkg/serve/config.go +++ b/pkg/serve/config.go @@ -90,6 +90,12 @@ const ( NITRO_USE_DURABLE_STORE = "NITRO_USE_DURABLE_STORE" NITRO_DURABLE_STORE_FOLDER = "NITRO_DURABLE_STORE_FOLDER" NITRO_ENDPOINT = "NITRO_ENDPOINT" + NITRO_MSG_PORT = "NITRO_MSG_PORT" + NITRO_WS_MSG_PORT = "NITRO_WS_MSG_PORT" + NITRO_RPC_PORT = "NITRO_RPC_PORT" + NITRO_CHAIN_START_BLOCK = "NITRO_CHAIN_START_BLOCK" + NITRO_TLS_CERT_FILEPATH = "NITRO_TLS_CERT_FILEPATH" + NITRO_TLS_KEY_FILEPATH = "NITRO_TLS_KEY_FILEPATH" ) type InProcessNitroNodeConfig struct { @@ -101,6 +107,12 @@ type InProcessNitroNodeConfig struct { CaAddress string UseDurableStore bool DurableStoreFolder string + RpcPort int + MsgPort int + WsMsgPort int + ChainStartBlock uint64 + TlsCertFilepath string + TlsKeyFilepath string } type RemoteNitroNodeConfig struct { @@ -329,6 +341,12 @@ func (c *Config) loadNitroConfig() { viper.BindEnv("nitro.inProcesssNode.caAddress", NITRO_CA_ADDRESS) viper.BindEnv("nitro.inProcesssNode.useDurableStore", NITRO_USE_DURABLE_STORE) viper.BindEnv("nitro.inProcesssNode.durableStoreFolder", NITRO_DURABLE_STORE_FOLDER) + viper.BindEnv("nitro.inProcesssNode.msgPort", NITRO_MSG_PORT) + viper.BindEnv("nitro.inProcesssNode.rpcPort", NITRO_RPC_PORT) + viper.BindEnv("nitro.inProcesssNode.wsMsgPort", NITRO_WS_MSG_PORT) + viper.BindEnv("nitro.inProcesssNode.chainStartBlock", NITRO_CHAIN_START_BLOCK) + viper.BindEnv("nitro.inProcesssNode.tlsCertFilepath", NITRO_TLS_CERT_FILEPATH) + viper.BindEnv("nitro.inProcesssNode.tlsKeyFilepath", NITRO_TLS_KEY_FILEPATH) viper.BindEnv("nitro.remoteNode.nitroEndpoint", NITRO_ENDPOINT) @@ -342,6 +360,12 @@ func (c *Config) loadNitroConfig() { c.Nitro.InProcessNode.CaAddress = viper.GetString("nitro.inProcesssNode.caAddress") c.Nitro.InProcessNode.UseDurableStore = viper.GetBool("nitro.inProcesssNode.useDurableStore") c.Nitro.InProcessNode.DurableStoreFolder = viper.GetString("nitro.inProcesssNode.durableStoreFolder") + c.Nitro.InProcessNode.MsgPort = viper.GetInt("nitro.inProcesssNode.msgPort") + c.Nitro.InProcessNode.RpcPort = viper.GetInt("nitro.inProcesssNode.rpcPort") + c.Nitro.InProcessNode.WsMsgPort = viper.GetInt("nitro.inProcesssNode.wsMsgPort") + c.Nitro.InProcessNode.ChainStartBlock = viper.GetUint64("nitro.inProcesssNode.chainStartBlock") + c.Nitro.InProcessNode.TlsCertFilepath = viper.GetString("nitro.inProcesssNode.tlsCertFilepath") + c.Nitro.InProcessNode.TlsKeyFilepath = viper.GetString("nitro.inProcesssNode.tlsKeyFilepath") c.Nitro.RemoteNode.NitroEndpoint = viper.GetString("nitro.remoteNode.nitroEndpoint") }