handle global_fees; add do_management.sh
This commit is contained in:
parent
4754517d8f
commit
773b1b0d68
11 changed files with 207 additions and 19 deletions
|
|
@ -117,3 +117,5 @@ let bin_nbo =
|
|||
|+ field beint32 (fun t -> t.fraction)
|
||||
|+ field (bytes currency_len) (fun t -> pad_currency t.currency)
|
||||
|> sealr
|
||||
|
||||
let dummy_value = "DUMMY:0.0" |> of_string |> Result.get_ok
|
||||
|
|
|
|||
|
|
@ -25,3 +25,7 @@ val jsont : t Jsont.t
|
|||
(* only for encoding *)
|
||||
val bin : t Bin.t
|
||||
val bin_nbo : t Bin.t
|
||||
|
||||
(* TODO
|
||||
dummy value to use as placeholder for WIP *)
|
||||
val dummy_value : t
|
||||
|
|
|
|||
|
|
@ -190,9 +190,9 @@ let mk_keys ~db_conn (module Sm : Secmod.S) ~last_issue_date =
|
|||
sign_f ~f:(Sm.sign_with_signkey ~pub:exchange_pub) R.{ list_issue_date; hc }
|
||||
in
|
||||
|
||||
let recoup = (* todo /recoup *) [] in
|
||||
let recoup = (* TODO /recoup *) [] in
|
||||
let* global_fees =
|
||||
Pg.get_global_fees db_conn ~start_date:None |> unwrap_err_caqti
|
||||
Pg.get_global_fees db_conn ~start_date:Timestamp.epoch |> unwrap_err_caqti
|
||||
in
|
||||
let auditors = (* TODO *) [] in
|
||||
let extensions = None in
|
||||
|
|
|
|||
|
|
@ -433,13 +433,10 @@ module Global_fees = struct
|
|||
purse_timeout;
|
||||
master_sig;
|
||||
} =
|
||||
(* TODO what is kyc_timeout, kyc_fee ? *)
|
||||
let dummy_amount =
|
||||
Amount.make ~sign:None ~currency:"EUR" ~value:0_L ~fraction:0_l
|
||||
|> Result.get_ok
|
||||
in
|
||||
(* TODO KYC
|
||||
what is kyc_timeout, kyc_fee ? *)
|
||||
let kyc_timeout = None in
|
||||
let kyc_fee = dummy_amount in
|
||||
let kyc_fee = Amount.dummy_value in
|
||||
(* * *)
|
||||
let open Bin_sig.GlobalFees in
|
||||
verify_f ~f:Sm.verify_with_master_key master_sig
|
||||
|
|
@ -465,12 +462,28 @@ module Global_fees = struct
|
|||
in
|
||||
match global_fees with
|
||||
| [] ->
|
||||
let+ () = Pg.insert_global_fee db_conn v |> unwrap_err_caqti in
|
||||
let+ () = Pg.insert_global_fees db_conn v |> unwrap_err_caqti in
|
||||
Logs.info (fun m -> m "added global fees");
|
||||
()
|
||||
| _l -> Error "global-fees already setup"
|
||||
| [ vv ] -> (
|
||||
match v.master_sig = vv.master_sig with
|
||||
| false ->
|
||||
Error
|
||||
"a different global-fees was already setup for this time frame"
|
||||
| true ->
|
||||
Logs.info (fun m -> m "an identical global-fees was already setup");
|
||||
Ok ())
|
||||
| _ ->
|
||||
Error
|
||||
"invalid database state, multiple global-fees found in database for \
|
||||
this time frame"
|
||||
|
||||
let jsont = GlobalFees.jsont
|
||||
|
||||
(* TODO global_fees
|
||||
ensure it is defined for the current time.
|
||||
there should be only one global_fees for each moment in time
|
||||
and once set for a timeframe, it should not change. *)
|
||||
let f req server _env =
|
||||
Logs.info (fun m -> m "POST /management/global-fees/");
|
||||
let sm = Vif.Server.device Devices.secmod server in
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@
|
|||
transaction
|
||||
|
||||
should check validity of signatures got from db, for /management at least *)
|
||||
(* TODO time
|
||||
fix comparison with timestamp footgun *)
|
||||
|
||||
module type CONN = Caqti_miou.CONNECTION
|
||||
|
||||
|
|
@ -303,15 +305,15 @@ let get_global_fees_by_time =
|
|||
fun (module Conn : CONN) ~start_date ~end_date ->
|
||||
Conn.collect_list get_global_fees_by_time (start_date, end_date)
|
||||
|
||||
let insert_global_fee =
|
||||
let insert_global_fee =
|
||||
let insert_global_fees =
|
||||
let insert_global_fees =
|
||||
Caqti_type.(global_fee ->. unit)
|
||||
"INSERT INTO global_fee (start_date, end_date, history_fee, account_fee, \
|
||||
purse_fee, history_expiration, purse_account_limit, purse_timeout, \
|
||||
master_sig) VALUES ($1, $2, ($3,$4), ($5,$6), ($7,$8), $9, $10, $11, \
|
||||
$12)"
|
||||
in
|
||||
fun (module Conn : CONN) v -> Conn.exec insert_global_fee v
|
||||
fun (module Conn : CONN) v -> Conn.exec insert_global_fees v
|
||||
|
||||
let get_wire_timestamp =
|
||||
let get_wire_timestamp =
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
type t = Ptime.t option
|
||||
type span = Ptime.Span.t option
|
||||
|
||||
let epoch = Some Ptime.epoch
|
||||
|
||||
let diff a b =
|
||||
match (a, b) with
|
||||
| None, _ | _, None -> None
|
||||
|
|
@ -23,6 +25,23 @@ let of_span_exn = function
|
|||
|
||||
(* -- *)
|
||||
|
||||
(* TODO
|
||||
this doesn't handle "never" value, and truncate time *)
|
||||
let of_string s =
|
||||
match Float.of_string_opt s with
|
||||
| None -> Error "Timestamp.of_string failure: not a float"
|
||||
| Some v -> (
|
||||
match Ptime.of_float_s v with
|
||||
| None -> Error "Timestamp.of_string failure"
|
||||
| Some v -> Ok (Some v))
|
||||
|
||||
let pp fmt t =
|
||||
match t with
|
||||
| None -> Fmt.pf fmt {|"never"|}
|
||||
| Some v ->
|
||||
let v = Ptime.to_float_s v in
|
||||
Fmt.pf fmt {|%f|} v
|
||||
|
||||
(* microseconds since the UNIX Epoch, or "never" if None *)
|
||||
let jsont =
|
||||
let number_or_never_jsont =
|
||||
|
|
@ -62,7 +81,7 @@ let decode_int64 i = if i = Int64.max_int then None else Some (ptime_of_int64 i)
|
|||
let bin = Bin.map Bin.neint64 decode_int64 encode_int64
|
||||
let bin_nbo = Bin.map Bin.beint64 decode_int64 encode_int64
|
||||
|
||||
let caqti : Ptime.t option Caqti_type.t =
|
||||
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
|
||||
|
|
@ -80,6 +99,23 @@ let compare a b =
|
|||
module Span = struct
|
||||
type t = span
|
||||
|
||||
(* TODO
|
||||
this doesn't handle "never" value, and truncate time *)
|
||||
let of_string s =
|
||||
match Float.of_string_opt s with
|
||||
| None -> Error "Timestamp.Span.of_string failure: not a float"
|
||||
| Some v -> (
|
||||
match Ptime.Span.of_float_s v with
|
||||
| None -> Error "Timestamp.Span.of_string failure"
|
||||
| Some v -> Ok (Some v))
|
||||
|
||||
let pp fmt t =
|
||||
match t with
|
||||
| None -> Fmt.pf fmt {|"forever"|}
|
||||
| Some v ->
|
||||
let v = Ptime.Span.to_float_s v in
|
||||
Fmt.pf fmt {|%f|} v
|
||||
|
||||
let to_int64 ptime = ptime |> Ptime.Span.to_float_s |> Int64.of_float
|
||||
|
||||
let of_int64 i =
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
(* TODO time
|
||||
uhuh!
|
||||
need to be int64 for binary/pg round trip
|
||||
|
||||
really need to fix this module *)
|
||||
really need to fix this module
|
||||
don't use option for never/forever *)
|
||||
|
||||
type t = Ptime.t option
|
||||
type span = Ptime.Span.t option
|
||||
|
|
@ -10,17 +10,27 @@ type span = Ptime.Span.t option
|
|||
module Span : sig
|
||||
type t = span
|
||||
|
||||
val of_string : string -> (t, string) result
|
||||
val pp : Stdlib.Format.formatter -> t -> unit
|
||||
|
||||
(* - *)
|
||||
|
||||
val jsont : t Jsont.t
|
||||
val bin : t Bin.t
|
||||
val bin_nbo : t Bin.t
|
||||
val caqti : t Caqti_type.t
|
||||
end
|
||||
|
||||
val epoch : t
|
||||
val diff : t -> t -> span
|
||||
val add_span_exn : t -> span -> t
|
||||
val of_span_exn : span -> t
|
||||
val compare : t -> t -> int option
|
||||
|
||||
(* used for offline tool argument conversion *)
|
||||
val of_string : string -> (t, string) result
|
||||
val pp : Stdlib.Format.formatter -> t -> unit
|
||||
|
||||
(* - *)
|
||||
val jsont : t Jsont.t
|
||||
val bin : t Bin.t
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue