$ # errors are printed to stderr
$ cargo run -- transactions.csv > accounts.csv
$ cargo test
-
Disputes are only made against deposits. It's not clear to me how disputes with withdrawal are to be handled (can held amount be negative?). So, instead I decided to ignore (and report error) for disputes against withdrawals.
-
Transaction amounts are non negative.
-
A disputes can cause available amount to become negative.
-
It's not specified if a locked account can receive deposits and withdrawals. The only thing that is specified is that a chargeback causes and account be marked as locked.
-
A chargeback doesn't change the available amount.
-
The code is divided into the following modules:
csv
: read from and write to CSVs, types for CSV records.ledger
: maintain balances and disputes.model
: data types to define the business models.lib
: wrap everything else and define functions to drive the engine.main
: drive the engine vialib
.
-
Deposits and disputes are stored separately from balances, in memory. This makes it trivial to retrieve all the balances and print them.
-
The
Balance
for aClient
is only created on first deposit. It suffices because none of the other transactions would have an effect on theBalance
of aClient
with no deposits. -
Amounts are represented by
rust_decimal::Decimal
.
-
Implement a custom deserializer for Amount, to reject negative amounts from the input CSV.
-
Generate a large sample CSV to test against.
-
Look into writing property based tests with QuickCheck
-
If locked accounts are to not accept deposits and withdrawals, handle that in
ledger
. -
Use something like
failure
,anyhow
and such to handle errors instead of overloadingstd::io::Error
everywhere. -
Unit test the error cases in
ledger
.