Initialize RPC client to connect with a remote Nitro node
This commit is contained in:
parent
fe1f4718e2
commit
0834c0a334
85
cmd/serve.go
85
cmd/serve.go
@ -69,6 +69,8 @@ func serve() {
|
||||
logWithCommand.Infof("ipld-eth-server version: %s", v.VersionWithMeta)
|
||||
|
||||
wg := new(sync.WaitGroup)
|
||||
defer wg.Wait()
|
||||
|
||||
serverConfig, err := s.NewConfig()
|
||||
if err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
@ -90,20 +92,60 @@ func serve() {
|
||||
|
||||
server.Serve(wg)
|
||||
|
||||
nitroNode, err := initializeNitroNode(serverConfig.Nitro)
|
||||
if err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
// TODO: Read from config file
|
||||
runNitroInProcess := false
|
||||
nitroEndpoint := "127.0.0.1:4005/api/v1"
|
||||
var voucherValidator paymentsmanager.VoucherValidator
|
||||
|
||||
if runNitroInProcess {
|
||||
log.Info("Running an in-process Nitro node")
|
||||
|
||||
nitroNode, err := initializeNitroNode(serverConfig.Nitro)
|
||||
if err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
}
|
||||
|
||||
pm, err := paymentsmanager.NewPaymentsManager(nitroNode)
|
||||
if err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
}
|
||||
pm.Start(wg)
|
||||
defer pm.Stop()
|
||||
|
||||
// TODO: Read from config file
|
||||
rpcPort := 4005
|
||||
tlsCertFilepath := "./nitroTLS/statechannels.org.pem"
|
||||
tlsKeyFilepath := "./nitroTLS/statechannels.org_key.pem"
|
||||
|
||||
cert, err := tls.LoadX509KeyPair(tlsCertFilepath, tlsKeyFilepath)
|
||||
if err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
}
|
||||
|
||||
nitroRpcServer, err := initializeNitroRpcServer(nitroNode, pm, &cert, rpcPort)
|
||||
if err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
}
|
||||
defer nitroRpcServer.Close()
|
||||
|
||||
voucherValidator = paymentsmanager.InProcessVoucherValidator{PaymentsManager: pm}
|
||||
} else {
|
||||
log.Info("Connecting to a remote Nitro node")
|
||||
|
||||
clientConnection, err := nitroHttpTransport.NewHttpTransportAsClient(nitroEndpoint, 10*time.Millisecond)
|
||||
if err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
}
|
||||
|
||||
nitroRpcClient, err := nitroRpc.NewRpcClient(clientConnection)
|
||||
if err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
}
|
||||
defer nitroRpcClient.Close()
|
||||
|
||||
voucherValidator = nitroRpc.RemoteVoucherValidator{Client: nitroRpcClient}
|
||||
}
|
||||
|
||||
pm, err := paymentsmanager.NewPaymentsManager(nitroNode)
|
||||
if err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
}
|
||||
|
||||
pm.Start(wg)
|
||||
|
||||
voucherValidator := paymentsmanager.InProcessVoucherValidator{PaymentsManager: pm}
|
||||
|
||||
// TODO: Read from config file
|
||||
queryRates := map[string]*big.Int{
|
||||
"eth_getBlockByNumber": big.NewInt(50),
|
||||
@ -112,21 +154,6 @@ func serve() {
|
||||
"eth_getLogs": big.NewInt(50),
|
||||
}
|
||||
|
||||
// TODO: Read from config file
|
||||
rpcPort := 4005
|
||||
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)
|
||||
}
|
||||
|
||||
if err := startServers(server, serverConfig, voucherValidator, queryRates); err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
}
|
||||
@ -154,10 +181,6 @@ func serve() {
|
||||
graphQL.Stop()
|
||||
}
|
||||
server.Stop()
|
||||
pm.Stop()
|
||||
nitroRpcServer.Close()
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
// TODO: Absorb voucherValidator and queryRates args into existing ones
|
||||
|
2
go.mod
2
go.mod
@ -302,4 +302,4 @@ replace (
|
||||
github.com/cerc-io/ipfs-ethdb/v5 => github.com/cerc-io/ipfs-ethdb/v5 v5.0.1-alpha.0.20231013070931-0b1a36562a28
|
||||
)
|
||||
|
||||
replace github.com/statechannels/go-nitro v0.1.1 => github.com/deep-stack/go-nitro v0.0.0-20231016053556-1aa955e958a8
|
||||
replace github.com/statechannels/go-nitro v0.1.1 => github.com/deep-stack/go-nitro v0.0.0-20231016095715-e033149edb71
|
||||
|
4
go.sum
4
go.sum
@ -184,8 +184,8 @@ github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5il
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs=
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
|
||||
github.com/deep-stack/go-nitro v0.0.0-20231016053556-1aa955e958a8 h1:vQgSbAAEtf+34DKfvCeOPQKhcigcTaRCSfaVD/sn/JA=
|
||||
github.com/deep-stack/go-nitro v0.0.0-20231016053556-1aa955e958a8/go.mod h1:gkKL37JcSo54ybLTI6VJRmP75bWEu9i1kc9RYmQLp+I=
|
||||
github.com/deep-stack/go-nitro v0.0.0-20231016095715-e033149edb71 h1:/AG4iXW0TO8iIRvGrdhOoh42zODMzJ/Zao/jXuJskS0=
|
||||
github.com/deep-stack/go-nitro v0.0.0-20231016095715-e033149edb71/go.mod h1:YYQvj9es00ZfLTwxZLM1M0ihUrqz8+lU2c10G06My3A=
|
||||
github.com/deepmap/oapi-codegen v1.6.0/go.mod h1:ryDa9AgbELGeB+YEXE1dR53yAjHwFvE9iAUlWl9Al3M=
|
||||
github.com/deepmap/oapi-codegen v1.8.2 h1:SegyeYGcdi0jLLrpbCMoJxnUUn8GBXHsvr4rbzjuhfU=
|
||||
github.com/deepmap/oapi-codegen v1.8.2/go.mod h1:YLgSKSDv/bZQB7N4ws6luhozi3cEdRktEqrX88CvjIw=
|
||||
|
Loading…
Reference in New Issue
Block a user