forked from cerc-io/ipld-eth-server
Update Nitro node initialization
This commit is contained in:
+31
-9
@@ -16,6 +16,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
@@ -35,10 +36,9 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
"github.com/statechannels/go-nitro/node/engine"
|
||||
"github.com/statechannels/go-nitro/node/engine/chainservice"
|
||||
"github.com/statechannels/go-nitro/node/engine/store"
|
||||
nitroStore "github.com/statechannels/go-nitro/node/engine/store"
|
||||
"github.com/statechannels/go-nitro/paymentsmanager"
|
||||
"github.com/statechannels/go-nitro/rpc/transport"
|
||||
"github.com/tidwall/buntdb"
|
||||
"golang.org/x/exp/slog"
|
||||
|
||||
"github.com/cerc-io/ipld-eth-server/v5/pkg/graphql"
|
||||
@@ -114,7 +114,15 @@ func serve() {
|
||||
|
||||
// TODO: Read from config file
|
||||
rpcPort := 4005
|
||||
nitroRpcServer, err := initializeNitroRpcServer(nitroNode, rpcPort)
|
||||
tlsCertFilepath := "./nitroTLS/statechannels.org.pem"
|
||||
tlsKeyFilepath := "./nitroTLS/statechannels.org_key.pem"
|
||||
|
||||
cert, err := tls.LoadX509KeyPair(tlsCertFilepath, tlsKeyFilepath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
nitroRpcServer, err := initializeNitroRpcServer(nitroNode, pm, &cert, rpcPort)
|
||||
if err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
}
|
||||
@@ -418,14 +426,28 @@ func initializeNitroNode(nitroConfig *s.NitroConfig) (*nitroNode.Node, error) {
|
||||
CaAddress: common.HexToAddress(caAddress),
|
||||
}
|
||||
|
||||
ourStore, err := store.NewStore(common.Hex2Bytes(pkString), useDurableStore, durableStoreFolder, buntdb.Config{})
|
||||
storeOpts := nitroStore.StoreOpts{
|
||||
PkBytes: common.Hex2Bytes(pkString),
|
||||
UseDurableStore: useDurableStore,
|
||||
DurableStoreFolder: durableStoreFolder,
|
||||
}
|
||||
|
||||
bootPeers := []string{}
|
||||
messageOpts := nitrop2pms.MessageOpts{
|
||||
PkBytes: common.Hex2Bytes(pkString),
|
||||
TcpPort: msgPort,
|
||||
WsMsgPort: wsMsgPort,
|
||||
BootPeers: bootPeers,
|
||||
PublicIp: publicIp,
|
||||
}
|
||||
|
||||
ourStore, err := nitroStore.NewStore(storeOpts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bootPeers := []string{}
|
||||
log.Info("Initializing message service...", " tcp port=", msgPort, " web socket port=", wsMsgPort)
|
||||
messageService := nitrop2pms.NewMessageService(publicIp, msgPort, wsMsgPort, *ourStore.GetAddress(), common.Hex2Bytes(pkString), bootPeers)
|
||||
messageService := nitrop2pms.NewMessageService(messageOpts)
|
||||
|
||||
// Compare chainOpts.ChainStartBlock to lastBlockNum seen in store. The larger of the two
|
||||
// gets passed as an argument when creating NewEthChainService
|
||||
@@ -453,17 +475,17 @@ func initializeNitroNode(nitroConfig *s.NitroConfig) (*nitroNode.Node, error) {
|
||||
return &node, nil
|
||||
}
|
||||
|
||||
func initializeNitroRpcServer(node *nitroNode.Node, rpcPort int) (*nitroRpc.RpcServer, error) {
|
||||
func initializeNitroRpcServer(node *nitroNode.Node, pm paymentsmanager.PaymentsManager, cert *tls.Certificate, rpcPort int) (*nitroRpc.RpcServer, error) {
|
||||
var transport transport.Responder
|
||||
var err error
|
||||
|
||||
slog.Info("Initializing Nitro HTTP RPC transport...")
|
||||
transport, err = nitroHttpTransport.NewHttpTransportAsServer(fmt.Sprint(rpcPort))
|
||||
transport, err = nitroHttpTransport.NewHttpTransportAsServer(fmt.Sprint(rpcPort), cert)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rpcServer, err := nitroRpc.NewRpcServer(node, transport)
|
||||
rpcServer, err := nitroRpc.NewRpcServer(pm, node, transport)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user