diff --git a/apps/fistful/src/ff_postings_transfer.erl b/apps/fistful/src/ff_postings_transfer.erl index 7e57333..49c4e8b 100644 --- a/apps/fistful/src/ff_postings_transfer.erl +++ b/apps/fistful/src/ff_postings_transfer.erl @@ -220,8 +220,8 @@ construct_trx_posting(Posting) -> %% Event migrations -spec maybe_migrate(any()) -> event(). % Actual events -maybe_migrate({created, #{final_cash_flow := _CashFlow}} = Ev) -> - Ev; +maybe_migrate({created, #{final_cash_flow := CashFlow} = EvBody}) -> + {created, EvBody#{final_cash_flow => maybe_migrate_cash_flow(CashFlow)}}; % Old events maybe_migrate({created, #{postings := Postings} = Transfer}) -> #{ @@ -238,6 +238,29 @@ maybe_migrate({created, #{postings := Postings} = Transfer}) -> postings => CashFlowPostings } }}); -% Other evnts +% Other events maybe_migrate(Ev) -> - Ev. \ No newline at end of file + Ev. + +maybe_migrate_cash_flow(#{postings := CashFlowPostings} = CashFlow) -> + CashFlow#{postings => lists:map(fun maybe_migrate_posting/1, CashFlowPostings)}. + +% Some cashflow in early withdrawals has been created with binary accounter_account_id +maybe_migrate_posting(#{ + sender := #{accounter_account_id := SenderAcc} = Sender +} = Posting) when is_binary(SenderAcc) -> + maybe_migrate_posting(Posting#{ + sender := Sender#{ + accounter_account_id := erlang:binary_to_integer(SenderAcc) + } + }); +maybe_migrate_posting(#{ + receiver := #{accounter_account_id := ReceiverAcc} = Receiver +} = Posting) when is_binary(ReceiverAcc) -> + maybe_migrate_posting(Posting#{ + receiver := Receiver#{ + accounter_account_id := erlang:binary_to_integer(ReceiverAcc) + } + }); +maybe_migrate_posting(Posting) -> + Posting.