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 other programs 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

The book includes them below from source, so it shows the code that cargo test compiles.

Quickstart

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

{{#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 that settles as one transfer. Each asset conserves on its own, 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 one. On an account that does not permit one it becomes InsufficientFunds. The overdraft chapter describes both.

{{#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

The Pending states chapter explains this one.

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