From 9b1ea5b5e47b4d1fa66d42bed3ef436fdcdf710e Mon Sep 17 00:00:00 2001 From: Dave Date: Tue, 21 Apr 2026 11:34:02 +0500 Subject: [PATCH] feat: add DisableIndicatorAutoCreate flag to prevent implicit balance creation Adds config option (env: BLNK_TRANSACTION_DISABLE_INDICATOR_AUTO_CREATE) that blocks automatic balance creation when an @indicator is not found. --- balance.go | 4 ++++ config/config.go | 1 + 2 files changed, 5 insertions(+) diff --git a/balance.go b/balance.go index 69b19d2..efa3f9a 100644 --- a/balance.go +++ b/balance.go @@ -146,6 +146,10 @@ func (l *Blnk) getOrCreateBalanceByIndicator(ctx context.Context, indicator, cur balance, err := l.datasource.GetBalanceByIndicator(indicator, currency) if err != nil { + if cfg.Transaction.DisableIndicatorAutoCreate { + span.RecordError(err) + return nil, fmt.Errorf("balance with indicator '%s' not found and auto-creation is disabled", indicator) + } span.AddEvent("Creating new balance") balance = &model.Balance{ Indicator: indicator, diff --git a/config/config.go b/config/config.go index 6edaa26..e882269 100644 --- a/config/config.go +++ b/config/config.go @@ -162,6 +162,7 @@ type TransactionConfig struct { EnableCoalescing bool `json:"enable_coalescing" envconfig:"BLNK_TRANSACTION_ENABLE_COALESCING"` EnableQueuedChecks bool `json:"enable_queued_checks" envconfig:"BLNK_TRANSACTION_ENABLE_QUEUED_CHECKS"` DisableBatchReferenceCheck bool `json:"disable_batch_reference_check" envconfig:"BLNK_TRANSACTION_DISABLE_BATCH_REFERENCE_CHECK"` + DisableIndicatorAutoCreate bool `json:"disable_indicator_auto_create" envconfig:"BLNK_TRANSACTION_DISABLE_INDICATOR_AUTO_CREATE"` } type ReconciliationConfig struct {