From a67a08d40af7f732e66540c23eca37082e2c9a51 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 --- main.go | 17 ++++++++++++++++- paymentsmanager/http_middleware.go | 2 +- paymentsmanager/payments_manager.go | 4 ++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index b7a32ea923..69daa441ec 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "os" "os/signal" "strings" + "sync" "syscall" "github.com/ethereum/go-ethereum/common" @@ -253,7 +254,21 @@ func main() { 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) + } + }() cert, err := tls.LoadX509KeyPair(tlsCertFilepath, tlsKeyFilepath) if err != nil { diff --git a/paymentsmanager/http_middleware.go b/paymentsmanager/http_middleware.go index 6e186bd073..0ce840cbd9 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 32486953c6..5af9e48feb 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 } }