wallets listing dedupe
This commit is contained in:
@@ -31,7 +31,8 @@ type Imp struct {
|
||||
|
||||
type config struct {
|
||||
*grpcapp.Config `yaml:",inline"`
|
||||
Oracle OracleConfig `yaml:"oracle"`
|
||||
|
||||
Oracle OracleConfig `yaml:"oracle"`
|
||||
}
|
||||
|
||||
type OracleConfig struct {
|
||||
@@ -45,6 +46,7 @@ func (c OracleConfig) dialTimeout() time.Duration {
|
||||
if c.DialTimeoutSecs <= 0 {
|
||||
return 5 * time.Second
|
||||
}
|
||||
|
||||
return time.Duration(c.DialTimeoutSecs) * time.Second
|
||||
}
|
||||
|
||||
@@ -52,6 +54,7 @@ func (c OracleConfig) callTimeout() time.Duration {
|
||||
if c.CallTimeoutSecs <= 0 {
|
||||
return 3 * time.Second
|
||||
}
|
||||
|
||||
return time.Duration(c.CallTimeoutSecs) * time.Second
|
||||
}
|
||||
|
||||
@@ -69,9 +72,11 @@ func (i *Imp) Shutdown() {
|
||||
if i.service != nil {
|
||||
i.service.Shutdown()
|
||||
}
|
||||
|
||||
if i.oracleClient != nil {
|
||||
_ = i.oracleClient.Close()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -98,6 +103,7 @@ func (i *Imp) Start() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
i.config = cfg
|
||||
|
||||
repoFactory := func(logger mlogger.Logger, conn *db.MongoConnection) (storage.Repository, error) {
|
||||
@@ -105,11 +111,12 @@ func (i *Imp) Start() error {
|
||||
}
|
||||
|
||||
var oracleClient oracleclient.Client
|
||||
|
||||
if addr := strings.TrimSpace(cfg.Oracle.Address); addr != "" {
|
||||
dialCtx, cancel := context.WithTimeout(context.Background(), cfg.Oracle.dialTimeout())
|
||||
defer cancel()
|
||||
|
||||
oc, err := oracleclient.New(dialCtx, oracleclient.Config{
|
||||
oracleConn, err := oracleclient.New(dialCtx, oracleclient.Config{
|
||||
Address: addr,
|
||||
DialTimeout: cfg.Oracle.dialTimeout(),
|
||||
CallTimeout: cfg.Oracle.callTimeout(),
|
||||
@@ -118,8 +125,8 @@ func (i *Imp) Start() error {
|
||||
if err != nil {
|
||||
i.logger.Warn("Failed to initialise oracle client", zap.String("address", addr), zap.Error(err))
|
||||
} else {
|
||||
oracleClient = oc
|
||||
i.oracleClient = oc
|
||||
oracleClient = oracleConn
|
||||
i.oracleClient = oracleConn
|
||||
i.logger.Info("Connected to oracle service", zap.String("address", addr))
|
||||
}
|
||||
}
|
||||
@@ -129,13 +136,16 @@ func (i *Imp) Start() error {
|
||||
if oracleClient != nil {
|
||||
opts = append(opts, fees.WithOracleClient(oracleClient))
|
||||
}
|
||||
|
||||
if cfg.GRPC != nil {
|
||||
if invokeURI := cfg.GRPC.DiscoveryInvokeURI(); invokeURI != "" {
|
||||
opts = append(opts, fees.WithDiscoveryInvokeURI(invokeURI))
|
||||
}
|
||||
}
|
||||
|
||||
svc := fees.NewService(logger, repo, producer, opts...)
|
||||
i.service = svc
|
||||
|
||||
return svc, nil
|
||||
}
|
||||
|
||||
@@ -143,6 +153,7 @@ func (i *Imp) Start() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
i.app = app
|
||||
|
||||
return i.app.Start()
|
||||
@@ -152,12 +163,14 @@ func (i *Imp) loadConfig() (*config, error) {
|
||||
data, err := os.ReadFile(i.file)
|
||||
if err != nil {
|
||||
i.logger.Error("Could not read configuration file", zap.String("config_file", i.file), zap.Error(err))
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cfg := &config{Config: &grpcapp.Config{}}
|
||||
if err := yaml.Unmarshal(data, cfg); err != nil {
|
||||
i.logger.Error("Failed to parse configuration", zap.Error(err))
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user