FF-7 Add old cashflows decoding (#28)

This commit is contained in:
Andrey Fadeev 2018-10-31 14:33:24 +03:00 committed by GitHub
parent f1e3355dca
commit 57fc3b7f30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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.
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.