Two accounts hold the same 30.00 USD. Both try to pay 70.00 USD. One succeeds and ends up negative; the other is refused. The difference is a single flag.
An account created with Account::new permits overdraft without bound. When its
positive postings do not cover a debit, resolve consumes all of them and creates
a negative posting for the remainder, and the transfer records because value
still conserves per asset. An account created with
Account::debit_must_not_exceed_credit carries
AccountFlags::DEBIT_MUST_NOT_EXCEED_CREDIT, cannot hold a negative posting, and
fails selection with InsufficientFunds instead. See
accounts for the rule and
transfers for where in resolve it applies.
Running the program below prints both outcomes:
Both accounts hold 30.00 USD. Both now try to pay 70.00 USD.
treasury permits overdraft (Account::new):
30.00 USD Active
commit succeeded, balance -40.00 USD
the 30.00 posting was consumed and a 40.00 shortfall posting created:
30.00 USD Spent
-40.00 USD Active
wallet forbids it (Account::debit_must_not_exceed_credit):
30.00 USD Active
commit refused: available 30.00 USD, requested 70.00 USD
balance unchanged at 30.00 USD
The shortfall posting is why the balance reads -40.00 without any field being mutated: the account's postings are now +30.00 (spent) and -40.00 (live), and the balance is the sum of the live ones. The merchant's +70.00 posting makes the transfer conserve: 30.00 consumed, 70.00 and -40.00 created.
{{#include ../../crates/kuatia/examples/overdraft.rs}}