From 667e480d62cb1d7199306f3dffd4d7bb4d0c1c14 Mon Sep 17 00:00:00 2001 From: crosleyzack Date: Tue, 25 Feb 2025 12:41:56 -0500 Subject: [PATCH] fix(ledger) tx reversion handles empty middle accounts --- internal/controller/ledger/controller_default.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/controller/ledger/controller_default.go b/internal/controller/ledger/controller_default.go index de2ce183c..60902d9dd 100644 --- a/internal/controller/ledger/controller_default.go +++ b/internal/controller/ledger/controller_default.go @@ -406,6 +406,13 @@ func (ctrl *DefaultController) revertTransaction(ctx context.Context, store Stor balances[posting.Source][posting.Asset], big.NewInt(0).Neg(posting.Amount), ) + if _, ok := balances[posting.Destination]; ok { + // if destination is also a source in some posting, since balances should only contain posting sources + balances[posting.Destination][posting.Asset] = balances[posting.Destination][posting.Asset].Add( + balances[posting.Destination][posting.Asset], + posting.Amount, + ) + } } for account, forAccount := range balances {