| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- //! Register an asset, open two accounts, fund one from the boundary and pay the
- //! other. Needs no database and no feature, so it is the shortest whole program
- //! the ledger has.
- //!
- //! Run with:
- //! ```sh
- //! cargo run -p kuatia --example quickstart
- //! ```
- use kuatia::prelude::*;
- #[tokio::main]
- async fn main() -> Result<(), Box<dyn std::error::Error>> {
- let ledger = Ledger::new(InMemoryStore::new());
- let usd = ledger.asset("USD", "$", 2).await?;
- let alice = AccountId::new(1);
- let bob = AccountId::new(2);
- let external = AccountId::new(99);
- ledger
- .create_account(Account::debit_must_not_exceed_credit(alice))
- .await?;
- ledger
- .create_account(Account::debit_must_not_exceed_credit(bob))
- .await?;
- ledger.create_account(Account::new(external)).await?;
- ledger
- .commit(
- TransferBuilder::new()
- .deposit(alice, ("100.00", &usd), external)
- .build()?,
- )
- .await?;
- ledger
- .commit(
- TransferBuilder::new()
- .pay(alice, bob, ("25.00", &usd))
- .build()?,
- )
- .await?;
- println!("alice: {}", ledger.balance(&alice, &usd).await?);
- println!("bob: {}", ledger.balance(&bob, &usd).await?);
- Ok(())
- }
|