pg global_fees fix + caqti_type
This commit is contained in:
parent
5b7c243f8c
commit
e57b12f9d5
2 changed files with 80 additions and 57 deletions
|
|
@ -464,17 +464,17 @@ module Global_fees = struct
|
||||||
}
|
}
|
||||||
|
|
||||||
let do_ ~db_conn v =
|
let do_ ~db_conn v =
|
||||||
let* global_fees_opt =
|
let* global_fees =
|
||||||
let start_date = v.GlobalFees.start_date in
|
let start_date = v.GlobalFees.start_date in
|
||||||
let end_date = v.GlobalFees.end_date in
|
let end_date = v.GlobalFees.end_date in
|
||||||
Pg.lookup_global_fee_by_time db_conn ~start_date ~end_date
|
Pg.lookup_global_fees_by_time db_conn ~start_date ~end_date
|
||||||
|> unwrap_err_caqti
|
|> unwrap_err_caqti
|
||||||
in
|
in
|
||||||
match global_fees_opt with
|
match global_fees with
|
||||||
| Some _ -> Error "global-fees already setup"
|
| [] ->
|
||||||
| None ->
|
|
||||||
let+ () = Pg.insert_global_fee db_conn v |> unwrap_err_caqti in
|
let+ () = Pg.insert_global_fee db_conn v |> unwrap_err_caqti in
|
||||||
()
|
()
|
||||||
|
| _l -> Error "global-fees already setup"
|
||||||
|
|
||||||
let jsont = GlobalFees.jsont
|
let jsont = GlobalFees.jsont
|
||||||
|
|
||||||
|
|
|
||||||
127
src/pg.ml
127
src/pg.ml
|
|
@ -48,6 +48,59 @@ module Caqti_type = struct
|
||||||
~decode:(fun s -> Api.decode (Jsont.list AccountRestriction.jsont) s)
|
~decode:(fun s -> Api.decode (Jsont.list AccountRestriction.jsont) s)
|
||||||
string
|
string
|
||||||
|
|
||||||
|
let global_fee =
|
||||||
|
let master_sig = Bin_sig.GlobalFees.caqti in
|
||||||
|
custom
|
||||||
|
~encode:(fun
|
||||||
|
GlobalFees.
|
||||||
|
{
|
||||||
|
start_date;
|
||||||
|
end_date;
|
||||||
|
history_fee;
|
||||||
|
account_fee;
|
||||||
|
purse_fee;
|
||||||
|
history_expiration;
|
||||||
|
purse_account_limit;
|
||||||
|
purse_timeout;
|
||||||
|
master_sig;
|
||||||
|
}
|
||||||
|
->
|
||||||
|
Ok
|
||||||
|
( start_date,
|
||||||
|
end_date,
|
||||||
|
history_fee,
|
||||||
|
account_fee,
|
||||||
|
purse_fee,
|
||||||
|
history_expiration,
|
||||||
|
purse_account_limit,
|
||||||
|
purse_timeout,
|
||||||
|
master_sig ))
|
||||||
|
~decode:(fun
|
||||||
|
( start_date,
|
||||||
|
end_date,
|
||||||
|
history_fee,
|
||||||
|
account_fee,
|
||||||
|
purse_fee,
|
||||||
|
history_expiration,
|
||||||
|
purse_account_limit,
|
||||||
|
purse_timeout,
|
||||||
|
master_sig )
|
||||||
|
->
|
||||||
|
Ok
|
||||||
|
{
|
||||||
|
start_date;
|
||||||
|
end_date;
|
||||||
|
history_fee;
|
||||||
|
account_fee;
|
||||||
|
purse_fee;
|
||||||
|
history_expiration;
|
||||||
|
purse_account_limit;
|
||||||
|
purse_timeout;
|
||||||
|
master_sig;
|
||||||
|
})
|
||||||
|
Caqti_type.(
|
||||||
|
t9 time time amount amount amount time_span int32 time_span master_sig)
|
||||||
|
|
||||||
include struct
|
include struct
|
||||||
(* alias for hash *)
|
(* alias for hash *)
|
||||||
|
|
||||||
|
|
@ -82,6 +135,7 @@ let preflight =
|
||||||
in
|
in
|
||||||
fun (module Conn : CONN) -> Syntax.list_iter (fun p -> Conn.exec p ()) l
|
fun (module Conn : CONN) -> Syntax.list_iter (fun p -> Conn.exec p ()) l
|
||||||
|
|
||||||
|
(* TODO return type *)
|
||||||
let lookup_signing_key =
|
let lookup_signing_key =
|
||||||
let lookup_signing_key =
|
let lookup_signing_key =
|
||||||
Caqti_type.(eddsa_pub ->? t3 time time time)
|
Caqti_type.(eddsa_pub ->? t3 time time time)
|
||||||
|
|
@ -107,6 +161,7 @@ let activate_signing_key =
|
||||||
Conn.exec insert_signkey
|
Conn.exec insert_signkey
|
||||||
(pub, stamp_start, stamp_expire, stamp_end, master_sig)
|
(pub, stamp_start, stamp_expire, stamp_end, master_sig)
|
||||||
|
|
||||||
|
(* TODO return type *)
|
||||||
let lookup_denomination_key =
|
let lookup_denomination_key =
|
||||||
let lookup_denomination_key =
|
let lookup_denomination_key =
|
||||||
Caqti_type.(
|
Caqti_type.(
|
||||||
|
|
@ -231,6 +286,7 @@ let disable_auditor =
|
||||||
fun (module Conn : CONN) ~auditor_pub ~change_date ->
|
fun (module Conn : CONN) ~auditor_pub ~change_date ->
|
||||||
Conn.exec update_auditor (auditor_pub, "", "", false, change_date)
|
Conn.exec update_auditor (auditor_pub, "", "", false, change_date)
|
||||||
|
|
||||||
|
(* TODO return type *)
|
||||||
let lookup_wire_fee_by_time =
|
let lookup_wire_fee_by_time =
|
||||||
let lookup_wire_fee_by_time =
|
let lookup_wire_fee_by_time =
|
||||||
Caqti_type.(t3 wire_method time time ->? t2 amount amount)
|
Caqti_type.(t3 wire_method time time ->? t2 amount amount)
|
||||||
|
|
@ -258,54 +314,35 @@ let insert_wire_fee =
|
||||||
Conn.exec insert_wire_fee
|
Conn.exec insert_wire_fee
|
||||||
(wire_method, start_date, end_date, wire_fee, closing_fee, master_sig)
|
(wire_method, start_date, end_date, wire_fee, closing_fee, master_sig)
|
||||||
|
|
||||||
let lookup_global_fee_by_time =
|
let get_global_fees =
|
||||||
let lookup_global_fee_by_time =
|
let get_global_fees =
|
||||||
let global_fee =
|
Caqti_type.(time ->* global_fee)
|
||||||
Caqti_type.(t6 amount amount amount time_span time_span int32)
|
"SELECT start_date, end_date, (history_fee).*, (account_fee).*, \
|
||||||
in
|
(purse_fee).*, history_expiration, purse_account_limit, purse_timeout, \
|
||||||
|
master_sig FROM global_fee WHERE start_date >= $1"
|
||||||
|
in
|
||||||
|
fun (module Conn : CONN) ~start_date ->
|
||||||
|
Conn.collect_list get_global_fees start_date
|
||||||
|
|
||||||
|
let lookup_global_fees_by_time =
|
||||||
|
let lookup_global_fees_by_time =
|
||||||
Caqti_type.(t2 time time ->? global_fee)
|
Caqti_type.(t2 time time ->? global_fee)
|
||||||
"SELECT (history_fee).*, (account_fee).*, (purse_fee).*, purse_timeout, \
|
"SELECT start_date, end_date, (history_fee).*, (account_fee).*, \
|
||||||
history_expiration, purse_account_limit FROM global_fee WHERE end_date \
|
(purse_fee).*, history_expiration, purse_account_limit, purse_timeout, \
|
||||||
> $1 AND start_date < $2;"
|
master_sig FROM global_fee WHERE end_date > $1 AND start_date < $2"
|
||||||
in
|
in
|
||||||
fun (module Conn : CONN) ~start_date ~end_date ->
|
fun (module Conn : CONN) ~start_date ~end_date ->
|
||||||
Conn.find_opt lookup_global_fee_by_time (start_date, end_date)
|
Conn.collect_list lookup_global_fees_by_time (start_date, end_date)
|
||||||
|
|
||||||
let insert_global_fee =
|
let insert_global_fee =
|
||||||
let insert_global_fee =
|
let insert_global_fee =
|
||||||
let master_sig = Bin_sig.GlobalFees.caqti in
|
Caqti_type.(global_fee ->. unit)
|
||||||
Caqti_type.(
|
|
||||||
t9 time time amount amount amount time_span time_span int32 master_sig
|
|
||||||
->. unit)
|
|
||||||
"INSERT INTO global_fee (start_date, end_date, history_fee, account_fee, \
|
"INSERT INTO global_fee (start_date, end_date, history_fee, account_fee, \
|
||||||
purse_fee, purse_timeout, history_expiration, purse_account_limit, \
|
purse_fee, history_expiration, purse_account_limit, purse_timeout, \
|
||||||
master_sig) VALUES ($1, $2, ($3,$4), ($5,$6), ($7,$8), $9, $10, $11, \
|
master_sig) VALUES ($1, $2, ($3,$4), ($5,$6), ($7,$8), $9, $10, $11, \
|
||||||
$12)"
|
$12)"
|
||||||
in
|
in
|
||||||
fun (module Conn : CONN)
|
fun (module Conn : CONN) v -> Conn.exec insert_global_fee v
|
||||||
GlobalFees.
|
|
||||||
{
|
|
||||||
start_date;
|
|
||||||
end_date;
|
|
||||||
history_fee;
|
|
||||||
account_fee;
|
|
||||||
purse_fee;
|
|
||||||
history_expiration;
|
|
||||||
purse_account_limit;
|
|
||||||
purse_timeout;
|
|
||||||
master_sig;
|
|
||||||
}
|
|
||||||
->
|
|
||||||
Conn.exec insert_global_fee
|
|
||||||
( start_date,
|
|
||||||
end_date,
|
|
||||||
history_fee,
|
|
||||||
account_fee,
|
|
||||||
purse_fee,
|
|
||||||
purse_timeout,
|
|
||||||
history_expiration,
|
|
||||||
purse_account_limit,
|
|
||||||
master_sig )
|
|
||||||
|
|
||||||
let lookup_wire_timestamp =
|
let lookup_wire_timestamp =
|
||||||
let lookup_wire_timestamp =
|
let lookup_wire_timestamp =
|
||||||
|
|
@ -524,20 +561,6 @@ let get_wire_fees =
|
||||||
{ wire_fee; closing_fee; start_date; end_date; sig_ })
|
{ wire_fee; closing_fee; start_date; end_date; sig_ })
|
||||||
l
|
l
|
||||||
|
|
||||||
let get_global_fees =
|
|
||||||
let get_global_fees =
|
|
||||||
let master_sig = Bin_sig.GlobalFees.caqti in
|
|
||||||
Caqti_type.(
|
|
||||||
time
|
|
||||||
->* t9 time time amount amount amount time_span time_span int master_sig)
|
|
||||||
"SELECT start_date, end_date, (history_fee).*, (account_fee).*, \
|
|
||||||
(purse_fee).*, purse_timeout, history_expiration, purse_account_limit, \
|
|
||||||
master_sig FROM global_fee WHERE start_date >= $1"
|
|
||||||
in
|
|
||||||
fun (module Conn : CONN) ~start_date ->
|
|
||||||
Conn.collect_list get_global_fees start_date
|
|
||||||
|
|
||||||
(* TODO record types for some results *)
|
|
||||||
(* TODO
|
(* TODO
|
||||||
iterate_denominations
|
iterate_denominations
|
||||||
iterate_active_signkeys
|
iterate_active_signkeys
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue