Simple application for managing transactions.
cargo run -- xyz.csv
Output of command will be returned to stdout.
Delta based approach has been choosen, each transaction is converted to structure with changes(increased balance, account locked, etc.) which is later on applied to user account. By doing this way account is decoupled from transactions, rollback can be easily implemented and deltas can be used to recreate user balance upto any given point.
-
core/engine.rsEngine is an entrypoint for each transaction.
It has a transaction processor which converts incoming transaction into
AccountDeltawhich describes how given transaction will affect user account and what changes needs to be applied (balances, locks).Once delta is generated, it is applied to user account to reflect changes from transaction.
Transaction β βββββββββΌββββββββββ β β β Engine β β β βββββββββ¬ββββββββββ β Transaction β βββββββββΌββββββββββ β β β Transaction β β Processor β β β βββββββββ¬ββββββββββ β AccountDelta β βββββββββΌββββββββββ β β β Account β β β βββββββββββββββββββ -
core/transaction_processor.rsTransaction processor based on transaction kind creates structure with changes for user that needs to be applied in order to reflect incoming transaction.
pub struct AccountDelta { pub available: Option<Amount>, pub held: Option<Amount>, pub locked: Option<bool>, pub can_create_debt: Option<bool>, }
Any or all of fileds can be set to be applied later on on user account.
For convenience,
AccountDeltahas several methods that are tailored for transactions types. -
core/account.rsHas a definition of
AccountDelta, its helpers and user accountAccount.Accountmodel represents user account,AccountDeltaare changes which are applied toAccountto reflect transaction. -
core/transaction.rsHas a definition of
Transaction, and its kinds. File content is deserialized into this structure. -
core/*_store.rsSimple memory storages for accounts and transactions
- Dispute of deposit causes debt when user has lower available amount than transaction amount
- Dispute of dispute/resolved/chargeback transaction is not possible