summaryrefslogtreecommitdiffstats
path: root/lib/ledger.ml
diff options
context:
space:
mode:
authorRutger Broekhoff2025-08-25 23:39:51 +0200
committerRutger Broekhoff2025-08-25 23:39:51 +0200
commitb8fbaa53b912347b3b50cac3e913a142db460b0a (patch)
tree4563ebc8b04a4ad841ad2103d8ddc0698e844a45 /lib/ledger.ml
parent3f5221c2da2a19cf5de05284821e9b854d31b7fb (diff)
downloadrdcapsis-b8fbaa53b912347b3b50cac3e913a142db460b0a.tar.gz
rdcapsis-b8fbaa53b912347b3b50cac3e913a142db460b0a.zip
Conversion
Diffstat (limited to 'lib/ledger.ml')
-rw-r--r--lib/ledger.ml32
1 files changed, 18 insertions, 14 deletions
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 =
16 16
17type iban_tag = Account_tag | Counterparty_iban_tag [@@deriving compare] 17type iban_tag = Account_tag | Counterparty_iban_tag [@@deriving compare]
18 18
19type unit_tag = Filed_tag | GooglePay_tag | AutoRoundSavings_tag 19type unit_tag = Filed_tag | Google_pay_tag | Auto_round_savings_tag
20[@@deriving compare] 20[@@deriving compare]
21 21
22type string_tag = 22type string_tag =
@@ -81,22 +81,26 @@ end = struct
81end 81end
82 82
83type scalar = Amount of Money.t | Rate of Z.t [@@deriving equal, compare] 83type scalar = Amount of Money.t | Rate of Z.t [@@deriving equal, compare]
84type account_id = string list
85type commodity_id = string (* TODO: consider making this UUID *) 84type commodity_id = string (* TODO: consider making this UUID *)
86 85
86module Account_id = struct
87 type t = string list [@@deriving sexp, compare]
88end
89
87type account = { 90type account = {
88 id : account_id; 91 id : Account_id.t;
89 description : string list; 92 description : string list;
90 commodity_id : commodity_id; 93 commodity_id : commodity_id;
91 balance : Money.t; 94 balance : Money.t;
92} 95}
93 96
94type bal_assert = { account : account_id; amount : Money.t; labels : Labels.t } 97type bal_assert = {
98 account : Account_id.t;
99 amount : Money.t;
100 labels : Labels.t;
101}
95 102
96module Account_id_key = struct 103module Account_id_map = Map.Make (Account_id)
97 type t = account_id
98 type comparator_witness
99end
100 104
101module Tx : sig 105module Tx : sig
102 type t 106 type t
@@ -105,23 +109,23 @@ module Tx : sig
105 val make : 109 val make :
106 cleared:Date.t option -> 110 cleared:Date.t option ->
107 commodity_id:commodity_id -> 111 commodity_id:commodity_id ->
108 debit:scalar Map.M(Account_id_key).t -> 112 debit:scalar Account_id_map.t ->
109 credit:scalar Map.M(Account_id_key).t -> 113 credit:scalar Account_id_map.t ->
110 labels:Labels.t -> 114 labels:Labels.t ->
111 (t, error) result 115 (t, error) result
112 116
113 val cleared : t -> Date.t option 117 val cleared : t -> Date.t option
114 val commodity_id : t -> commodity_id 118 val commodity_id : t -> commodity_id
115 val debit : t -> scalar Map.M(Account_id_key).t 119 val debit : t -> scalar Account_id_map.t
116 val credit : t -> scalar Map.M(Account_id_key).t 120 val credit : t -> scalar Account_id_map.t
117 val labels : t -> Labels.t 121 val labels : t -> Labels.t
118end = struct 122end = struct
119 (* We hide this because we only want to allow constructing balanced transactions *) 123 (* We hide this because we only want to allow constructing balanced transactions *)
120 type t = { 124 type t = {
121 cleared : Date.t option; 125 cleared : Date.t option;
122 commodity_id : commodity_id; 126 commodity_id : commodity_id;
123 debit : scalar Map.M(Account_id_key).t; 127 debit : scalar Account_id_map.t;
124 credit : scalar Map.M(Account_id_key).t; 128 credit : scalar Account_id_map.t;
125 labels : Labels.t; 129 labels : Labels.t;
126 } 130 }
127 [@@deriving fields] 131 [@@deriving fields]