|
|
|
|
@@ -9,6 +9,7 @@ import (
|
|
|
|
|
|
|
|
|
|
oracleclient "github.com/tech/sendico/fx/oracle/client"
|
|
|
|
|
chainclient "github.com/tech/sendico/gateway/chain/client"
|
|
|
|
|
mntxclient "github.com/tech/sendico/gateway/mntx/client"
|
|
|
|
|
ledgerclient "github.com/tech/sendico/ledger/client"
|
|
|
|
|
"github.com/tech/sendico/payments/orchestrator/internal/service/orchestrator"
|
|
|
|
|
"github.com/tech/sendico/payments/orchestrator/storage"
|
|
|
|
|
@@ -36,6 +37,7 @@ type Imp struct {
|
|
|
|
|
feesConn *grpc.ClientConn
|
|
|
|
|
ledgerClient ledgerclient.Client
|
|
|
|
|
gatewayClient chainclient.Client
|
|
|
|
|
mntxClient mntxclient.Client
|
|
|
|
|
oracleClient oracleclient.Client
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -44,6 +46,7 @@ type config struct {
|
|
|
|
|
Fees clientConfig `yaml:"fees"`
|
|
|
|
|
Ledger clientConfig `yaml:"ledger"`
|
|
|
|
|
Gateway clientConfig `yaml:"gateway"`
|
|
|
|
|
Mntx clientConfig `yaml:"mntx"`
|
|
|
|
|
Oracle clientConfig `yaml:"oracle"`
|
|
|
|
|
CardGateways map[string]cardGatewayRouteConfig `yaml:"card_gateways"`
|
|
|
|
|
FeeAccounts map[string]string `yaml:"fee_ledger_accounts"`
|
|
|
|
|
@@ -105,6 +108,9 @@ func (i *Imp) Shutdown() {
|
|
|
|
|
if i.gatewayClient != nil {
|
|
|
|
|
_ = i.gatewayClient.Close()
|
|
|
|
|
}
|
|
|
|
|
if i.mntxClient != nil {
|
|
|
|
|
_ = i.mntxClient.Close()
|
|
|
|
|
}
|
|
|
|
|
if i.oracleClient != nil {
|
|
|
|
|
_ = i.oracleClient.Close()
|
|
|
|
|
}
|
|
|
|
|
@@ -139,6 +145,11 @@ func (i *Imp) Start() error {
|
|
|
|
|
i.gatewayClient = gatewayClient
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mntxClient := i.initMntxClient(cfg.Mntx)
|
|
|
|
|
if mntxClient != nil {
|
|
|
|
|
i.mntxClient = mntxClient
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
oracleClient := i.initOracleClient(cfg.Oracle)
|
|
|
|
|
if oracleClient != nil {
|
|
|
|
|
i.oracleClient = oracleClient
|
|
|
|
|
@@ -155,6 +166,9 @@ func (i *Imp) Start() error {
|
|
|
|
|
if gatewayClient != nil {
|
|
|
|
|
opts = append(opts, orchestrator.WithChainGatewayClient(gatewayClient))
|
|
|
|
|
}
|
|
|
|
|
if mntxClient != nil {
|
|
|
|
|
opts = append(opts, orchestrator.WithMntxGateway(mntxClient))
|
|
|
|
|
}
|
|
|
|
|
if oracleClient != nil {
|
|
|
|
|
opts = append(opts, orchestrator.WithOracleClient(oracleClient))
|
|
|
|
|
}
|
|
|
|
|
@@ -192,11 +206,11 @@ func (i *Imp) initFeesClient(cfg clientConfig) (feesv1.FeeEngineClient, *grpc.Cl
|
|
|
|
|
|
|
|
|
|
conn, err := grpc.DialContext(dialCtx, addr, grpc.WithTransportCredentials(creds))
|
|
|
|
|
if err != nil {
|
|
|
|
|
i.logger.Warn("failed to connect to fees service", zap.String("address", addr), zap.Error(err))
|
|
|
|
|
i.logger.Warn("Failed to connect to fees service", zap.String("address", addr), zap.Error(err))
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i.logger.Info("connected to fees service", zap.String("address", addr))
|
|
|
|
|
i.logger.Info("Connected to fees service", zap.String("address", addr))
|
|
|
|
|
return feesv1.NewFeeEngineClient(conn), conn
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -216,10 +230,10 @@ func (i *Imp) initLedgerClient(cfg clientConfig) ledgerclient.Client {
|
|
|
|
|
Insecure: cfg.InsecureTransport,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
i.logger.Warn("failed to connect to ledger service", zap.String("address", addr), zap.Error(err))
|
|
|
|
|
i.logger.Warn("Failed to connect to ledger service", zap.String("address", addr), zap.Error(err))
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
i.logger.Info("connected to ledger service", zap.String("address", addr))
|
|
|
|
|
i.logger.Info("Connected to ledger service", zap.String("address", addr))
|
|
|
|
|
return client
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -246,6 +260,28 @@ func (i *Imp) initGatewayClient(cfg clientConfig) chainclient.Client {
|
|
|
|
|
return client
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (i *Imp) initMntxClient(cfg clientConfig) mntxclient.Client {
|
|
|
|
|
addr := cfg.address()
|
|
|
|
|
if addr == "" {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), cfg.dialTimeout())
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
client, err := mntxclient.New(ctx, mntxclient.Config{
|
|
|
|
|
Address: addr,
|
|
|
|
|
DialTimeout: cfg.dialTimeout(),
|
|
|
|
|
CallTimeout: cfg.callTimeout(),
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
i.logger.Warn("Failed to connect to mntx gateway service", zap.String("address", addr), zap.Error(err))
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
i.logger.Info("Connected to mntx gateway service", zap.String("address", addr))
|
|
|
|
|
return client
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (i *Imp) initOracleClient(cfg clientConfig) oracleclient.Client {
|
|
|
|
|
addr := cfg.address()
|
|
|
|
|
if addr == "" {
|
|
|
|
|
@@ -262,10 +298,10 @@ func (i *Imp) initOracleClient(cfg clientConfig) oracleclient.Client {
|
|
|
|
|
Insecure: cfg.InsecureTransport,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
i.logger.Warn("failed to connect to oracle service", zap.String("address", addr), zap.Error(err))
|
|
|
|
|
i.logger.Warn("Failed to connect to oracle service", zap.String("address", addr), zap.Error(err))
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
i.logger.Info("connected to oracle service", zap.String("address", addr))
|
|
|
|
|
i.logger.Info("Connected to oracle service", zap.String("address", addr))
|
|
|
|
|
return client
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|