rm auditor.ml+env.ml

This commit is contained in:
swrup 2026-03-20 00:20:25 +01:00 committed by Swrup
parent 439fdc6a30
commit 6e5b4fc179
6 changed files with 50 additions and 40 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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

View file

@ -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");

View file

@ -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");
()

View file

@ -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