Skip to content

inneralien/tte

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TTE — Toy Transaction Engine

This is a command line tool that reads a CSV file containing a series of transactions and generates an accounts balance output file also in CSV.

The Goals
  • Update client accounts

  • Handle disputes

  • Handle chargebacks

  • Output the state of clients accounts

Stretch Goal
  • Learn to spell withdrawal (p.s. It’s not withdrawl)

Running

Default run via cargo that creates an accounts.csv file

cargo run -- transactions.csv > accounts.csv

The default log level is Info. The debug level can be changed by setting the RUST_LOG environment variable used by the env_logger crate.

RUST_LOG=debug cargo run -- transactions.csv

Input and Output Data

Input

The input is a CSV formatted file similar to the following example

Example Transactions Input Data
type,       client,     tx,     amount
deposit,         1,     1,         1.0
deposit,         2,     2,         2.0
deposit,         1,     3,         2.0
withdrawal,      1,     4,         1.5
withdrawal,      2,     5,         3.0
ℹ️
ASSUMPTION — There is a header line in the CSV file.
ℹ️
ASSUMPTION — One can dispute a withdrawal which can cause a negative total which would mean that the bank owes the client for funds withdrawn fraudulently.
Transaction Types
  • Deposit

  • Withdrawal

  • Dispute

  • Resolve

  • Chargeback

Output

The output from running the program on a given set of input data is an account balance summary like this.

Example Accounts Output Data
client, available, held, total, locked
     1,       1.5,  0.0,   1.5,  false
     2,       2.0,  0.0,   2.0,  false

The output is also valid CSV, but is written to stdout instead of to a file.

Errors

Most errors are silently handled so they don’t stop the processing of the transaction data. Logging is used to note any errors in the transactions file like referencing tx values that haven’t been seen yet. Logging messages all go to stderr so stdio redirected to a file will not get contaminated.

Things Left to Do

As software is never done, here are some of the things left to do.

  • ❏ Move the Client into a file to make it a module.

  • ❏ Find a more concise way to build unit tests. They are currently a jumble. Figuring out how to parameterize unit tests in Rust is a priority.

  • ❏ Figure out how to use csv Writer instead of writing CSV output manually. It’s really easy to write it manually at the moment, but would likely get problematic as the program grows

  • ❏ Generate or gather more test data input files. I am woefully lacking valid test data. One alternative would be to model the logic in something like Alloy to help find the edge cases that need special care.

  • ❏ Figure out how to handle CSV files both with and without header lines.

  • read_csv works on anything that is impl io::Read, so reading from streams of data wouldn’t be too much extra work.

  • ❏ Converting things to async/await would facilitate multiple concurrent producers of CSV data.

Releases

No releases published

Packages

No packages published

Languages