This commit is contained in:
swrup 2025-12-11 08:55:52 +01:00
parent 2d67963656
commit be56240ddc
2 changed files with 27 additions and 31 deletions

View file

@ -240,32 +240,24 @@ let verify_auditor_add_sig
h_auditor_url= Bin_type.Hash_64_cstr.hash auditor_url; h_auditor_url= Bin_type.Hash_64_cstr.hash auditor_url;
} }
(* todo: there is something about use of monotonic time + protection against replay attack that I don't understand *) (* TODO timestamps last_change +/- checks *)
let update_auditor ~db_conn (* todo: there is something about use of monotonic time
AuditorSetupMessage. + protection against replay attack that I don't understand *)
{ auditor_url; auditor_name; auditor_pub; master_sig= _; validity_start } let update_auditor ~db_conn v =
= let auditor_pub = v.AuditorSetupMessage.auditor_pub in
let validity_start = v.AuditorSetupMessage.validity_start in
let* last_date_opt = let* last_date_opt =
Pg.lookup_auditor_timestamp db_conn auditor_pub |> unwrap_err_caqti Pg.lookup_auditor_timestamp db_conn auditor_pub |> unwrap_err_caqti
in in
match last_date_opt with match last_date_opt with
| None -> | None ->
let+ () = let+ () = Pg.insert_auditor db_conn v |> unwrap_err_caqti in
Pg.insert_auditor db_conn ~auditor_pub ~auditor_url ~auditor_name
~start_date:validity_start
|> unwrap_err_caqti
in
() ()
| Some last_date -> | Some last_date ->
let cmp = Timestamp.compare last_date validity_start |> Option.get in let cmp = Timestamp.compare last_date validity_start |> Option.get in
if cmp > 0 then Error "more recent management auditor already present" if cmp > 0 then Error "more recent management auditor already present"
else else
let enabled = true in let+ () = Pg.update_auditor db_conn v |> unwrap_err_caqti in
let+ () =
Pg.update_auditor db_conn ~auditor_pub ~auditor_url ~auditor_name
~enabled ~change_date:validity_start
|> unwrap_err_caqti
in
() ()
let verify_auditor_disable_sig auditor_pub let verify_auditor_disable_sig auditor_pub
@ -285,10 +277,8 @@ let auditor_disable ~db_conn auditor_pub
let cmp = Timestamp.compare last_date validity_end |> Option.get in let cmp = Timestamp.compare last_date validity_end |> Option.get in
if cmp > 0 then Error "more recent management auditor already present" if cmp > 0 then Error "more recent management auditor already present"
else else
let enabled = false in
let+ () = let+ () =
Pg.update_auditor db_conn ~auditor_pub ~auditor_url:"" Pg.disable_auditor db_conn ~auditor_pub ~change_date:validity_end
~auditor_name:"" ~enabled ~change_date:validity_end
|> unwrap_err_caqti |> unwrap_err_caqti
in in
() ()

View file

@ -203,12 +203,11 @@ let insert_auditor =
is_active, last_change) VALUES ($1, $2, $3, true, $4)" is_active, last_change) VALUES ($1, $2, $3, true, $4)"
in in
fun (module Conn : CONN) fun (module Conn : CONN)
~auditor_pub Api.AuditorSetupMessage.
~auditor_url { auditor_url; auditor_name; auditor_pub; master_sig= _; validity_start }
~auditor_name
~start_date
-> ->
Conn.exec insert_auditor (auditor_pub, auditor_name, auditor_url, start_date) Conn.exec insert_auditor
(auditor_pub, auditor_name, auditor_url, validity_start)
let update_auditor = let update_auditor =
let update_auditor = let update_auditor =
@ -217,14 +216,20 @@ let update_auditor =
last_change=$5 WHERE auditor_pub=$1" last_change=$5 WHERE auditor_pub=$1"
in in
fun (module Conn : CONN) fun (module Conn : CONN)
~auditor_pub Api.AuditorSetupMessage.
~auditor_url { auditor_url; auditor_name; auditor_pub; master_sig= _; validity_start }
~auditor_name
~change_date
~enabled
-> ->
Conn.exec update_auditor Conn.exec update_auditor
(auditor_pub, auditor_url, auditor_name, enabled, change_date) (auditor_pub, auditor_url, auditor_name, true, validity_start)
let disable_auditor =
let update_auditor =
Caqti_type.(t5 eddsa_pub string string bool time ->. unit)
"UPDATE auditors SET auditor_url=$2, auditor_name=$3, is_active=$4, \
last_change=$5 WHERE auditor_pub=$1"
in
fun (module Conn : CONN) ~auditor_pub ~change_date ->
Conn.exec update_auditor (auditor_pub, "", "", false, change_date)
let lookup_wire_fee_by_time = let lookup_wire_fee_by_time =
let lookup_wire_fee_by_time = let lookup_wire_fee_by_time =
@ -391,7 +396,8 @@ let disable_wire =
let disable_wire = let disable_wire =
(* TODO (* TODO
check syntax on this check syntax on this
don't erase old values with null and just change `is_active` and `last_change`? *) don't erase old values with null and just change `is_active` and `last_change`?
or re-use the update query *)
Caqti_type.(t2 payto_uri time ->. unit) Caqti_type.(t2 payto_uri time ->. unit)
"UPDATE wire_accounts SET is_active=false, conversion_url=NULL, \ "UPDATE wire_accounts SET is_active=false, conversion_url=NULL, \
debit_restrictions=NULL::TEXT::JSONB, \ debit_restrictions=NULL::TEXT::JSONB, \