This commit is contained in:
parent
997a579bc8
commit
a6d2563a59
3 changed files with 13 additions and 19 deletions
|
|
@ -27,14 +27,12 @@ let mk_future_denom denom_key_signf
|
||||||
let open Binary_formats in
|
let open Binary_formats in
|
||||||
let h_denom_pub = h_pub in
|
let h_denom_pub = h_pub in
|
||||||
let h_section_name = Cstring_hash_64.hash section_name in
|
let h_section_name = Cstring_hash_64.hash section_name in
|
||||||
let anchor_time =
|
let anchor_time = TimeAbsoluteNBO.{ v= Util.ptime_to_int64 stamp_start } in
|
||||||
TimeAbsoluteNBO.{ v= Util.ptime_to_int64_us stamp_start }
|
|
||||||
in
|
|
||||||
let duration_withdraw =
|
let duration_withdraw =
|
||||||
let v =
|
let v =
|
||||||
Ptime.diff stamp_start stamp_expire_withdraw
|
Ptime.diff stamp_start stamp_expire_withdraw
|
||||||
|> Util.ptime_of_span_exn
|
|> Util.ptime_of_span_exn
|
||||||
|> Util.ptime_to_int64_us
|
|> Util.ptime_to_int64
|
||||||
in
|
in
|
||||||
TimeRelativeNBO.{ v }
|
TimeRelativeNBO.{ v }
|
||||||
in
|
in
|
||||||
|
|
@ -66,14 +64,12 @@ let mk_future_signkey signkey_signf
|
||||||
let signkey_secmod_sig =
|
let signkey_secmod_sig =
|
||||||
let open Binary_formats in
|
let open Binary_formats in
|
||||||
let exchange_pub = pub in
|
let exchange_pub = pub in
|
||||||
let anchor_time =
|
let anchor_time = TimeAbsoluteNBO.{ v= Util.ptime_to_int64 stamp_start } in
|
||||||
TimeAbsoluteNBO.{ v= Util.ptime_to_int64_us stamp_start }
|
|
||||||
in
|
|
||||||
let duration =
|
let duration =
|
||||||
let v =
|
let v =
|
||||||
Ptime.diff stamp_start stamp_expire
|
Ptime.diff stamp_start stamp_expire
|
||||||
|> Util.ptime_of_span_exn
|
|> Util.ptime_of_span_exn
|
||||||
|> Util.ptime_to_int64_us
|
|> Util.ptime_to_int64
|
||||||
in
|
in
|
||||||
TimeRelativeNBO.{ v }
|
TimeRelativeNBO.{ v }
|
||||||
in
|
in
|
||||||
|
|
|
||||||
13
src/pg.ml
13
src/pg.ml
|
|
@ -4,19 +4,12 @@
|
||||||
module Caqti_type = struct
|
module Caqti_type = struct
|
||||||
include Caqti_type
|
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,
|
(* we want to use int64 timestamps,
|
||||||
not postgresql built-in timestamp type *)
|
not postgresql built-in timestamp type *)
|
||||||
let ptime : Ptime.t Caqti_type.t =
|
let ptime : Ptime.t Caqti_type.t =
|
||||||
Caqti_type.custom ~encode:ptime_to_int64 ~decode:ptime_of_int64
|
let encode i = Ok (Util.ptime_to_int64 i) in
|
||||||
Caqti_type.(int64)
|
let decode = Util.ptime_of_int64 in
|
||||||
|
Caqti_type.custom ~encode ~decode Caqti_type.(int64)
|
||||||
end
|
end
|
||||||
|
|
||||||
let pg_amount : Amount.t Caqti_type.t =
|
let pg_amount : Amount.t Caqti_type.t =
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,12 @@ end
|
||||||
|
|
||||||
(* -- Ptime -- *)
|
(* -- 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 =
|
let ptime_of_span_exn span =
|
||||||
match Ptime.of_span span with
|
match Ptime.of_span span with
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue