handle global_fees; add do_management.sh

This commit is contained in:
swrup 2026-02-03 14:04:05 +01:00
parent 67bd144bb0
commit ac4058df7e
11 changed files with 226 additions and 40 deletions

View file

@ -303,7 +303,7 @@ module Auditors = struct
let auditor_pub = v.AuditorSetupMessage.auditor_pub in
let validity_start = v.AuditorSetupMessage.validity_start in
let* last_date_opt =
Pg.lookup_auditor_timestamp db_conn auditor_pub |> unwrap_err_caqti
Pg.get_auditor_timestamp db_conn auditor_pub |> unwrap_err_caqti
in
match last_date_opt with
| None ->
@ -341,7 +341,7 @@ module Auditors_disable = struct
let do_ ~db_conn auditor_pub
AuditorTeardownMessage.{ master_sig= _; validity_end } =
let* last_date_opt =
Pg.lookup_auditor_timestamp db_conn auditor_pub |> unwrap_err_caqti
Pg.get_auditor_timestamp db_conn auditor_pub |> unwrap_err_caqti
in
match last_date_opt with
| None -> Error "auditor not found"
@ -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
@ -460,17 +457,33 @@ module Global_fees = struct
let* global_fees =
let start_date = v.GlobalFees.start_date in
let end_date = v.GlobalFees.end_date in
Pg.lookup_global_fees_by_time db_conn ~start_date ~end_date
Pg.get_global_fees_by_time db_conn ~start_date ~end_date
|> unwrap_err_caqti
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
@ -526,7 +539,7 @@ module Wire = struct
let do_ ~db_conn v =
let* last_change_opt =
let payto_uri = v.WireSetupMessage.payto_uri in
Pg.lookup_wire_timestamp db_conn ~payto_uri |> unwrap_err_caqti
Pg.get_wire_timestamp db_conn ~payto_uri |> unwrap_err_caqti
in
match last_change_opt with
| Some _ -> Error "wire already setup"
@ -573,7 +586,7 @@ module Wire_disable = struct
let do_ ~db_conn
WireTeardownMessage.{ payto_uri; master_sig_del= _; validity_end } =
let* last_change_opt =
Pg.lookup_wire_timestamp db_conn ~payto_uri |> unwrap_err_caqti
Pg.get_wire_timestamp db_conn ~payto_uri |> unwrap_err_caqti
in
match last_change_opt with
| None -> Error "wire not found"