Skip to content

k-brk/transactions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

About

Simple application for managing transactions.

Usage

cargo run -- xyz.csv

Output of command will be returned to stdout.

Implementation

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

    Engine is an entrypoint for each transaction.

    It has a transaction processor which converts incoming transaction into AccountDelta which 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.rs

    Transaction 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, AccountDelta has several methods that are tailored for transactions types.

  • core/account.rs

    Has a definition of AccountDelta, its helpers and user account Account.

    Account model represents user account, AccountDelta are changes which are applied to Account to reflect transaction.

  • core/transaction.rs

    Has a definition of Transaction, and its kinds. File content is deserialized into this structure.

  • core/*_store.rs

    Simple memory storages for accounts and transactions

Additional assumptions

  • Dispute of deposit causes debt when user has lower available amount than transaction amount
  • Dispute of dispute/resolved/chargeback transaction is not possible

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages