runnable.md 2.0 KB

Runnable programs

The programs in crates/kuatia/examples/ need no setup. quickstart runs on the in-memory store, so it needs no feature and no database; the rest open a real SQLite database in memory through Ledger::connect, which the sqlite feature re-exports:

cargo run -p kuatia --example quickstart
cargo run -p kuatia --features sqlite --example create_accounts
cargo run -p kuatia --features sqlite --example fund_and_trade
cargo run -p kuatia --features sqlite --example withdraw
cargo run -p kuatia --features sqlite --example overdraft
cargo run -p kuatia --features sqlite --example inflight_hold
cargo run -p kuatia --features sqlite --example escrow

They are included below from source, so what the book shows is the code cargo test compiles.

Quickstart

Register an asset, open two accounts, fund one and pay the other. This is the same source as the quick example in the top-level README, held there by a test.

{{#include ../../crates/kuatia/examples/quickstart.rs}}

Create accounts

{{#include ../../crates/kuatia/examples/create_accounts.rs}}

Fund and trade

A deposit into two accounts, then a cross-asset trade settled as one transfer: each asset conserves independently, so a swap needs no special verb.

{{#include ../../crates/kuatia/examples/fund_and_trade.rs}}

Withdraw

{{#include ../../crates/kuatia/examples/withdraw.rs}}

Overdraft

A shortfall becomes a negative posting on an account that permits it, and InsufficientFunds on an account that does not. Walked through in overdraft.

{{#include ../../crates/kuatia/examples/overdraft.rs}}

Inflight hold

Authorize, confirm and void through a per-destination holding subaccount; see inflight holds.

{{#include ../../crates/kuatia/examples/inflight_hold.rs}}

Escrow

Explained in Pending states.

{{#include ../../crates/kuatia/examples/escrow.rs}}