From b8fbaa53b912347b3b50cac3e913a142db460b0a Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Mon, 25 Aug 2025 23:39:51 +0200 Subject: Conversion --- lib/ledger.ml | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'lib/ledger.ml') diff --git a/lib/ledger.ml b/lib/ledger.ml index 1d9a63c..3b52bcc 100644 --- a/lib/ledger.ml +++ b/lib/ledger.ml @@ -16,7 +16,7 @@ type tx_type = type iban_tag = Account_tag | Counterparty_iban_tag [@@deriving compare] -type unit_tag = Filed_tag | GooglePay_tag | AutoRoundSavings_tag +type unit_tag = Filed_tag | Google_pay_tag | Auto_round_savings_tag [@@deriving compare] type string_tag = @@ -81,22 +81,26 @@ end = struct end type scalar = Amount of Money.t | Rate of Z.t [@@deriving equal, compare] -type account_id = string list type commodity_id = string (* TODO: consider making this UUID *) +module Account_id = struct + type t = string list [@@deriving sexp, compare] +end + type account = { - id : account_id; + id : Account_id.t; description : string list; commodity_id : commodity_id; balance : Money.t; } -type bal_assert = { account : account_id; amount : Money.t; labels : Labels.t } +type bal_assert = { + account : Account_id.t; + amount : Money.t; + labels : Labels.t; +} -module Account_id_key = struct - type t = account_id - type comparator_witness -end +module Account_id_map = Map.Make (Account_id) module Tx : sig type t @@ -105,23 +109,23 @@ module Tx : sig val make : cleared:Date.t option -> commodity_id:commodity_id -> - debit:scalar Map.M(Account_id_key).t -> - credit:scalar Map.M(Account_id_key).t -> + debit:scalar Account_id_map.t -> + credit:scalar Account_id_map.t -> labels:Labels.t -> (t, error) result val cleared : t -> Date.t option val commodity_id : t -> commodity_id - val debit : t -> scalar Map.M(Account_id_key).t - val credit : t -> scalar Map.M(Account_id_key).t + val debit : t -> scalar Account_id_map.t + val credit : t -> scalar Account_id_map.t val labels : t -> Labels.t end = struct (* We hide this because we only want to allow constructing balanced transactions *) type t = { cleared : Date.t option; commodity_id : commodity_id; - debit : scalar Map.M(Account_id_key).t; - credit : scalar Map.M(Account_id_key).t; + debit : scalar Account_id_map.t; + credit : scalar Account_id_map.t; labels : Labels.t; } [@@deriving fields] -- cgit v1.2.3