This commit is contained in:
swrup 2025-12-11 07:23:51 +01:00
parent 0e46ea162a
commit a3e3b8fd33
5 changed files with 50 additions and 26 deletions

View file

@ -5,12 +5,6 @@ open Bin_type
(* TODO keep this? (* TODO keep this?
some of those are actuall ecdhe, or union of eddsa|ecdhe *) some of those are actuall ecdhe, or union of eddsa|ecdhe *)
module Aliases = struct module Aliases = struct
module TimestampNBO : Time_S = struct
type t = Timestamp.t
let bin = Timestamp.bin_nbo
end
module AmountNBO = struct module AmountNBO = struct
type t = Amount.t type t = Amount.t
@ -397,7 +391,7 @@ module GlobalFees = struct
}) })
|+ Purpose.field purpose |+ Purpose.field purpose
|+ field TimeAbsoluteNBO.bin (fun t -> t.start_date) |+ 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.purse_timeout)
|+ field TimeRelativeNBO.bin (fun t -> t.kyc_timeout) |+ field TimeRelativeNBO.bin (fun t -> t.kyc_timeout)
|+ field TimeRelativeNBO.bin (fun t -> t.history_expiration) |+ field TimeRelativeNBO.bin (fun t -> t.history_expiration)

View file

@ -58,28 +58,29 @@ module Bytes_64 = struct
end end
(* -- Time -- *) (* -- Time -- *)
module type Time_S = sig module TimeAbsolute = struct
type t = Timestamp.t
val bin : t Bin.t
end
module TIME : Time_S = struct
type t = Timestamp.t type t = Timestamp.t
let bin = Timestamp.bin let bin = Timestamp.bin
end end
module TIME_NBO : Time_S = struct module TimeAbsoluteNBO = struct
type t = Timestamp.t type t = Timestamp.t
let bin = Timestamp.bin_nbo let bin = Timestamp.bin_nbo
end end
module TimeAbsolute : Time_S = TIME module TimeRelative = struct
module TimeAbsoluteNBO : Time_S = TIME_NBO type t = Timestamp.Span.t
module TimeRelative : Time_S = TIME
module TimeRelativeNBO : Time_S = TIME_NBO let bin = Timestamp.Span.bin
end
module TimeRelativeNBO = struct
type t = Timestamp.Span.t
let bin = Timestamp.Span.bin_nbo
end
(* -- Cryptographic primitives -- *) (* -- Cryptographic primitives -- *)

View file

@ -277,15 +277,12 @@ let insert_global_fee =
history_fee; history_fee;
account_fee; account_fee;
purse_fee; purse_fee;
history_expiration= _; history_expiration;
purse_account_limit; purse_account_limit;
purse_timeout= _; purse_timeout;
master_sig; master_sig;
} }
-> ->
(* TODO time *)
let purse_timeout = None in
let history_expiration = None in
Conn.exec insert_global_fee Conn.exec insert_global_fee
( start_date, ( start_date,
end_date, end_date,

View file

@ -48,7 +48,6 @@ let jsont =
|> Jsont.Object.mem "t_s" number_or_never_jsont ~enc:Fun.id |> Jsont.Object.mem "t_s" number_or_never_jsont ~enc:Fun.id
|> Jsont.Object.finish |> Jsont.Object.finish
(* TODO exn *)
let ptime_to_int64 ptime = ptime |> Ptime.to_float_s |> Int64.of_float let ptime_to_int64 ptime = ptime |> Ptime.to_float_s |> Int64.of_float
let ptime_of_int64 i = let ptime_of_int64 i =
@ -77,3 +76,28 @@ let compare a b =
let b = ptime_to_int64 b in let b = ptime_to_int64 b in
let c = Int64.compare a b in let c = Int64.compare a b in
Some c 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

View file

@ -7,6 +7,14 @@
type t = Ptime.t option type t = Ptime.t option
type span = Ptime.Span.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 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
@ -16,4 +24,4 @@ val compare : t -> t -> int option
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