This commit is contained in:
swrup 2025-11-16 14:21:05 +01:00
parent 997a579bc8
commit a6d2563a59
3 changed files with 13 additions and 19 deletions

View file

@ -27,14 +27,12 @@ let mk_future_denom denom_key_signf
let open Binary_formats in
let h_denom_pub = h_pub in
let h_section_name = Cstring_hash_64.hash section_name in
let anchor_time =
TimeAbsoluteNBO.{ v= Util.ptime_to_int64_us stamp_start }
in
let anchor_time = TimeAbsoluteNBO.{ v= Util.ptime_to_int64 stamp_start } in
let duration_withdraw =
let v =
Ptime.diff stamp_start stamp_expire_withdraw
|> Util.ptime_of_span_exn
|> Util.ptime_to_int64_us
|> Util.ptime_to_int64
in
TimeRelativeNBO.{ v }
in
@ -66,14 +64,12 @@ let mk_future_signkey signkey_signf
let signkey_secmod_sig =
let open Binary_formats in
let exchange_pub = pub in
let anchor_time =
TimeAbsoluteNBO.{ v= Util.ptime_to_int64_us stamp_start }
in
let anchor_time = TimeAbsoluteNBO.{ v= Util.ptime_to_int64 stamp_start } in
let duration =
let v =
Ptime.diff stamp_start stamp_expire
|> Util.ptime_of_span_exn
|> Util.ptime_to_int64_us
|> Util.ptime_to_int64
in
TimeRelativeNBO.{ v }
in

View file

@ -4,19 +4,12 @@
module Caqti_type = struct
include Caqti_type
let ptime_to_int64 ptime =
ptime |> Ptime.to_float_s |> Int64.of_float |> Result.ok
let ptime_of_int64 i =
match Ptime.of_float_s (Int64.to_float i) with
| None -> Fmt.error "ptime_of_int64 error: `%Ld` is not a valid ptime" i
| Some ts -> Ok ts
(* we want to use int64 timestamps,
not postgresql built-in timestamp type *)
let ptime : Ptime.t Caqti_type.t =
Caqti_type.custom ~encode:ptime_to_int64 ~decode:ptime_of_int64
Caqti_type.(int64)
let encode i = Ok (Util.ptime_to_int64 i) in
let decode = Util.ptime_of_int64 in
Caqti_type.custom ~encode ~decode Caqti_type.(int64)
end
let pg_amount : Amount.t Caqti_type.t =

View file

@ -9,7 +9,12 @@ end
(* -- Ptime -- *)
let ptime_to_int64_us p = Int64.of_float (1_000_000. *. Ptime.to_float_s p)
let ptime_to_int64 ptime = ptime |> Ptime.to_float_s |> Int64.of_float
let ptime_of_int64 i =
match Ptime.of_float_s (Int64.to_float i) with
| None -> Fmt.error "ptime_of_int64 error: `%Ld` is not a valid ptime" i
| Some ts -> Ok ts
let ptime_of_span_exn span =
match Ptime.of_span span with