removed obsolete errors
This commit is contained in:
@@ -6,12 +6,13 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Mw *mwa.Config `yaml:"middleware"`
|
||||
Storage *fsc.Config `yaml:"storage"`
|
||||
Mw *mwa.Config `yaml:"middleware"`
|
||||
Storage *fsc.Config `yaml:"storage"`
|
||||
ChainGateway *ChainGatewayConfig `yaml:"chain_gateway"`
|
||||
}
|
||||
|
||||
type ChainGatewayConfig struct {
|
||||
Address string `yaml:"address"`
|
||||
AddressEnv string `yaml:"address_env"`
|
||||
DialTimeoutSeconds int `yaml:"dial_timeout_seconds"`
|
||||
CallTimeoutSeconds int `yaml:"call_timeout_seconds"`
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/db/refreshtokens"
|
||||
"github.com/tech/sendico/pkg/db/transaction"
|
||||
"github.com/tech/sendico/pkg/domainprovider"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/messaging"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
@@ -142,7 +143,12 @@ func CreateAPI(a eapi.API) (*AccountAPI, error) {
|
||||
}
|
||||
p.accountsPermissionRef = accountsPolicy.ID
|
||||
|
||||
if err := p.initChainGateway(a.Config()); err != nil {
|
||||
cfg := a.Config()
|
||||
if cfg == nil {
|
||||
p.logger.Error("Failed to fetch service configuration")
|
||||
return nil, merrors.InvalidArgument("No configuration provided")
|
||||
}
|
||||
if err := p.initChainGateway(cfg.ChainGateway); err != nil {
|
||||
p.logger.Error("Failed to initialize chain gateway client", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
@@ -150,21 +156,21 @@ func CreateAPI(a eapi.API) (*AccountAPI, error) {
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (a *AccountAPI) initChainGateway(cfg *eapi.Config) error {
|
||||
if cfg == nil || cfg.ChainGateway == nil {
|
||||
return fmt.Errorf("chain gateway configuration is not provided")
|
||||
func (a *AccountAPI) initChainGateway(cfg *eapi.ChainGatewayConfig) error {
|
||||
if cfg == nil {
|
||||
return merrors.InvalidArgument("chain gateway configuration is not provided")
|
||||
}
|
||||
|
||||
address := strings.TrimSpace(os.Getenv(cfg.ChainGateway.AddressEnv))
|
||||
address := strings.TrimSpace(os.Getenv(cfg.AddressEnv))
|
||||
if address == "" {
|
||||
return fmt.Errorf("chain gateway address env %s is empty", cfg.ChainGateway.AddressEnv)
|
||||
return merrors.InvalidArgument(fmt.Sprintf("chain gateway address env %s is empty", cfg.AddressEnv))
|
||||
}
|
||||
|
||||
clientCfg := chaingatewayclient.Config{
|
||||
Address: address,
|
||||
DialTimeout: time.Duration(cfg.ChainGateway.DialTimeoutSeconds) * time.Second,
|
||||
CallTimeout: time.Duration(cfg.ChainGateway.CallTimeoutSeconds) * time.Second,
|
||||
Insecure: cfg.ChainGateway.Insecure,
|
||||
DialTimeout: time.Duration(cfg.DialTimeoutSeconds) * time.Second,
|
||||
CallTimeout: time.Duration(cfg.CallTimeoutSeconds) * time.Second,
|
||||
Insecure: cfg.Insecure,
|
||||
}
|
||||
|
||||
client, err := chaingatewayclient.New(context.Background(), clientCfg)
|
||||
@@ -172,7 +178,7 @@ func (a *AccountAPI) initChainGateway(cfg *eapi.Config) error {
|
||||
return err
|
||||
}
|
||||
|
||||
asset, err := buildGatewayAsset(cfg.ChainGateway.DefaultAsset)
|
||||
asset, err := buildGatewayAsset(cfg.DefaultAsset)
|
||||
if err != nil {
|
||||
_ = client.Close()
|
||||
return err
|
||||
@@ -190,7 +196,7 @@ func buildGatewayAsset(cfg eapi.ChainGatewayAssetConfig) (*gatewayv1.Asset, erro
|
||||
}
|
||||
tokenSymbol := strings.TrimSpace(cfg.TokenSymbol)
|
||||
if tokenSymbol == "" {
|
||||
return nil, fmt.Errorf("chain gateway token symbol is required")
|
||||
return nil, merrors.InvalidArgument("chain gateway token symbol is required")
|
||||
}
|
||||
return &gatewayv1.Asset{
|
||||
Chain: chain,
|
||||
@@ -208,8 +214,8 @@ func parseChainNetwork(value string) (gatewayv1.ChainNetwork, error) {
|
||||
case "OTHER_EVM", "CHAIN_NETWORK_OTHER_EVM":
|
||||
return gatewayv1.ChainNetwork_CHAIN_NETWORK_OTHER_EVM, nil
|
||||
case "", "CHAIN_NETWORK_UNSPECIFIED":
|
||||
return gatewayv1.ChainNetwork_CHAIN_NETWORK_UNSPECIFIED, fmt.Errorf("chain network must be specified")
|
||||
return gatewayv1.ChainNetwork_CHAIN_NETWORK_UNSPECIFIED, merrors.InvalidArgument("chain network must be specified")
|
||||
default:
|
||||
return gatewayv1.ChainNetwork_CHAIN_NETWORK_UNSPECIFIED, fmt.Errorf("unsupported chain network %s", value)
|
||||
return gatewayv1.ChainNetwork_CHAIN_NETWORK_UNSPECIFIED, merrors.InvalidArgument("unsupported chain network %s", value)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user