diff options
| author | Rutger Broekhoff | 2026-01-08 02:48:35 +0100 |
|---|---|---|
| committer | Rutger Broekhoff | 2026-01-08 02:48:35 +0100 |
| commit | f255ac3e6c6283812287139273cd09345c8f82e0 (patch) | |
| tree | f4cb6c26f9aa90845404918b1000b9593e47177a | |
| parent | 40ed2624e13bc519bebe4332a217fd539b76e5f4 (diff) | |
| download | rdcapsis-f255ac3e6c6283812287139273cd09345c8f82e0.tar.gz rdcapsis-f255ac3e6c6283812287139273cd09345c8f82e0.zip | |
What a day
| -rw-r--r-- | lib/ledger.ml | 14 |
1 files changed, 14 insertions, 0 deletions
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 | |||
| 524 | let%map pre_bal, post_bal = mres in | 524 | let%map pre_bal, post_bal = mres in |
| 525 | (pre_bal, post_bal, world') | 525 | (pre_bal, post_bal, world') |
| 526 | 526 | ||
| 527 | let get_bal aid (world : t) : (Commodity_id.t * Money.Diff.t) option = | ||
| 528 | let open Option.Let_syntax in | ||
| 529 | let%map cb, _world' = | ||
| 530 | Account_hierarchy.alter aid | ||
| 531 | (fun _acc_type acc_comm acc_bal -> ((acc_comm, acc_bal), acc_bal)) | ||
| 532 | world | ||
| 533 | in | ||
| 534 | cb | ||
| 535 | |||
| 527 | let apply_tx (tx : Tx.t) world : t option = | 536 | let apply_tx (tx : Tx.t) world : t option = |
| 528 | Map.fold_option tx.entries ~init:world | 537 | Map.fold_option tx.entries ~init:world |
| 529 | ~f:(fun ~key:aid ~(data : Tx.entry) world -> | 538 | ~f:(fun ~key:aid ~(data : Tx.entry) world -> |
| @@ -536,6 +545,11 @@ module World = struct | |||
| 536 | | Some bal_ass -> | 545 | | Some bal_ass -> |
| 537 | if Money.Diff.(bal_ass = new_bal) then Some world else None) | 546 | if Money.Diff.(bal_ass = new_bal) then Some world else None) |
| 538 | 547 | ||
| 548 | let apply_ba (ba : bal_assert) world : t option = | ||
| 549 | let open Option.Let_syntax in | ||
| 550 | let%bind _comm, bal = get_bal ba.account world in | ||
| 551 | if not Money.Diff.(bal = ba.bal) then None else Some world | ||
| 552 | |||
| 539 | let apply : item -> t -> t option = function | 553 | let apply : item -> t -> t option = function |
| 540 | | Tx_item tx -> apply_tx tx | 554 | | Tx_item tx -> apply_tx tx |
| 541 | | Bal_assert_item ba -> apply_ba ba | 555 | | Bal_assert_item ba -> apply_ba ba |