Files
sendico/api/gateway/chain/internal/service/gateway/options.go
2025-12-05 10:55:01 +01:00

77 lines
1.9 KiB
Go

package gateway
import (
"strings"
"github.com/tech/sendico/gateway/chain/internal/keymanager"
"github.com/tech/sendico/gateway/chain/internal/service/gateway/shared"
clockpkg "github.com/tech/sendico/pkg/clock"
)
// Option configures the Service.
type Option func(*Service)
// WithKeyManager configures the service key manager.
func WithKeyManager(manager keymanager.Manager) Option {
return func(s *Service) {
s.keyManager = manager
}
}
// WithTransferExecutor configures the executor responsible for on-chain submissions.
func WithTransferExecutor(executor TransferExecutor) Option {
return func(s *Service) {
s.executor = executor
}
}
// WithNetworks configures supported blockchain networks.
func WithNetworks(networks []shared.Network) Option {
return func(s *Service) {
if len(networks) == 0 {
return
}
if s.networks == nil {
s.networks = make(map[string]shared.Network, len(networks))
}
for _, network := range networks {
if network.Name == "" {
continue
}
clone := network
if clone.TokenConfigs == nil {
clone.TokenConfigs = []shared.TokenContract{}
}
for i := range clone.TokenConfigs {
clone.TokenConfigs[i].Symbol = strings.ToUpper(strings.TrimSpace(clone.TokenConfigs[i].Symbol))
clone.TokenConfigs[i].ContractAddress = strings.ToLower(strings.TrimSpace(clone.TokenConfigs[i].ContractAddress))
}
clone.Name = strings.ToLower(strings.TrimSpace(clone.Name))
s.networks[clone.Name] = clone
}
}
}
// WithServiceWallet configures the service wallet binding.
func WithServiceWallet(wallet shared.ServiceWallet) Option {
return func(s *Service) {
s.serviceWallet = wallet
}
}
// WithClock overrides the service clock.
func WithClock(clk clockpkg.Clock) Option {
return func(s *Service) {
if clk != nil {
s.clock = clk
}
}
}
// WithSettings applies gateway settings.
func WithSettings(settings CacheSettings) Option {
return func(s *Service) {
s.settings = settings.withDefaults()
}
}