wip pg.ml
This commit is contained in:
parent
c48892ca9a
commit
2433ff3932
3 changed files with 56 additions and 9 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
|
||||||
|
|
|
||||||
46
src/pg.ml
Normal file
46
src/pg.ml
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
(* TODO be sure to not use postgres ptime
|
||||||
|
add a dune stanza like for prelude:
|
||||||
|
"(flags (:standard -open Prelude))" *)
|
||||||
|
module Caqti_type = struct
|
||||||
|
include Caqti_type
|
||||||
|
|
||||||
|
(* we want to use int64 timestamps,
|
||||||
|
not postgresql built-in timestamp type *)
|
||||||
|
let ptime : Ptime.t Caqti_type.t =
|
||||||
|
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 =
|
||||||
|
let open Amount in
|
||||||
|
(* TODO bad int32 conversion *)
|
||||||
|
Caqti_type.custom
|
||||||
|
~encode:(fun amount -> Ok (amount.value, Int64.to_int32 amount.fraction))
|
||||||
|
~decode:(fun (value, fraction) ->
|
||||||
|
let fraction = Int64.of_int32 fraction in
|
||||||
|
Ok { sign= None; currency= `Eur; value; fraction })
|
||||||
|
Caqti_type.(t2 int64 int32)
|
||||||
|
|
||||||
|
(* WIP: minimum db functions for basic /management *)
|
||||||
|
|
||||||
|
let pg_todo () = assert false
|
||||||
|
|
||||||
|
(* signkey *)
|
||||||
|
let activate_signing_key = pg_todo
|
||||||
|
let lookup_signing_key = pg_todo
|
||||||
|
let iterate_active_signkeys = pg_todo
|
||||||
|
let insert_signkey_revocation = pg_todo
|
||||||
|
let lookup_signkey_revocation = pg_todo
|
||||||
|
|
||||||
|
(* denominations *)
|
||||||
|
let insert_denomination_info = pg_todo
|
||||||
|
let get_denomination_info = pg_todo
|
||||||
|
let get_denomination_by_serial = pg_todo
|
||||||
|
let iterate_denomination_info = pg_todo
|
||||||
|
let iterate_denominations = pg_todo
|
||||||
|
let get_coin_denomination = pg_todo
|
||||||
|
let insert_denomination_revocation = pg_todo
|
||||||
|
let get_denomination_revocation = pg_todo
|
||||||
|
let lookup_denomination_key = pg_todo
|
||||||
|
let add_denomination_key = pg_todo
|
||||||
|
|
@ -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