got rid of fees dependency in ledger

This commit is contained in:
Stephan D
2026-02-27 16:23:50 +01:00
parent 02a0d192b9
commit 605f0ba139
13 changed files with 51 additions and 300 deletions

View File

@@ -3,7 +3,6 @@ package serverimp
import (
"context"
"os"
"strings"
"time"
"github.com/tech/sendico/ledger/internal/service/ledger"
@@ -13,11 +12,8 @@ import (
"github.com/tech/sendico/pkg/db"
msg "github.com/tech/sendico/pkg/messaging"
"github.com/tech/sendico/pkg/mlogger"
feesv1 "github.com/tech/sendico/pkg/proto/billing/fees/v1"
"github.com/tech/sendico/pkg/server/grpcapp"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"gopkg.in/yaml.v3"
)
@@ -26,29 +22,13 @@ type Imp struct {
file string
debug bool
config *config
app *grpcapp.App[storage.Repository]
service *ledger.Service
feesConn *grpc.ClientConn
config *config
app *grpcapp.App[storage.Repository]
service *ledger.Service
}
type config struct {
*grpcapp.Config `yaml:",inline"`
Fees FeesClientConfig `yaml:"fees"`
}
type FeesClientConfig struct {
Address string `yaml:"address"`
TimeoutSeconds int `yaml:"timeout_seconds"`
}
const defaultFeesTimeout = 3 * time.Second
func (c FeesClientConfig) timeout() time.Duration {
if c.TimeoutSeconds <= 0 {
return defaultFeesTimeout
}
return time.Duration(c.TimeoutSeconds) * time.Second
}
func Create(logger mlogger.Logger, file string, debug bool) (*Imp, error) {
@@ -64,9 +44,6 @@ func (i *Imp) Shutdown() {
if i.service != nil {
i.service.Shutdown()
}
if i.feesConn != nil {
_ = i.feesConn.Close()
}
return
}
@@ -82,10 +59,6 @@ func (i *Imp) Shutdown() {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
i.app.Shutdown(ctx)
cancel()
if i.feesConn != nil {
_ = i.feesConn.Close()
}
}
func (i *Imp) Start() error {
@@ -99,22 +72,6 @@ func (i *Imp) Start() error {
return mongostorage.New(logger, conn)
}
var feesClient feesv1.FeeEngineClient
feesTimeout := cfg.Fees.timeout()
if addr := strings.TrimSpace(cfg.Fees.Address); addr != "" {
ctx, cancel := context.WithTimeout(context.Background(), feesTimeout)
defer cancel()
conn, err := grpc.DialContext(ctx, addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
i.logger.Warn("Failed to connect to fees service", zap.String("address", addr), zap.Error(err))
} else {
i.logger.Info("Connected to fees service", zap.String("address", addr))
i.feesConn = conn
feesClient = feesv1.NewFeeEngineClient(conn)
}
}
serviceFactory := func(logger mlogger.Logger, repo storage.Repository, producer msg.Producer) (grpcapp.Service, error) {
invokeURI := ""
if cfg.GRPC != nil {
@@ -124,7 +81,7 @@ func (i *Imp) Start() error {
if cfg.Messaging != nil {
msgSettings = cfg.Messaging.Settings
}
svc, err := ledger.NewService(logger, repo, producer, msgSettings, feesClient, feesTimeout, invokeURI)
svc, err := ledger.NewService(logger, repo, producer, msgSettings, invokeURI)
if err != nil {
return nil, err
}