tg-670 #671
@@ -45,9 +45,6 @@ gateway:
|
|||||||
treasury:
|
treasury:
|
||||||
execution_delay: 60s
|
execution_delay: 60s
|
||||||
poll_interval: 60s
|
poll_interval: 60s
|
||||||
telegram:
|
|
||||||
allowed_chats: []
|
|
||||||
users: []
|
|
||||||
ledger:
|
ledger:
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
limits:
|
limits:
|
||||||
|
|||||||
@@ -50,10 +50,3 @@ treasury:
|
|||||||
limits:
|
limits:
|
||||||
max_amount_per_operation: ""
|
max_amount_per_operation: ""
|
||||||
max_daily_amount: ""
|
max_daily_amount: ""
|
||||||
telegram:
|
|
||||||
allowed_chats: []
|
|
||||||
users:
|
|
||||||
- telegram_user_id: "8273799472"
|
|
||||||
ledger_account: "6972c738949b91ea0395e5fb"
|
|
||||||
- telegram_user_id: "8273507566"
|
|
||||||
ledger_account: "6995d6c118bca1d8baa5f2be"
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package serverimp
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tech/sendico/gateway/tgsettle/internal/service/gateway"
|
"github.com/tech/sendico/gateway/tgsettle/internal/service/gateway"
|
||||||
@@ -38,8 +37,6 @@ type config struct {
|
|||||||
*grpcapp.Config `yaml:",inline"`
|
*grpcapp.Config `yaml:",inline"`
|
||||||
Gateway gatewayConfig `yaml:"gateway"`
|
Gateway gatewayConfig `yaml:"gateway"`
|
||||||
Treasury treasuryConfig `yaml:"treasury"`
|
Treasury treasuryConfig `yaml:"treasury"`
|
||||||
Ledger ledgerConfig `yaml:"ledger"` // deprecated: use treasury.ledger
|
|
||||||
Telegram telegramConfig `yaml:"telegram"` // deprecated: use treasury.telegram
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type gatewayConfig struct {
|
type gatewayConfig struct {
|
||||||
@@ -50,20 +47,9 @@ type gatewayConfig struct {
|
|||||||
SuccessReaction string `yaml:"success_reaction"`
|
SuccessReaction string `yaml:"success_reaction"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type telegramConfig struct {
|
|
||||||
AllowedChats []string `yaml:"allowed_chats"`
|
|
||||||
Users []telegramUserConfig `yaml:"users"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type telegramUserConfig struct {
|
|
||||||
TelegramUserID string `yaml:"telegram_user_id"`
|
|
||||||
LedgerAccount string `yaml:"ledger_account"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type treasuryConfig struct {
|
type treasuryConfig struct {
|
||||||
ExecutionDelay time.Duration `yaml:"execution_delay"`
|
ExecutionDelay time.Duration `yaml:"execution_delay"`
|
||||||
PollInterval time.Duration `yaml:"poll_interval"`
|
PollInterval time.Duration `yaml:"poll_interval"`
|
||||||
Telegram telegramConfig `yaml:"telegram"`
|
|
||||||
Ledger ledgerConfig `yaml:"ledger"`
|
Ledger ledgerConfig `yaml:"ledger"`
|
||||||
Limits treasuryLimitsConfig `yaml:"limits"`
|
Limits treasuryLimitsConfig `yaml:"limits"`
|
||||||
}
|
}
|
||||||
@@ -145,8 +131,6 @@ func (i *Imp) Start() error {
|
|||||||
if cfg.Messaging != nil {
|
if cfg.Messaging != nil {
|
||||||
msgSettings = cfg.Messaging.Settings
|
msgSettings = cfg.Messaging.Settings
|
||||||
}
|
}
|
||||||
treasuryTelegram := treasuryTelegramConfig(cfg, i.logger)
|
|
||||||
treasuryLedger := treasuryLedgerConfig(cfg, i.logger)
|
|
||||||
gwCfg := gateway.Config{
|
gwCfg := gateway.Config{
|
||||||
Rail: cfg.Gateway.Rail,
|
Rail: cfg.Gateway.Rail,
|
||||||
TargetChatIDEnv: cfg.Gateway.TargetChatIDEnv,
|
TargetChatIDEnv: cfg.Gateway.TargetChatIDEnv,
|
||||||
@@ -159,12 +143,8 @@ func (i *Imp) Start() error {
|
|||||||
Treasury: gateway.TreasuryConfig{
|
Treasury: gateway.TreasuryConfig{
|
||||||
ExecutionDelay: cfg.Treasury.ExecutionDelay,
|
ExecutionDelay: cfg.Treasury.ExecutionDelay,
|
||||||
PollInterval: cfg.Treasury.PollInterval,
|
PollInterval: cfg.Treasury.PollInterval,
|
||||||
Telegram: gateway.TelegramConfig{
|
|
||||||
AllowedChats: treasuryTelegram.AllowedChats,
|
|
||||||
Users: telegramUsers(treasuryTelegram.Users),
|
|
||||||
},
|
|
||||||
Ledger: gateway.LedgerConfig{
|
Ledger: gateway.LedgerConfig{
|
||||||
Timeout: treasuryLedger.Timeout,
|
Timeout: cfg.Treasury.Ledger.Timeout,
|
||||||
},
|
},
|
||||||
Limits: gateway.TreasuryLimitsConfig{
|
Limits: gateway.TreasuryLimitsConfig{
|
||||||
MaxAmountPerOperation: cfg.Treasury.Limits.MaxAmountPerOperation,
|
MaxAmountPerOperation: cfg.Treasury.Limits.MaxAmountPerOperation,
|
||||||
@@ -228,46 +208,3 @@ func (i *Imp) loadConfig() (*config, error) {
|
|||||||
}
|
}
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func telegramUsers(input []telegramUserConfig) []gateway.TelegramUserBinding {
|
|
||||||
result := make([]gateway.TelegramUserBinding, 0, len(input))
|
|
||||||
for _, next := range input {
|
|
||||||
result = append(result, gateway.TelegramUserBinding{
|
|
||||||
TelegramUserID: strings.TrimSpace(next.TelegramUserID),
|
|
||||||
LedgerAccount: strings.TrimSpace(next.LedgerAccount),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func treasuryTelegramConfig(cfg *config, logger mlogger.Logger) telegramConfig {
|
|
||||||
if cfg == nil {
|
|
||||||
return telegramConfig{}
|
|
||||||
}
|
|
||||||
if len(cfg.Treasury.Telegram.Users) > 0 || len(cfg.Treasury.Telegram.AllowedChats) > 0 {
|
|
||||||
return cfg.Treasury.Telegram
|
|
||||||
}
|
|
||||||
if len(cfg.Telegram.Users) > 0 || len(cfg.Telegram.AllowedChats) > 0 {
|
|
||||||
if logger != nil {
|
|
||||||
logger.Warn("Deprecated config path used: telegram.*; move these settings to treasury.telegram.*")
|
|
||||||
}
|
|
||||||
return cfg.Telegram
|
|
||||||
}
|
|
||||||
return cfg.Treasury.Telegram
|
|
||||||
}
|
|
||||||
|
|
||||||
func treasuryLedgerConfig(cfg *config, logger mlogger.Logger) ledgerConfig {
|
|
||||||
if cfg == nil {
|
|
||||||
return ledgerConfig{}
|
|
||||||
}
|
|
||||||
if cfg.Treasury.Ledger.Timeout > 0 {
|
|
||||||
return cfg.Treasury.Ledger
|
|
||||||
}
|
|
||||||
if cfg.Ledger.Timeout > 0 {
|
|
||||||
if logger != nil {
|
|
||||||
logger.Warn("Deprecated config path used: ledger.*; move these settings to treasury.ledger.*")
|
|
||||||
}
|
|
||||||
return cfg.Ledger
|
|
||||||
}
|
|
||||||
return cfg.Treasury.Ledger
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -68,20 +68,9 @@ type Config struct {
|
|||||||
Treasury TreasuryConfig
|
Treasury TreasuryConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
type TelegramConfig struct {
|
|
||||||
AllowedChats []string
|
|
||||||
Users []TelegramUserBinding
|
|
||||||
}
|
|
||||||
|
|
||||||
type TelegramUserBinding struct {
|
|
||||||
TelegramUserID string
|
|
||||||
LedgerAccount string
|
|
||||||
}
|
|
||||||
|
|
||||||
type TreasuryConfig struct {
|
type TreasuryConfig struct {
|
||||||
ExecutionDelay time.Duration
|
ExecutionDelay time.Duration
|
||||||
PollInterval time.Duration
|
PollInterval time.Duration
|
||||||
Telegram TelegramConfig
|
|
||||||
Ledger LedgerConfig
|
Ledger LedgerConfig
|
||||||
Limits TreasuryLimitsConfig
|
Limits TreasuryLimitsConfig
|
||||||
}
|
}
|
||||||
@@ -188,9 +177,6 @@ func (s *Service) startTreasuryModule() {
|
|||||||
s.logger.Warn("Treasury module disabled: discovery registry is unavailable")
|
s.logger.Warn("Treasury module disabled: discovery registry is unavailable")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(s.cfg.Treasury.Telegram.Users) > 0 || len(s.cfg.Treasury.Telegram.AllowedChats) > 0 {
|
|
||||||
s.logger.Warn("Treasury telegram config users/chats are ignored; use treasury_telegram_users collection for runtime authorization")
|
|
||||||
}
|
|
||||||
|
|
||||||
ledgerTimeout := s.cfg.Treasury.Ledger.Timeout
|
ledgerTimeout := s.cfg.Treasury.Ledger.Timeout
|
||||||
if ledgerTimeout <= 0 {
|
if ledgerTimeout <= 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user