Refactor in process Nitro node setup
This commit is contained in:
parent
f2f951f7b8
commit
db91f3ff66
59
cmd/serve.go
59
cmd/serve.go
@ -96,38 +96,12 @@ func serve() {
|
||||
|
||||
var voucherValidator paymentsmanager.VoucherValidator
|
||||
|
||||
// TODO: Refactor into a function / subcommand
|
||||
nitroConfig := serverConfig.Nitro
|
||||
if nitroConfig.RunNodeInProcess {
|
||||
log.Info("Running an in-process Nitro node")
|
||||
|
||||
nitroNode, err := initNitroNode(&nitroConfig.InProcessNode)
|
||||
if err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
}
|
||||
|
||||
pm, err := paymentsmanager.NewPaymentsManager(nitroNode)
|
||||
if err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
}
|
||||
pm.Start(wg)
|
||||
pm, nitroRpcServer := initNitroInProcess(wg, nitroConfig)
|
||||
defer pm.Stop()
|
||||
|
||||
tlsCertFilepath := nitroConfig.InProcessNode.TlsCertFilepath
|
||||
tlsKeyFilepath := nitroConfig.InProcessNode.TlsKeyFilepath
|
||||
|
||||
var cert *tls.Certificate
|
||||
if tlsCertFilepath != "" && tlsKeyFilepath != "" {
|
||||
*cert, err = tls.LoadX509KeyPair(tlsCertFilepath, tlsKeyFilepath)
|
||||
if err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
nitroRpcServer, err := initNitroRpcServer(nitroNode, pm, cert, nitroConfig.InProcessNode.RpcPort)
|
||||
if err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
}
|
||||
defer nitroRpcServer.Close()
|
||||
|
||||
voucherValidator = paymentsmanager.InProcessVoucherValidator{PaymentsManager: pm}
|
||||
@ -416,6 +390,37 @@ func init() {
|
||||
viper.BindPFlag("validator.everyNthBlock", serveCmd.PersistentFlags().Lookup("validator-every-nth-block"))
|
||||
}
|
||||
|
||||
func initNitroInProcess(wg *sync.WaitGroup, nitroConfig *s.NitroConfig) (*paymentsmanager.PaymentsManager, *nitroRpc.RpcServer) {
|
||||
nitroNode, err := initNitroNode(&nitroConfig.InProcessNode)
|
||||
if err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
}
|
||||
|
||||
pm, err := paymentsmanager.NewPaymentsManager(nitroNode)
|
||||
if err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
}
|
||||
pm.Start(wg)
|
||||
|
||||
tlsCertFilepath := nitroConfig.InProcessNode.TlsCertFilepath
|
||||
tlsKeyFilepath := nitroConfig.InProcessNode.TlsKeyFilepath
|
||||
|
||||
var cert *tls.Certificate
|
||||
if tlsCertFilepath != "" && tlsKeyFilepath != "" {
|
||||
*cert, err = tls.LoadX509KeyPair(tlsCertFilepath, tlsKeyFilepath)
|
||||
if err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
nitroRpcServer, err := initNitroRpcServer(nitroNode, pm, cert, nitroConfig.InProcessNode.RpcPort)
|
||||
if err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
}
|
||||
|
||||
return &pm, nitroRpcServer
|
||||
}
|
||||
|
||||
// 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) {
|
||||
pkString := config.Pk
|
||||
|
Loading…
Reference in New Issue
Block a user