linting
This commit is contained in:
@@ -217,7 +217,7 @@ func (s *Service) onTelegramUpdate(ctx context.Context, update *model.TelegramWe
|
||||
ReplyToMessageID: message.MessageID,
|
||||
Text: "Only approved users can confirm this payment.",
|
||||
}); e != nil {
|
||||
s.logger.Warn("Failed to create telegram text", append(replyFields, zap.Error(err))...)
|
||||
s.logger.Warn("Failed to create telegram text", append(replyFields, zap.Error(e))...)
|
||||
}
|
||||
if err := s.clearPendingConfirmation(ctx, pending.RequestID); err != nil {
|
||||
return err
|
||||
@@ -307,13 +307,13 @@ func (s *Service) publishPendingConfirmationResult(pending *storagemodel.Pending
|
||||
}
|
||||
sourceService := strings.TrimSpace(pending.SourceService)
|
||||
if sourceService == "" {
|
||||
sourceService = string(mservice.PaymentGateway)
|
||||
sourceService = mservice.PaymentGateway
|
||||
}
|
||||
rail := strings.TrimSpace(pending.Rail)
|
||||
if rail == "" {
|
||||
rail = s.rail
|
||||
}
|
||||
env := confirmations.ConfirmationResult(string(mservice.PaymentGateway), result, sourceService, rail)
|
||||
env := confirmations.ConfirmationResult(mservice.PaymentGateway, result, sourceService, rail)
|
||||
if err := s.producer.SendMessage(env); err != nil {
|
||||
s.logger.Warn("Failed to publish confirmation result", zap.Error(err),
|
||||
zap.String("request_id", strings.TrimSpace(result.RequestID)),
|
||||
@@ -338,7 +338,7 @@ func (s *Service) sendTelegramText(_ context.Context, request *model.TelegramTex
|
||||
if request.ChatID == "" || request.Text == "" {
|
||||
return merrors.InvalidArgument("telegram chat_id and text are required", "chat_id", "text")
|
||||
}
|
||||
env := tnotifications.TelegramText(string(mservice.PaymentGateway), request)
|
||||
env := tnotifications.TelegramText(mservice.PaymentGateway, request)
|
||||
if err := s.producer.SendMessage(env); err != nil {
|
||||
s.logger.Warn("Failed to publish telegram text request", zap.Error(err),
|
||||
zap.String("request_id", request.RequestID),
|
||||
|
||||
@@ -228,9 +228,7 @@ func amountModuloSlot(amount *paymenttypes.Money) (int, bool) {
|
||||
return 0, false
|
||||
}
|
||||
sign := 1
|
||||
if strings.HasPrefix(raw, "+") {
|
||||
raw = strings.TrimPrefix(raw, "+")
|
||||
}
|
||||
raw = strings.TrimPrefix(raw, "+")
|
||||
if strings.HasPrefix(raw, "-") {
|
||||
sign = -1
|
||||
raw = strings.TrimPrefix(raw, "-")
|
||||
@@ -294,7 +292,7 @@ func hashModulo(input string, mod int) int {
|
||||
}
|
||||
h := fnv.New32a()
|
||||
_, _ = h.Write([]byte(strings.TrimSpace(input)))
|
||||
return int(h.Sum32() % uint32(mod))
|
||||
return int(h.Sum32()) % mod
|
||||
}
|
||||
|
||||
func (s settlementScenario) delayedTransitionEnabled() bool {
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
tnotifications "github.com/tech/sendico/pkg/messaging/notifications/telegram"
|
||||
"github.com/tech/sendico/pkg/mlogger"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
pmodel "github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
paymenttypes "github.com/tech/sendico/pkg/payments/types"
|
||||
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
|
||||
@@ -63,7 +62,7 @@ type Config struct {
|
||||
AcceptedUserIDs []string
|
||||
SuccessReaction string
|
||||
InvokeURI string
|
||||
MessagingSettings pmodel.SettingsT
|
||||
MessagingSettings model.SettingsT
|
||||
DiscoveryRegistry *discovery.Registry
|
||||
Treasury TreasuryConfig
|
||||
}
|
||||
@@ -90,7 +89,7 @@ type Service struct {
|
||||
producer msg.Producer
|
||||
broker mb.Broker
|
||||
cfg Config
|
||||
msgCfg pmodel.SettingsT
|
||||
msgCfg model.SettingsT
|
||||
rail string
|
||||
chatID string
|
||||
announcer *discovery.Announcer
|
||||
@@ -249,9 +248,9 @@ func (s *Service) startConsumers() {
|
||||
}
|
||||
return
|
||||
}
|
||||
resultProcessor := confirmations.NewConfirmationResultProcessor(s.logger, string(mservice.PaymentGateway), s.rail, s.onConfirmationResult)
|
||||
resultProcessor := confirmations.NewConfirmationResultProcessor(s.logger, mservice.PaymentGateway, s.rail, s.onConfirmationResult)
|
||||
s.consumeProcessor(resultProcessor)
|
||||
dispatchProcessor := confirmations.NewConfirmationDispatchProcessor(s.logger, string(mservice.PaymentGateway), s.rail, s.onConfirmationDispatch)
|
||||
dispatchProcessor := confirmations.NewConfirmationDispatchProcessor(s.logger, mservice.PaymentGateway, s.rail, s.onConfirmationDispatch)
|
||||
s.consumeProcessor(dispatchProcessor)
|
||||
updateProcessor := tnotifications.NewTelegramUpdateProcessor(s.logger, s.onTelegramUpdate)
|
||||
s.consumeProcessor(updateProcessor)
|
||||
@@ -573,7 +572,7 @@ func (s *Service) buildConfirmationRequest(intent *model.PaymentGatewayIntent) (
|
||||
QuoteRef: intent.QuoteRef,
|
||||
AcceptedUserIDs: s.cfg.AcceptedUserIDs,
|
||||
TimeoutSeconds: timeout,
|
||||
SourceService: string(mservice.PaymentGateway),
|
||||
SourceService: mservice.PaymentGateway,
|
||||
Rail: rail,
|
||||
OperationRef: intent.OperationRef,
|
||||
IntentRef: intent.IntentRef,
|
||||
@@ -590,7 +589,7 @@ func (s *Service) sendConfirmationRequest(request *model.ConfirmationRequest) er
|
||||
s.logger.Warn("Messaging producer not configured")
|
||||
return merrors.Internal("messaging producer is not configured")
|
||||
}
|
||||
env := confirmations.ConfirmationRequest(string(mservice.PaymentGateway), request)
|
||||
env := confirmations.ConfirmationRequest(mservice.PaymentGateway, request)
|
||||
if err := s.producer.SendMessage(env); err != nil {
|
||||
s.logger.Warn("Failed to publish confirmation request",
|
||||
zap.Error(err),
|
||||
@@ -626,7 +625,7 @@ func (s *Service) publishTelegramReaction(result *model.ConfirmationResult) {
|
||||
if request.ChatID == "" || request.MessageID == "" || request.Emoji == "" {
|
||||
return
|
||||
}
|
||||
env := tnotifications.TelegramReaction(string(mservice.PaymentGateway), request)
|
||||
env := tnotifications.TelegramReaction(mservice.PaymentGateway, request)
|
||||
if err := s.producer.SendMessage(env); err != nil {
|
||||
s.logger.Warn("Failed to publish telegram reaction",
|
||||
zap.Error(err),
|
||||
@@ -805,7 +804,7 @@ func (s *Service) startAnnouncer() {
|
||||
Operations: caps,
|
||||
InvokeURI: s.invokeURI,
|
||||
}
|
||||
s.announcer = discovery.NewAnnouncer(s.logger, s.producer, string(mservice.PaymentGateway), announce)
|
||||
s.announcer = discovery.NewAnnouncer(s.logger, s.producer, mservice.PaymentGateway, announce)
|
||||
s.announcer.Start()
|
||||
s.logger.Info("Discovery announcer started",
|
||||
zap.String("service", mservice.ChSettle),
|
||||
@@ -910,14 +909,10 @@ func intentFromSubmitTransfer(req *chainv1.SubmitTransferRequest, defaultRail, d
|
||||
return nil, merrors.InvalidArgument("submit_transfer: operation_ref is required")
|
||||
}
|
||||
quoteRef := strings.TrimSpace(metadata[metadataQuoteRef])
|
||||
targetChatID := strings.TrimSpace(metadata[metadataTargetChatID])
|
||||
outgoingLeg := normalizeRail(metadata[metadataOutgoingLeg])
|
||||
if outgoingLeg == "" {
|
||||
outgoingLeg = normalizeRail(defaultRail)
|
||||
}
|
||||
if targetChatID == "" {
|
||||
targetChatID = strings.TrimSpace(defaultChatID)
|
||||
}
|
||||
return &model.PaymentGatewayIntent{
|
||||
PaymentRef: paymentRef,
|
||||
PaymentIntentID: paymentIntentID,
|
||||
|
||||
@@ -32,7 +32,7 @@ func (f *fakePaymentsStore) FindByIdempotencyKey(_ context.Context, key string)
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
if f.records == nil {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // fake store: no records means no payment by idempotency key
|
||||
}
|
||||
return f.records[key], nil
|
||||
}
|
||||
@@ -41,14 +41,14 @@ func (f *fakePaymentsStore) FindByOperationRef(_ context.Context, key string) (*
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
if f.records == nil {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // fake store: no records means no payment by operation ref
|
||||
}
|
||||
for _, record := range f.records {
|
||||
if record != nil && record.OperationRef == key {
|
||||
return record, nil
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // fake store: operation ref not found
|
||||
}
|
||||
|
||||
func (f *fakePaymentsStore) Upsert(_ context.Context, record *storagemodel.PaymentRecord) error {
|
||||
@@ -124,7 +124,7 @@ func (f *fakePendingStore) FindByRequestID(_ context.Context, requestID string)
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
if f.records == nil {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // fake store: no pending confirmations configured
|
||||
}
|
||||
return f.records[requestID], nil
|
||||
}
|
||||
@@ -137,7 +137,7 @@ func (f *fakePendingStore) FindByMessageID(_ context.Context, messageID string)
|
||||
return record, nil
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // fake store: message id not found
|
||||
}
|
||||
|
||||
func (f *fakePendingStore) MarkClarified(_ context.Context, requestID string) error {
|
||||
@@ -197,7 +197,7 @@ func (f *fakeBroker) Publish(_ envelope.Envelope) error {
|
||||
}
|
||||
|
||||
func (f *fakeBroker) Subscribe(event model.NotificationEvent) (<-chan envelope.Envelope, error) {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // fake broker does not emit events in unit tests
|
||||
}
|
||||
|
||||
func (f *fakeBroker) Unsubscribe(event model.NotificationEvent, subChan <-chan envelope.Envelope) error {
|
||||
@@ -237,7 +237,7 @@ func newTestService(_ *testing.T) (*Service, *fakeRepo, *captureProducer) {
|
||||
pending: &fakePendingStore{},
|
||||
}
|
||||
|
||||
sigEnv := tnotifications.TelegramReaction(string(mservice.PaymentGateway), &model.TelegramReactionRequest{
|
||||
sigEnv := tnotifications.TelegramReaction(mservice.PaymentGateway, &model.TelegramReactionRequest{
|
||||
RequestID: "x",
|
||||
ChatID: "1",
|
||||
MessageID: "2",
|
||||
|
||||
@@ -64,7 +64,7 @@ func (s *Service) updateTransferStatus(ctx context.Context, record *model.Paymen
|
||||
return nil, emitErr
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
return struct{}{}, nil
|
||||
})
|
||||
if err != nil {
|
||||
s.logger.Warn("Failed to update transfer status", zap.String("payment_ref", record.PaymentIntentID), zap.String("status", string(record.Status)), zap.Error(err))
|
||||
|
||||
@@ -267,7 +267,8 @@ func (r *Router) captureAmount(ctx context.Context, userID, accountID, chatID st
|
||||
})
|
||||
return
|
||||
}
|
||||
if typed, ok := err.(limitError); ok {
|
||||
var typed limitError
|
||||
if errors.As(err, &typed) {
|
||||
switch typed.LimitKind() {
|
||||
case "per_operation":
|
||||
_ = r.sendText(ctx, chatID, "*Amount exceeds allowed limit*\n\n*Max per operation:* "+markdownCode(typed.LimitMax())+"\n\nEnter another amount or "+markdownCommand(CommandCancel)+".")
|
||||
|
||||
@@ -22,7 +22,7 @@ func (f fakeUserBindingResolver) ResolveUserBinding(_ context.Context, telegramU
|
||||
return nil, f.err
|
||||
}
|
||||
if f.bindings == nil {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // test resolver: missing bindings means user is unknown
|
||||
}
|
||||
return f.bindings[telegramUserID], nil
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func (fakeService) MaxPerOperationLimit() string {
|
||||
}
|
||||
|
||||
func (fakeService) GetActiveRequestForAccount(context.Context, string) (*storagemodel.TreasuryRequest, error) {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // test service: no active request by default
|
||||
}
|
||||
|
||||
func (fakeService) GetAccountProfile(_ context.Context, ledgerAccountID string) (*AccountProfile, error) {
|
||||
@@ -48,15 +48,15 @@ func (fakeService) GetAccountProfile(_ context.Context, ledgerAccountID string)
|
||||
}
|
||||
|
||||
func (fakeService) CreateRequest(context.Context, CreateRequestInput) (*storagemodel.TreasuryRequest, error) {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // test service: request creation is not exercised in these tests
|
||||
}
|
||||
|
||||
func (fakeService) ConfirmRequest(context.Context, string, string) (*storagemodel.TreasuryRequest, error) {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // test service: confirmation path is not exercised in these tests
|
||||
}
|
||||
|
||||
func (fakeService) CancelRequest(context.Context, string, string) (*storagemodel.TreasuryRequest, error) {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // test service: cancellation path is not exercised in these tests
|
||||
}
|
||||
|
||||
func TestRouterUnauthorizedInAllowedChatSendsAccessDenied(t *testing.T) {
|
||||
|
||||
@@ -260,7 +260,7 @@ func (c *connectorClient) callContext(ctx context.Context) (context.Context, con
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
return context.WithTimeout(ctx, c.cfg.Timeout)
|
||||
return context.WithTimeout(ctx, c.cfg.Timeout) //nolint:gosec // cancel func is always invoked by call sites
|
||||
}
|
||||
|
||||
func structFromMap(values map[string]any) *structpb.Struct {
|
||||
|
||||
@@ -141,7 +141,7 @@ func (c *discoveryClient) resolveClient(_ context.Context) (Client, error) {
|
||||
c.endpointKey = key
|
||||
if c.logger != nil {
|
||||
c.logger.Info("Discovered ledger endpoint selected",
|
||||
zap.String("service", string(mservice.Ledger)),
|
||||
zap.String("service", mservice.Ledger),
|
||||
zap.String("invoke_uri", endpoint.raw),
|
||||
zap.String("address", endpoint.address),
|
||||
zap.Bool("insecure", endpoint.insecure))
|
||||
@@ -186,10 +186,10 @@ func (c *discoveryClient) resolveEndpoint() (discoveryEndpoint, error) {
|
||||
|
||||
func matchesService(service string, candidate mservice.Type) bool {
|
||||
service = strings.TrimSpace(service)
|
||||
if service == "" || strings.TrimSpace(string(candidate)) == "" {
|
||||
if service == "" || strings.TrimSpace(candidate) == "" {
|
||||
return false
|
||||
}
|
||||
return strings.EqualFold(service, strings.TrimSpace(string(candidate)))
|
||||
return strings.EqualFold(service, strings.TrimSpace(candidate))
|
||||
}
|
||||
|
||||
func parseDiscoveryEndpoint(raw string) (discoveryEndpoint, error) {
|
||||
|
||||
@@ -106,7 +106,7 @@ func (a *botUsersAdapter) ResolveUserBinding(ctx context.Context, telegramUserID
|
||||
return nil, err
|
||||
}
|
||||
if record == nil {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // nil means no treasury user binding configured
|
||||
}
|
||||
return &bot.UserBinding{
|
||||
TelegramUserID: strings.TrimSpace(record.TelegramUserID),
|
||||
@@ -145,7 +145,7 @@ func (a *botServiceAdapter) GetAccountProfile(ctx context.Context, ledgerAccount
|
||||
return nil, err
|
||||
}
|
||||
if profile == nil {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // nil means no account profile is available
|
||||
}
|
||||
return &bot.AccountProfile{
|
||||
AccountID: strings.TrimSpace(profile.AccountID),
|
||||
|
||||
@@ -298,33 +298,33 @@ func (s *Service) ExecuteRequest(ctx context.Context, requestID string) (*Execut
|
||||
return nil, err
|
||||
}
|
||||
if record == nil {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // nil means request does not exist
|
||||
}
|
||||
|
||||
switch record.Status {
|
||||
case storagemodel.TreasuryRequestStatusExecuted,
|
||||
storagemodel.TreasuryRequestStatusCancelled,
|
||||
storagemodel.TreasuryRequestStatusFailed:
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // nil means request is terminal and not executable
|
||||
case storagemodel.TreasuryRequestStatusScheduled:
|
||||
claimed, err := s.repo.ClaimScheduled(ctx, requestID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !claimed {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // nil means scheduled request is not yet claimable
|
||||
}
|
||||
record, err = s.repo.FindByRequestID(ctx, requestID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if record == nil {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // nil means request disappeared after claim
|
||||
}
|
||||
}
|
||||
|
||||
if record.Status != storagemodel.TreasuryRequestStatusConfirmed {
|
||||
return nil, nil
|
||||
return nil, nil //nolint:nilnil // nil means request is not ready for execution
|
||||
}
|
||||
return s.executeClaimed(ctx, record)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user