add time.ml, similar to libgnunetutil's

This commit is contained in:
swrup 2026-02-05 15:31:49 +01:00
parent 5eba5f2265
commit cec0e6afa9
17 changed files with 336 additions and 321 deletions

View file

@ -89,9 +89,7 @@ let mk_keys ~db_conn (module Sm : Secmod.S) ~last_issue_date =
let kyc_enabled = false in
let disable_direct_deposit = (* todo *) false in
let master_public_key = Config.master_public_key in
let reserve_closing_delay =
Some Config.Exchangedb.idle_reserve_expiration_time
in
let reserve_closing_delay = Config.Exchangedb.idle_reserve_expiration_time in
(* todo *)
let wallet_balance_limit_without_kyc = None in
let hard_limits = [] in
@ -108,16 +106,12 @@ let mk_keys ~db_conn (module Sm : Secmod.S) ~last_issue_date =
denom_data_l
in
let list_issue_date =
match denom_data_l with [] -> None | v :: _ -> v.Denom_data.stamp_start
match denom_data_l with
| [] -> Time.Timestamp.never
| v :: _ -> v.Denom_data.stamp_start
in
let denominations =
let open Denom_data in
(* TODO time
truncated timestamps to int for comparison *)
let timestamp_to_int = function
| None -> 0
| Some ptime -> ptime |> Ptime.to_float_s |> Int.of_float
in
(* if `?last_issue_date` query param does not exactly match the `stamp_start`
of one of the denomination keys, all keys are returned *)
let l =
@ -126,13 +120,15 @@ let mk_keys ~db_conn (module Sm : Secmod.S) ~last_issue_date =
| Some last_issue_date -> (
match
List.find_opt
(fun v -> timestamp_to_int v.stamp_start = last_issue_date)
(fun v ->
Time.Timestamp.compare v.stamp_start last_issue_date = 0)
denom_data_l
with
| None -> denom_data_l
| Some _ ->
List.filter
(fun v -> timestamp_to_int v.stamp_start >= last_issue_date)
(fun v ->
Time.Timestamp.compare v.stamp_start last_issue_date >= 0)
denom_data_l)
in
List.map denomgroup_of_denomdata l
@ -141,7 +137,9 @@ let mk_keys ~db_conn (module Sm : Secmod.S) ~last_issue_date =
let signkeys =
(* TODO sm-db
use database signkey data / verify secmod and database are in sync *)
(*let+ signkey_data_l = Pg.get_active_signkeys db_conn |> unwrap_err_caqti in*)
(*
let now = Ptime_clock.now () |> Option.some in
let+ signkey_data_l = Pg.get_active_signkeys db_conn ~now |> unwrap_err_caqti in*)
let signkey_data_l = Sm.get_signkeys_data () in
let signkey_data_l =
List.sort
@ -192,7 +190,7 @@ let mk_keys ~db_conn (module Sm : Secmod.S) ~last_issue_date =
let recoup = (* TODO /recoup *) [] in
let* global_fees =
Pg.get_global_fees db_conn ~start_date:Timestamp.epoch |> unwrap_err_caqti
Pg.get_global_fees db_conn ~start_date:Timestamp.zero |> unwrap_err_caqti
in
let* auditors =
(* TODO /auditors/$AUDITOR_PUB/$H_DENOM_PUB *)
@ -246,19 +244,17 @@ let f req server _env =
Logs.info (fun m -> m "GET /keys/");
let db_conn = Vif.Server.device Devices.db_connection server in
let sm = Vif.Server.device Devices.secmod server in
let last_issue_date =
match Vif.Queries.get req "last_issue_date" with
| [] -> None
| v :: _ -> (
(* TODO time *)
match float_of_string_opt v with
| None ->
Fmt.failwith
"invalid `?last_issue_date` query param, float_of_string failure"
| Some v -> Some (Int.of_float v))
in
let res =
(*let last_issue_date = Ptime_clock.now () |> Option.some in*)
let* last_issue_date =
match Vif.Queries.get req "last_issue_date" with
| [] -> Ok None
| v :: _ -> (
match int_of_string_opt v with
| None ->
Error
"invalid `?last_issue_date` query param, int_of_string failure"
| Some n -> Ok (Some (Time.Timestamp.of_s (Int64.of_int n))))
in
let* v = mk_keys ~db_conn sm ~last_issue_date in
let s = Api.encode_exn jsont v in
Ok s