diff --git a/src/auditor.ml b/src/auditor.ml deleted file mode 100644 index 7534ac4a..00000000 --- a/src/auditor.ml +++ /dev/null @@ -1,19 +0,0 @@ -type t = { - auditor_pub: Crypto.EddsaPublicKey.t; - auditor_url: string; - auditor_name: string; - last_change: Timestamp.t; - is_active: bool; -} - -let of_setup_message - Api.AuditorSetupMessage. - { auditor_url; auditor_name; auditor_pub; master_sig= _; validity_start } - = - { - auditor_url; - auditor_name; - auditor_pub; - last_change= validity_start; - is_active= true; - } diff --git a/src/env.ml b/src/env.ml deleted file mode 100644 index d93b4e4e..00000000 --- a/src/env.ml +++ /dev/null @@ -1,7 +0,0 @@ -type t = { - sw: Caqti_miou.Switch.t; - stack: Mnet.stack; - tcp: Mnet.TCP.state; - dns: Mnet_dns.t; - fs: Fat.t; -} diff --git a/src/global.ml b/src/global.ml index 16e9d795..ba6bb713 100644 --- a/src/global.ml +++ b/src/global.ml @@ -1,7 +1,15 @@ +type env = { + sw: Caqti_miou.Switch.t; + stack: Mnet.stack; + tcp: Mnet.TCP.state; + dns: Mnet_dns.t; + fs: Fat.t; +} + (* IMPROVE: use caqti pool [connect_pool] with parameter [?post_connect] for preflight *) let db_conn = - let f Env.{ sw; stack; tcp; dns; fs= _ } = + let f { sw; stack; tcp; dns; fs= _ } = Logs.info (fun m -> m "Connecting to database"); let db_uri = Config.Exchangedb_postgres.config in match Caqti_mnet.connect ~sw stack tcp dns db_uri with @@ -17,7 +25,7 @@ let db_conn = Vifu.Device.v ~name:"db_conn" ~finally [] f let keys = - let f (module Conn : Pg.CONN) (env : Env.t) = + let f (module Conn : Pg.CONN) (env : env) = let (module Fs : Fat.FS) = (module struct let t = env.fs diff --git a/src/mte.ml b/src/mte.ml index f2eb2d19..3e2c6c85 100644 --- a/src/mte.ml +++ b/src/mte.ml @@ -95,7 +95,7 @@ let () = Caqti_miou.Switch.run @@ fun sw -> (* -- *) let fs = Fat.create storage in - let env = Env.{ sw; stack; tcp; dns; fs } in + let env = Global.{ sw; stack; tcp; dns; fs } in let devices = Vifu.Devices.[ Global.db_conn; Global.keys ] in let cfg = Vifu.Config.v Config.Exchange.port in Logs.info (fun m -> m "Starting MTE server"); diff --git a/src/mte_management.ml b/src/mte_management.ml index 4583db6f..d5fd44e2 100644 --- a/src/mte_management.ml +++ b/src/mte_management.ml @@ -117,7 +117,7 @@ module Auditors = struct let* opt = Pg.find_auditor db_conn auditor_pub |> unwrap_caqti in match opt with | None -> - let auditor = Auditor.of_setup_message v in + let auditor = Pg_type.Auditor.of_setup_message v in let+ () = Pg.update_auditor db_conn auditor |> unwrap_caqti in Logs.info (fun m -> m "enabled auditor"); () diff --git a/src/pg_type.ml b/src/pg_type.ml index 032a64a2..f58157cc 100644 --- a/src/pg_type.ml +++ b/src/pg_type.ml @@ -351,13 +351,41 @@ let exchange_partner_setup = }) Caqti_type.(t7 eddsa_pub time time time_span amount master_sig string) -let auditor = - let open Auditor in - Caqti_type.custom - ~encode:(fun - { auditor_pub; auditor_url; auditor_name; last_change; is_active } -> - Ok (auditor_pub, auditor_url, auditor_name, last_change, is_active)) - ~decode:(fun - (auditor_pub, auditor_url, auditor_name, last_change, is_active) -> - Ok { auditor_pub; auditor_url; auditor_name; last_change; is_active }) - Caqti_type.(t5 eddsa_pub string string time bool) +module Auditor = struct + type t = { + auditor_pub: Crypto.EddsaPublicKey.t; + auditor_url: string; + auditor_name: string; + last_change: Timestamp.t; + is_active: bool; + } + + let of_setup_message + Api.AuditorSetupMessage. + { + auditor_url; + auditor_name; + auditor_pub; + master_sig= _; + validity_start; + } = + { + auditor_url; + auditor_name; + auditor_pub; + last_change= validity_start; + is_active= true; + } + + let caqti = + Caqti_type.custom + ~encode:(fun + { auditor_pub; auditor_url; auditor_name; last_change; is_active } -> + Ok (auditor_pub, auditor_url, auditor_name, last_change, is_active)) + ~decode:(fun + (auditor_pub, auditor_url, auditor_name, last_change, is_active) -> + Ok { auditor_pub; auditor_url; auditor_name; last_change; is_active }) + Caqti_type.(t5 eddsa_pub string string time bool) +end + +let auditor = Auditor.caqti