This commit is contained in:
parent
0e46ea162a
commit
a3e3b8fd33
5 changed files with 50 additions and 26 deletions
|
|
@ -5,12 +5,6 @@ open Bin_type
|
|||
(* TODO keep this?
|
||||
some of those are actuall ecdhe, or union of eddsa|ecdhe *)
|
||||
module Aliases = struct
|
||||
module TimestampNBO : Time_S = struct
|
||||
type t = Timestamp.t
|
||||
|
||||
let bin = Timestamp.bin_nbo
|
||||
end
|
||||
|
||||
module AmountNBO = struct
|
||||
type t = Amount.t
|
||||
|
||||
|
|
@ -397,7 +391,7 @@ module GlobalFees = struct
|
|||
})
|
||||
|+ Purpose.field purpose
|
||||
|+ field TimeAbsoluteNBO.bin (fun t -> t.start_date)
|
||||
|+ field TimeRelativeNBO.bin (fun t -> t.end_date)
|
||||
|+ field TimeAbsoluteNBO.bin (fun t -> t.end_date)
|
||||
|+ field TimeRelativeNBO.bin (fun t -> t.purse_timeout)
|
||||
|+ field TimeRelativeNBO.bin (fun t -> t.kyc_timeout)
|
||||
|+ field TimeRelativeNBO.bin (fun t -> t.history_expiration)
|
||||
|
|
|
|||
|
|
@ -58,28 +58,29 @@ module Bytes_64 = struct
|
|||
end
|
||||
|
||||
(* -- Time -- *)
|
||||
module type Time_S = sig
|
||||
type t = Timestamp.t
|
||||
|
||||
val bin : t Bin.t
|
||||
end
|
||||
|
||||
module TIME : Time_S = struct
|
||||
module TimeAbsolute = struct
|
||||
type t = Timestamp.t
|
||||
|
||||
let bin = Timestamp.bin
|
||||
end
|
||||
|
||||
module TIME_NBO : Time_S = struct
|
||||
module TimeAbsoluteNBO = struct
|
||||
type t = Timestamp.t
|
||||
|
||||
let bin = Timestamp.bin_nbo
|
||||
end
|
||||
|
||||
module TimeAbsolute : Time_S = TIME
|
||||
module TimeAbsoluteNBO : Time_S = TIME_NBO
|
||||
module TimeRelative : Time_S = TIME
|
||||
module TimeRelativeNBO : Time_S = TIME_NBO
|
||||
module TimeRelative = struct
|
||||
type t = Timestamp.Span.t
|
||||
|
||||
let bin = Timestamp.Span.bin
|
||||
end
|
||||
|
||||
module TimeRelativeNBO = struct
|
||||
type t = Timestamp.Span.t
|
||||
|
||||
let bin = Timestamp.Span.bin_nbo
|
||||
end
|
||||
|
||||
(* -- Cryptographic primitives -- *)
|
||||
|
||||
|
|
|
|||
|
|
@ -277,15 +277,12 @@ let insert_global_fee =
|
|||
history_fee;
|
||||
account_fee;
|
||||
purse_fee;
|
||||
history_expiration= _;
|
||||
history_expiration;
|
||||
purse_account_limit;
|
||||
purse_timeout= _;
|
||||
purse_timeout;
|
||||
master_sig;
|
||||
}
|
||||
->
|
||||
(* TODO time *)
|
||||
let purse_timeout = None in
|
||||
let history_expiration = None in
|
||||
Conn.exec insert_global_fee
|
||||
( start_date,
|
||||
end_date,
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ let jsont =
|
|||
|> Jsont.Object.mem "t_s" number_or_never_jsont ~enc:Fun.id
|
||||
|> Jsont.Object.finish
|
||||
|
||||
(* TODO exn *)
|
||||
let ptime_to_int64 ptime = ptime |> Ptime.to_float_s |> Int64.of_float
|
||||
|
||||
let ptime_of_int64 i =
|
||||
|
|
@ -77,3 +76,28 @@ let compare a b =
|
|||
let b = ptime_to_int64 b in
|
||||
let c = Int64.compare a b in
|
||||
Some c
|
||||
|
||||
module Span = struct
|
||||
type t = span
|
||||
|
||||
let to_int64 ptime = ptime |> Ptime.Span.to_float_s |> Int64.of_float
|
||||
|
||||
let of_int64 i =
|
||||
match Ptime.Span.of_float_s (Int64.to_float i) with
|
||||
| None ->
|
||||
Fmt.failwith
|
||||
"ptime_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 -> to_int64 p
|
||||
let decode_int64 i = if i = Int64.max_int then None else Some (of_int64 i)
|
||||
|
||||
(* UINT64_MAX represents "forever" *)
|
||||
let bin = Bin.map Bin.neint64 decode_int64 encode_int64
|
||||
let bin_nbo = Bin.map Bin.beint64 decode_int64 encode_int64
|
||||
|
||||
let caqti : t Caqti_type.t =
|
||||
let encode v = Ok (encode_int64 v) in
|
||||
let decode v = Ok (decode_int64 v) in
|
||||
Caqti_type.custom ~encode ~decode Caqti_type.int64
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,6 +7,14 @@
|
|||
type t = Ptime.t option
|
||||
type span = Ptime.Span.t option
|
||||
|
||||
module Span : sig
|
||||
type t = span
|
||||
|
||||
val bin : t Bin.t
|
||||
val bin_nbo : t Bin.t
|
||||
val caqti : t Caqti_type.t
|
||||
end
|
||||
|
||||
val diff : t -> t -> span
|
||||
val add_span_exn : t -> span -> t
|
||||
val of_span_exn : span -> t
|
||||
|
|
@ -16,4 +24,4 @@ val compare : t -> t -> int option
|
|||
val jsont : t Jsont.t
|
||||
val bin : 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