From f255ac3e6c6283812287139273cd09345c8f82e0 Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Thu, 8 Jan 2026 02:48:35 +0100 Subject: What a day --- lib/ledger.ml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/ledger.ml b/lib/ledger.ml index 3e1d177..54a030e 100644 --- a/lib/ledger.ml +++ b/lib/ledger.ml @@ -524,6 +524,15 @@ module World = struct let%map pre_bal, post_bal = mres in (pre_bal, post_bal, world') + let get_bal aid (world : t) : (Commodity_id.t * Money.Diff.t) option = + let open Option.Let_syntax in + let%map cb, _world' = + Account_hierarchy.alter aid + (fun _acc_type acc_comm acc_bal -> ((acc_comm, acc_bal), acc_bal)) + world + in + cb + let apply_tx (tx : Tx.t) world : t option = Map.fold_option tx.entries ~init:world ~f:(fun ~key:aid ~(data : Tx.entry) world -> @@ -536,6 +545,11 @@ module World = struct | Some bal_ass -> if Money.Diff.(bal_ass = new_bal) then Some world else None) + let apply_ba (ba : bal_assert) world : t option = + let open Option.Let_syntax in + let%bind _comm, bal = get_bal ba.account world in + if not Money.Diff.(bal = ba.bal) then None else Some world + let apply : item -> t -> t option = function | Tx_item tx -> apply_tx tx | Bal_assert_item ba -> apply_ba ba -- cgit v1.2.3