From e033149edb710daa71916611b5e70c2b43c82f0a Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Mon, 16 Oct 2023 15:14:33 +0530 Subject: [PATCH] Fix payments manager initialization --- go.mod | 2 +- main.go | 18 +++++++++++++++++- paymentsmanager/http_middleware.go | 2 +- paymentsmanager/payments_manager.go | 4 ++-- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 5a856e661..50060e440 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,6 @@ require ( github.com/libp2p/go-libp2p-kad-dht v0.24.2 github.com/tidwall/buntdb v1.2.10 github.com/urfave/cli/v2 v2.25.3 - golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 ) @@ -145,6 +144,7 @@ require ( go.uber.org/fx v1.20.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.25.0 // indirect + golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect golang.org/x/mod v0.12.0 // indirect golang.org/x/net v0.14.0 // indirect golang.org/x/sync v0.3.0 // indirect diff --git a/main.go b/main.go index 092864377..74428a10b 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "os" "os/signal" "strings" + "sync" "syscall" "github.com/ethereum/go-ethereum/common" @@ -252,7 +253,22 @@ func main() { if err != nil { return err } - paymentsManager := paymentsmanager.PaymentsManager{} + + paymentsManager, err := paymentsmanager.NewPaymentsManager(node) + if err != nil { + return err + } + + wg := new(sync.WaitGroup) + defer wg.Wait() + + paymentsManager.Start(wg) + defer func() { + err := paymentsManager.Stop() + if err != nil { + panic(err) + } + }() var cert tls.Certificate if tlsCertFilepath != "" && tlsKeyFilepath != "" { diff --git a/paymentsmanager/http_middleware.go b/paymentsmanager/http_middleware.go index 6e186bd07..0ce840cbd 100644 --- a/paymentsmanager/http_middleware.go +++ b/paymentsmanager/http_middleware.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "io" + "log/slog" "math/big" "net/http" "regexp" @@ -12,7 +13,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/statechannels/go-nitro/crypto" - "golang.org/x/exp/slog" ) const ( diff --git a/paymentsmanager/payments_manager.go b/paymentsmanager/payments_manager.go index 32486953c..5af9e48fe 100644 --- a/paymentsmanager/payments_manager.go +++ b/paymentsmanager/payments_manager.go @@ -1,6 +1,7 @@ package paymentsmanager import ( + "log/slog" "math/big" "sync" "time" @@ -10,7 +11,6 @@ import ( "github.com/statechannels/go-nitro/node" "github.com/statechannels/go-nitro/payments" "github.com/statechannels/go-nitro/types" - "golang.org/x/exp/slog" ) const ( @@ -167,7 +167,7 @@ func (pm *PaymentsManager) run() { vouchersMap.Add(voucherHash.Hex(), InFlightVoucher{voucher: voucher, amount: paymentAmount}) case <-pm.quitChan: - slog.Info("stopping voucher subscription loop") + slog.Info("stopping voucher subscription loop...") return } }