Merge pull request 'refactored deprecated code' (#621) from pkg-620 into main
Some checks failed
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/billing_documents Pipeline was successful
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/callbacks Pipeline was successful
ci/woodpecker/push/discovery Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline failed
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/gateway_chain Pipeline was successful
ci/woodpecker/push/gateway_mntx Pipeline was successful
ci/woodpecker/push/gateway_tgsettle Pipeline was successful
ci/woodpecker/push/gateway_tron Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful
ci/woodpecker/push/payments_methods Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline was successful
ci/woodpecker/push/payments_quotation Pipeline was successful

Reviewed-on: #621
This commit was merged in pull request #621.
This commit is contained in:
2026-03-03 21:29:22 +00:00
14 changed files with 54 additions and 70 deletions

View File

@@ -105,10 +105,7 @@ func (a *PaymentAPI) getActDocument(r *http.Request, account *model.Account, _ *
} }
func (a *PaymentAPI) fetchActDocument(ctx context.Context, invokeURI, paymentRef string) (*documentsv1.GetDocumentResponse, error) { func (a *PaymentAPI) fetchActDocument(ctx context.Context, invokeURI, paymentRef string) (*documentsv1.GetDocumentResponse, error) {
dialCtx, cancel := context.WithTimeout(ctx, documentsDialTimeout) conn, err := grpc.NewClient(invokeURI, grpc.WithTransportCredentials(insecure.NewCredentials()))
defer cancel()
conn, err := grpc.DialContext(dialCtx, invokeURI, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil { if err != nil {
return nil, merrors.InternalWrap(err, "dial billing documents") return nil, merrors.InternalWrap(err, "dial billing documents")
} }

View File

@@ -213,9 +213,6 @@ func newQuotationClient(ctx context.Context, cfg quotationClientConfig, opts ...
return nil, merrors.InvalidArgument("payment quotation: address is required") return nil, merrors.InvalidArgument("payment quotation: address is required")
} }
dialCtx, cancel := context.WithTimeout(ctx, cfg.DialTimeout)
defer cancel()
dialOpts := make([]grpc.DialOption, 0, len(opts)+1) dialOpts := make([]grpc.DialOption, 0, len(opts)+1)
dialOpts = append(dialOpts, opts...) dialOpts = append(dialOpts, opts...)
if cfg.Insecure { if cfg.Insecure {
@@ -224,7 +221,7 @@ func newQuotationClient(ctx context.Context, cfg quotationClientConfig, opts ...
dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{}))) dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})))
} }
conn, err := grpc.DialContext(dialCtx, cfg.Address, dialOpts...) conn, err := grpc.NewClient(cfg.Address, dialOpts...)
if err != nil { if err != nil {
return nil, merrors.InternalWrap(err, fmt.Sprintf("payment-quotation: dial %s", cfg.Address)) return nil, merrors.InternalWrap(err, fmt.Sprintf("payment-quotation: dial %s", cfg.Address))
} }

View File

@@ -227,10 +227,6 @@ func (a *WalletAPI) queryBalanceFromGateways(ctx context.Context, gateways []dis
} }
func (a *WalletAPI) queryGatewayBalance(ctx context.Context, gateway discovery.GatewaySummary, walletRef string) (*connectorv1.Balance, error) { func (a *WalletAPI) queryGatewayBalance(ctx context.Context, gateway discovery.GatewaySummary, walletRef string) (*connectorv1.Balance, error) {
// Create connection with timeout
dialCtx, cancel := context.WithTimeout(ctx, a.dialTimeout)
defer cancel()
var dialOpts []grpc.DialOption var dialOpts []grpc.DialOption
if a.insecure { if a.insecure {
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials())) dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
@@ -238,7 +234,7 @@ func (a *WalletAPI) queryGatewayBalance(ctx context.Context, gateway discovery.G
dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{}))) dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})))
} }
conn, err := grpc.DialContext(dialCtx, gateway.InvokeURI, dialOpts...) conn, err := grpc.NewClient(gateway.InvokeURI, dialOpts...)
if err != nil { if err != nil {
return nil, merrors.InternalWrap(err, "dial gateway") return nil, merrors.InternalWrap(err, "dial gateway")
} }

View File

@@ -162,10 +162,6 @@ func findGatewayForNetwork(gateways []discovery.GatewaySummary, network string)
} }
func (a *WalletAPI) createWalletOnGateway(ctx context.Context, gateway discovery.GatewaySummary, req *connectorv1.OpenAccountRequest) (string, error) { func (a *WalletAPI) createWalletOnGateway(ctx context.Context, gateway discovery.GatewaySummary, req *connectorv1.OpenAccountRequest) (string, error) {
// Create connection with timeout
dialCtx, cancel := context.WithTimeout(ctx, a.dialTimeout)
defer cancel()
var dialOpts []grpc.DialOption var dialOpts []grpc.DialOption
if a.insecure { if a.insecure {
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials())) dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
@@ -173,7 +169,7 @@ func (a *WalletAPI) createWalletOnGateway(ctx context.Context, gateway discovery
dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{}))) dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})))
} }
conn, err := grpc.DialContext(dialCtx, gateway.InvokeURI, dialOpts...) conn, err := grpc.NewClient(gateway.InvokeURI, dialOpts...)
if err != nil { if err != nil {
return "", merrors.InternalWrap(err, "dial gateway") return "", merrors.InternalWrap(err, "dial gateway")
} }

View File

@@ -215,10 +215,6 @@ func (a *WalletAPI) queryAllGateways(ctx context.Context, gateways []discovery.G
} }
func (a *WalletAPI) queryGateway(ctx context.Context, gateway discovery.GatewaySummary, req *connectorv1.ListAccountsRequest) ([]*connectorv1.Account, error) { func (a *WalletAPI) queryGateway(ctx context.Context, gateway discovery.GatewaySummary, req *connectorv1.ListAccountsRequest) ([]*connectorv1.Account, error) {
// Create connection with timeout
dialCtx, cancel := context.WithTimeout(ctx, a.dialTimeout)
defer cancel()
var dialOpts []grpc.DialOption var dialOpts []grpc.DialOption
if a.insecure { if a.insecure {
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials())) dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
@@ -226,7 +222,7 @@ func (a *WalletAPI) queryGateway(ctx context.Context, gateway discovery.GatewayS
dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{}))) dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})))
} }
conn, err := grpc.DialContext(dialCtx, gateway.InvokeURI, dialOpts...) conn, err := grpc.NewClient(gateway.InvokeURI, dialOpts...)
if err != nil { if err != nil {
return nil, merrors.InternalWrap(err, "dial gateway") return nil, merrors.InternalWrap(err, "dial gateway")
} }

View File

@@ -92,9 +92,6 @@ func New(ctx context.Context, cfg Config, opts ...grpc.DialOption) (Client, erro
return nil, merrors.InvalidArgument("oracle: address is required") return nil, merrors.InvalidArgument("oracle: address is required")
} }
dialCtx, cancel := context.WithTimeout(ctx, cfg.DialTimeout)
defer cancel()
dialOpts := make([]grpc.DialOption, 0, len(opts)+1) dialOpts := make([]grpc.DialOption, 0, len(opts)+1)
dialOpts = append(dialOpts, opts...) dialOpts = append(dialOpts, opts...)
@@ -104,7 +101,7 @@ func New(ctx context.Context, cfg Config, opts ...grpc.DialOption) (Client, erro
dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{}))) dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})))
} }
conn, err := grpc.DialContext(dialCtx, cfg.Address, dialOpts...) conn, err := grpc.NewClient(cfg.Address, dialOpts...)
if err != nil { if err != nil {
return nil, merrors.InternalWrap(err, fmt.Sprintf("oracle: dial %s", cfg.Address)) return nil, merrors.InternalWrap(err, fmt.Sprintf("oracle: dial %s", cfg.Address))
} }

View File

@@ -63,9 +63,6 @@ func New(ctx context.Context, cfg Config, opts ...grpc.DialOption) (Client, erro
return nil, merrors.InvalidArgument("chain-gateway: address is required") return nil, merrors.InvalidArgument("chain-gateway: address is required")
} }
dialCtx, cancel := context.WithTimeout(ctx, cfg.DialTimeout)
defer cancel()
dialOpts := make([]grpc.DialOption, 0, len(opts)+1) dialOpts := make([]grpc.DialOption, 0, len(opts)+1)
dialOpts = append(dialOpts, opts...) dialOpts = append(dialOpts, opts...)
@@ -75,7 +72,7 @@ func New(ctx context.Context, cfg Config, opts ...grpc.DialOption) (Client, erro
dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{}))) dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})))
} }
conn, err := grpc.DialContext(dialCtx, cfg.Address, dialOpts...) conn, err := grpc.NewClient(cfg.Address, dialOpts...)
if err != nil { if err != nil {
return nil, merrors.Internal(fmt.Sprintf("chain-gateway: dial %s: %s", cfg.Address, err.Error())) return nil, merrors.Internal(fmt.Sprintf("chain-gateway: dial %s: %s", cfg.Address, err.Error()))
} }

View File

@@ -45,14 +45,11 @@ func New(ctx context.Context, cfg Config, opts ...grpc.DialOption) (Client, erro
if strings.TrimSpace(cfg.Address) == "" { if strings.TrimSpace(cfg.Address) == "" {
return nil, merrors.InvalidArgument("mntx: address is required") return nil, merrors.InvalidArgument("mntx: address is required")
} }
dialCtx, cancel := context.WithTimeout(ctx, cfg.DialTimeout)
defer cancel()
dialOpts := make([]grpc.DialOption, 0, len(opts)+1) dialOpts := make([]grpc.DialOption, 0, len(opts)+1)
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials())) dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
dialOpts = append(dialOpts, opts...) dialOpts = append(dialOpts, opts...)
conn, err := grpc.DialContext(dialCtx, cfg.Address, dialOpts...) conn, err := grpc.NewClient(cfg.Address, dialOpts...)
if err != nil { if err != nil {
return nil, merrors.Internal("mntx: dial failed: " + err.Error()) return nil, merrors.Internal("mntx: dial failed: " + err.Error())
} }

View File

@@ -105,9 +105,6 @@ func New(ctx context.Context, cfg Config, opts ...grpc.DialOption) (Client, erro
return nil, merrors.InvalidArgument("ledger: address is required") return nil, merrors.InvalidArgument("ledger: address is required")
} }
dialCtx, cancel := context.WithTimeout(ctx, cfg.DialTimeout)
defer cancel()
dialOpts := make([]grpc.DialOption, 0, len(opts)+1) dialOpts := make([]grpc.DialOption, 0, len(opts)+1)
dialOpts = append(dialOpts, opts...) dialOpts = append(dialOpts, opts...)
@@ -117,7 +114,7 @@ func New(ctx context.Context, cfg Config, opts ...grpc.DialOption) (Client, erro
dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{}))) dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})))
} }
conn, err := grpc.DialContext(dialCtx, cfg.Address, dialOpts...) conn, err := grpc.NewClient(cfg.Address, dialOpts...)
if err != nil { if err != nil {
return nil, merrors.InternalWrap(err, fmt.Sprintf("ledger: dial %s", cfg.Address)) return nil, merrors.InternalWrap(err, fmt.Sprintf("ledger: dial %s", cfg.Address))
} }

View File

@@ -49,9 +49,6 @@ func New(ctx context.Context, cfg Config, opts ...grpc.DialOption) (Client, erro
return nil, merrors.InvalidArgument("payment-methods: address is required") return nil, merrors.InvalidArgument("payment-methods: address is required")
} }
dialCtx, cancel := context.WithTimeout(ctx, cfg.DialTimeout)
defer cancel()
dialOpts := make([]grpc.DialOption, 0, len(opts)+1) dialOpts := make([]grpc.DialOption, 0, len(opts)+1)
dialOpts = append(dialOpts, opts...) dialOpts = append(dialOpts, opts...)
if cfg.Insecure { if cfg.Insecure {
@@ -60,7 +57,7 @@ func New(ctx context.Context, cfg Config, opts ...grpc.DialOption) (Client, erro
dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{}))) dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})))
} }
conn, err := grpc.DialContext(dialCtx, cfg.Address, dialOpts...) conn, err := grpc.NewClient(cfg.Address, dialOpts...)
if err != nil { if err != nil {
return nil, merrors.InternalWrap(err, fmt.Sprintf("payment-methods: dial %s", cfg.Address)) return nil, merrors.InternalWrap(err, fmt.Sprintf("payment-methods: dial %s", cfg.Address))
} }

View File

@@ -56,8 +56,6 @@ func New(ctx context.Context, cfg Config, opts ...grpc.DialOption) (Client, erro
} }
func dial(ctx context.Context, cfg Config, address string, opts ...grpc.DialOption) (*grpc.ClientConn, error) { func dial(ctx context.Context, cfg Config, address string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
dialCtx, cancel := context.WithTimeout(ctx, cfg.DialTimeout)
defer cancel()
dialOpts := make([]grpc.DialOption, 0, len(opts)+1) dialOpts := make([]grpc.DialOption, 0, len(opts)+1)
dialOpts = append(dialOpts, opts...) dialOpts = append(dialOpts, opts...)
@@ -67,7 +65,7 @@ func dial(ctx context.Context, cfg Config, address string, opts ...grpc.DialOpti
dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{}))) dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})))
} }
conn, err := grpc.DialContext(dialCtx, address, dialOpts...) conn, err := grpc.NewClient(address, dialOpts...)
if err != nil { if err != nil {
return nil, merrors.InternalWrap(err, fmt.Sprintf("payment-orchestrator: dial %s", address)) return nil, merrors.InternalWrap(err, fmt.Sprintf("payment-orchestrator: dial %s", address))
} }

View File

@@ -451,5 +451,5 @@ func dialGrpc(ctx context.Context, endpoint discoveryEndpoint) (*grpc.ClientConn
if ctx == nil { if ctx == nil {
ctx = context.Background() ctx = context.Background()
} }
return grpc.DialContext(ctx, endpoint.address, dialOpts...) return grpc.NewClient(endpoint.address, dialOpts...)
} }

View File

@@ -10,6 +10,7 @@ import (
feesv1 "github.com/tech/sendico/pkg/proto/billing/fees/v1" feesv1 "github.com/tech/sendico/pkg/proto/billing/fees/v1"
"go.uber.org/zap" "go.uber.org/zap"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/credentials/insecure"
) )
@@ -82,19 +83,33 @@ func dialGRPC(ctx context.Context, cfg clientConfig, address string) (*grpc.Clie
ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
} }
dialOpts := make([]grpc.DialOption, 0, 1)
if cfg.InsecureTransport { if cfg.InsecureTransport {
return grpc.DialContext( dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
ctx, } else {
address, dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})))
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
)
} }
return grpc.DialContext( conn, err := grpc.NewClient(address, dialOpts...)
ctx, if err != nil {
address, return nil, err
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})), }
grpc.WithBlock(), conn.Connect()
) if err := waitUntilReady(ctx, conn); err != nil {
_ = conn.Close()
return nil, err
}
return conn, nil
}
func waitUntilReady(ctx context.Context, conn *grpc.ClientConn) error {
for {
state := conn.GetState()
if state == connectivity.Ready {
return nil
}
if !conn.WaitForStateChange(ctx, state) {
return ctx.Err()
}
}
} }

View File

@@ -10,6 +10,7 @@ import (
msg "github.com/tech/sendico/pkg/messaging" msg "github.com/tech/sendico/pkg/messaging"
"github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/mlogger"
"go.uber.org/zap" "go.uber.org/zap"
"go.uber.org/zap/zapcore"
) )
const defaultReannounceHeartbeatFactor = 6 const defaultReannounceHeartbeatFactor = 6
@@ -20,10 +21,11 @@ type Announcer struct {
sender string sender string
announce Announcement announce Announcement
startOnce sync.Once startOnce sync.Once
stopOnce sync.Once stopOnce sync.Once
stopCh chan struct{} stopCh chan struct{}
doneCh chan struct{} doneCh chan struct{}
announceLevel zapcore.Level
} }
func NewAnnouncer(logger mlogger.Logger, producer msg.Producer, sender string, announce Announcement) *Announcer { func NewAnnouncer(logger mlogger.Logger, producer msg.Producer, sender string, announce Announcement) *Announcer {
@@ -42,12 +44,13 @@ func NewAnnouncer(logger mlogger.Logger, producer msg.Producer, sender string, a
announce.ID = DefaultEntryID(announce.Service) announce.ID = DefaultEntryID(announce.Service)
} }
return &Announcer{ return &Announcer{
logger: logger, logger: logger,
producer: producer, producer: producer,
sender: strings.TrimSpace(sender), sender: strings.TrimSpace(sender),
announce: announce, announce: announce,
stopCh: make(chan struct{}), stopCh: make(chan struct{}),
doneCh: make(chan struct{}), doneCh: make(chan struct{}),
announceLevel: zapcore.InfoLevel,
} }
} }
@@ -126,7 +129,8 @@ func (a *Announcer) sendAnnouncement() {
a.logWarn("Failed to publish discovery announce", fields...) a.logWarn("Failed to publish discovery announce", fields...)
return return
} }
a.logInfo("Discovery announce published", append(announcementFields(a.announce), zap.String("event", event.ToString()))...) a.logger.Log(a.announceLevel, "Discovery announce published", append(announcementFields(a.announce), zap.String("event", event.ToString()))...)
a.announceLevel = zapcore.DebugLevel
} }
func (a *Announcer) sendHeartbeat() { func (a *Announcer) sendHeartbeat() {