wip int64 timestamp
This commit is contained in:
parent
32fa5b1fc3
commit
12a384a33a
8 changed files with 49 additions and 28 deletions
|
|
@ -128,9 +128,9 @@ module Coin = struct
|
||||||
type t = {
|
type t = {
|
||||||
section_name: string;
|
section_name: string;
|
||||||
value: Amount.t;
|
value: Amount.t;
|
||||||
duration_withdraw: Ptime.Span.t;
|
duration_withdraw: Timestamp.span;
|
||||||
duration_spend: Ptime.Span.t;
|
duration_spend: Timestamp.span;
|
||||||
duration_legal: Ptime.Span.t;
|
duration_legal: Timestamp.span;
|
||||||
fee_withdraw: Amount.t;
|
fee_withdraw: Amount.t;
|
||||||
fee_deposit: Amount.t;
|
fee_deposit: Amount.t;
|
||||||
fee_refresh: Amount.t;
|
fee_refresh: Amount.t;
|
||||||
|
|
|
||||||
|
|
@ -36,16 +36,14 @@ let make
|
||||||
Config.Coin.t) =
|
Config.Coin.t) =
|
||||||
assert (cipher = `RSA);
|
assert (cipher = `RSA);
|
||||||
|
|
||||||
let stamp_start = Ptime_clock.now () |> Option.some in
|
let stamp_start = Timestamp.now () in
|
||||||
let stamp_expire_withdraw =
|
let stamp_expire_withdraw =
|
||||||
Timestamp.add_span_exn stamp_start (Some duration_withdraw)
|
Timestamp.add_span_exn stamp_start duration_withdraw
|
||||||
in
|
in
|
||||||
let stamp_expire_deposit =
|
let stamp_expire_deposit =
|
||||||
Timestamp.add_span_exn stamp_start (Some duration_spend)
|
Timestamp.add_span_exn stamp_start duration_spend
|
||||||
in
|
|
||||||
let stamp_expire_legal =
|
|
||||||
Timestamp.add_span_exn stamp_start (Some duration_legal)
|
|
||||||
in
|
in
|
||||||
|
let stamp_expire_legal = Timestamp.add_span_exn stamp_start duration_legal in
|
||||||
|
|
||||||
let open Mirage_crypto_pk.Rsa in
|
let open Mirage_crypto_pk.Rsa in
|
||||||
let priv = generate ~bits:rsa_keysize () in
|
let priv = generate ~bits:rsa_keysize () in
|
||||||
|
|
|
||||||
|
|
@ -196,15 +196,11 @@ let update_master_signatures ~db_conn ~sm_signkey ~sm_denom
|
||||||
match opt with None -> error | Some v -> Ok v
|
match opt with None -> error | Some v -> Ok v
|
||||||
in
|
in
|
||||||
let check = function false -> error | true -> Ok () in
|
let check = function false -> error | true -> Ok () in
|
||||||
(* TODO time *)
|
let* () =
|
||||||
let timestamp_equal a b =
|
check
|
||||||
let timestamp_to_int64 = function
|
(Timestamp.to_int64 valid_from
|
||||||
| None -> None
|
= Timestamp.to_int64 denom.stamp_start)
|
||||||
| Some v -> v |> Ptime.to_float_s |> Int64.of_float |> Option.some
|
|
||||||
in
|
|
||||||
timestamp_to_int64 a = timestamp_to_int64 b
|
|
||||||
in
|
in
|
||||||
let* () = check (timestamp_equal valid_from denom.stamp_start) in
|
|
||||||
let* () = check (coin = denom.value) in
|
let* () = check (coin = denom.value) in
|
||||||
let* () = check (fee_refund = denom.fee_refund) in
|
let* () = check (fee_refund = denom.fee_refund) in
|
||||||
let* () = check (age_mask = denom.age_mask) in
|
let* () = check (age_mask = denom.age_mask) in
|
||||||
|
|
|
||||||
|
|
@ -173,9 +173,7 @@ module Parse_duration = struct
|
||||||
(fun acc { number; dunit } -> acc + (number * dunit_to_seconds dunit))
|
(fun acc { number; dunit } -> acc + (number * dunit_to_seconds dunit))
|
||||||
0 t
|
0 t
|
||||||
in
|
in
|
||||||
let acc = Int64.of_int acc in
|
Timestamp.span_of_int64 @@ Int64.of_int acc
|
||||||
let ptime = ptime_span_of_int64 acc in
|
|
||||||
ptime
|
|
||||||
|
|
||||||
let parse s : duration_element list =
|
let parse s : duration_element list =
|
||||||
match parse_string ~consume:All duration s with
|
match parse_string ~consume:All duration s with
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,10 @@ module Caqti_type = struct
|
||||||
Amount.make ~sign:None ~currency:Config.currency ~value ~fraction)
|
Amount.make ~sign:None ~currency:Config.currency ~value ~fraction)
|
||||||
(t2 int64 int32)
|
(t2 int64 int32)
|
||||||
|
|
||||||
(* we want to use int64 timestamps,
|
(* ! do not use ptime
|
||||||
|
we want to use int64 timestamps,
|
||||||
not postgresql built-in timestamp type *)
|
not postgresql built-in timestamp type *)
|
||||||
let ptime : Ptime.t option t = Timestamp.caqti
|
let ptime : unit t = Caqti_type.unit
|
||||||
let time = Timestamp.caqti
|
let time = Timestamp.caqti
|
||||||
let age_mask : int t = Caqti_type.int
|
let age_mask : int t = Caqti_type.int
|
||||||
let rsa_public = RsaPublicKey.caqti
|
let rsa_public = RsaPublicKey.caqti
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,9 @@ type t = {
|
||||||
}
|
}
|
||||||
|
|
||||||
let make () =
|
let make () =
|
||||||
let stamp_start = Ptime_clock.now () |> Option.some in
|
let stamp_start = Timestamp.now () in
|
||||||
let stamp_expire =
|
let stamp_expire =
|
||||||
Timestamp.add_span_exn stamp_start
|
Timestamp.add_span_exn stamp_start Config.Exchange.signkey_legal_duration
|
||||||
(Some Config.Exchange.signkey_legal_duration)
|
|
||||||
in
|
in
|
||||||
let stamp_end = stamp_expire in
|
let stamp_end = stamp_expire in
|
||||||
let priv, pub = Mirage_crypto_ec.Ed25519.generate () in
|
let priv, pub = Mirage_crypto_ec.Ed25519.generate () in
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
type t = Ptime.t option
|
type t = Ptime.t option
|
||||||
type span = Ptime.Span.t option
|
type span = Ptime.Span.t option
|
||||||
|
|
||||||
|
let now () = Ptime_clock.now () |> Option.some
|
||||||
|
|
||||||
let diff a b =
|
let diff a b =
|
||||||
match (a, b) with
|
match (a, b) with
|
||||||
| None, _ | _, None -> None
|
| None, _ | _, None -> None
|
||||||
|
|
@ -56,9 +58,31 @@ let ptime_of_int64 i =
|
||||||
| None -> Fmt.failwith "ptime_of_int64 error: `%Ld` is not a valid ptime" i
|
| None -> Fmt.failwith "ptime_of_int64 error: `%Ld` is not a valid ptime" i
|
||||||
| Some ts -> ts
|
| Some ts -> ts
|
||||||
|
|
||||||
|
let ptime_span_to_int64 span = span |> Ptime.Span.to_float_s |> Int64.of_float
|
||||||
|
|
||||||
|
let ptime_span_of_int64 i =
|
||||||
|
match Ptime.Span.of_float_s (Int64.to_float i) with
|
||||||
|
| None ->
|
||||||
|
Fmt.failwith "span_of_int64 error: `%Ld` is not a valid ptime span" i
|
||||||
|
| Some ts -> ts
|
||||||
|
|
||||||
|
(* - *)
|
||||||
|
|
||||||
let encode_int64 = function None -> Int64.max_int | Some p -> ptime_to_int64 p
|
let encode_int64 = function None -> Int64.max_int | Some p -> ptime_to_int64 p
|
||||||
let decode_int64 i = if i = Int64.max_int then None else Some (ptime_of_int64 i)
|
let decode_int64 i = if i = Int64.max_int then None else Some (ptime_of_int64 i)
|
||||||
|
|
||||||
|
let encode_span_int64 = function
|
||||||
|
| None -> Int64.max_int
|
||||||
|
| Some p -> ptime_span_to_int64 p
|
||||||
|
|
||||||
|
let decode_span_int64 i =
|
||||||
|
if i = Int64.max_int then None else Some (ptime_span_of_int64 i)
|
||||||
|
|
||||||
|
let to_int64 = encode_int64
|
||||||
|
let of_int64 = decode_int64
|
||||||
|
let span_to_int64 = encode_span_int64
|
||||||
|
let span_of_int64 = decode_span_int64
|
||||||
|
|
||||||
(* UINT64_MAX represents "never". *)
|
(* UINT64_MAX represents "never". *)
|
||||||
let bin = Bin.map Bin.neint64 decode_int64 encode_int64
|
let bin = Bin.map Bin.neint64 decode_int64 encode_int64
|
||||||
let bin_nbo = Bin.map Bin.beint64 decode_int64 encode_int64
|
let bin_nbo = Bin.map Bin.beint64 decode_int64 encode_int64
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,20 @@
|
||||||
uhuh!
|
uhuh!
|
||||||
need to be int64 for binary/pg round trip *)
|
need to be int64 for binary/pg round trip *)
|
||||||
|
|
||||||
type t = Ptime.t option
|
type t
|
||||||
type span = Ptime.Span.t option
|
type span
|
||||||
|
|
||||||
|
val now : unit -> t
|
||||||
val diff : t -> t -> span
|
val diff : t -> t -> span
|
||||||
val add_span_exn : t -> span -> t
|
val add_span_exn : t -> span -> t
|
||||||
val of_span_exn : span -> t
|
val of_span_exn : span -> t
|
||||||
|
val of_int64 : int64 -> t
|
||||||
|
val to_int64 : t -> int64
|
||||||
|
val span_of_int64 : int64 -> span
|
||||||
|
val span_to_int64 : span -> int64
|
||||||
|
|
||||||
(* - *)
|
(* - *)
|
||||||
val jsont : t Jsont.t
|
val jsont : t Jsont.t
|
||||||
val bin : t Bin.t
|
val bin : t Bin.t
|
||||||
val bin_nbo : t Bin.t
|
val bin_nbo : t Bin.t
|
||||||
val caqti : Ptime.t option Caqti_type.t
|
val caqti : t Caqti_type.t
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue