This commit is contained in:
parent
035d9b81bf
commit
815613faf6
1 changed files with 64 additions and 71 deletions
135
src/pg.ml
135
src/pg.ml
|
|
@ -221,6 +221,52 @@ module Caqti_type = struct
|
||||||
{ wire_fee; closing_fee; start_date; end_date; sig_ })
|
{ wire_fee; closing_fee; start_date; end_date; sig_ })
|
||||||
Caqti_type.(t5 amount amount time time master_sig)
|
Caqti_type.(t5 amount amount time time master_sig)
|
||||||
|
|
||||||
|
let exchange_wire_account =
|
||||||
|
let master_sig = Bin_sig.MasterWireDetails.caqti in
|
||||||
|
Caqti_type.custom
|
||||||
|
~encode:(fun
|
||||||
|
ExchangeWireAccount.
|
||||||
|
{
|
||||||
|
payto_uri;
|
||||||
|
conversion_url;
|
||||||
|
debit_restrictions;
|
||||||
|
credit_restrictions;
|
||||||
|
master_sig;
|
||||||
|
bank_label;
|
||||||
|
priority;
|
||||||
|
}
|
||||||
|
->
|
||||||
|
Ok
|
||||||
|
( payto_uri,
|
||||||
|
conversion_url,
|
||||||
|
debit_restrictions,
|
||||||
|
credit_restrictions,
|
||||||
|
master_sig,
|
||||||
|
bank_label,
|
||||||
|
priority ))
|
||||||
|
~decode:(fun
|
||||||
|
( payto_uri,
|
||||||
|
conversion_url,
|
||||||
|
debit_restrictions,
|
||||||
|
credit_restrictions,
|
||||||
|
master_sig,
|
||||||
|
bank_label,
|
||||||
|
priority )
|
||||||
|
->
|
||||||
|
Ok
|
||||||
|
{
|
||||||
|
payto_uri;
|
||||||
|
conversion_url;
|
||||||
|
debit_restrictions;
|
||||||
|
credit_restrictions;
|
||||||
|
master_sig;
|
||||||
|
bank_label;
|
||||||
|
priority;
|
||||||
|
})
|
||||||
|
Caqti_type.(
|
||||||
|
t7 payto_uri (option string) account_restrictions account_restrictions
|
||||||
|
master_sig (option string) (option int))
|
||||||
|
|
||||||
include Caqti_request.Infix
|
include Caqti_request.Infix
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -421,87 +467,34 @@ let lookup_wire_timestamp =
|
||||||
|
|
||||||
let insert_wire =
|
let insert_wire =
|
||||||
let insert_wire =
|
let insert_wire =
|
||||||
let master_sig = Bin_sig.MasterWireDetails.caqti in
|
Caqti_type.(t3 exchange_wire_account bool time ->. unit)
|
||||||
Caqti_type.(
|
|
||||||
t8 payto_uri (option string) account_restrictions account_restrictions
|
|
||||||
master_sig time (option string) (option int)
|
|
||||||
->. unit)
|
|
||||||
"INSERT INTO wire_accounts (payto_uri, conversion_url, \
|
"INSERT INTO wire_accounts (payto_uri, conversion_url, \
|
||||||
debit_restrictions, credit_restrictions, master_sig, is_active, \
|
credit_restrictions, debit_restrictions, master_sig, bank_label, \
|
||||||
last_change, bank_label, priority) VALUES \
|
priority, is_active, last_change) VALUES \
|
||||||
($1,$2,$3::TEXT::JSONB,$4::TEXT::JSONB,$5,true,$6,$7,$8)"
|
($1,$2,$3::TEXT::JSONB,$4::TEXT::JSONB,$5,$6,$7,true,$8)"
|
||||||
in
|
in
|
||||||
fun (module Conn : CONN)
|
fun (module Conn : CONN) ~last_change v ->
|
||||||
~last_change
|
let is_active = true in
|
||||||
ExchangeWireAccount.
|
Conn.exec insert_wire (v, is_active, last_change)
|
||||||
{
|
|
||||||
payto_uri;
|
|
||||||
conversion_url;
|
|
||||||
debit_restrictions;
|
|
||||||
credit_restrictions;
|
|
||||||
master_sig;
|
|
||||||
bank_label;
|
|
||||||
priority;
|
|
||||||
}
|
|
||||||
->
|
|
||||||
Conn.exec insert_wire
|
|
||||||
( payto_uri,
|
|
||||||
conversion_url,
|
|
||||||
debit_restrictions,
|
|
||||||
credit_restrictions,
|
|
||||||
master_sig,
|
|
||||||
last_change,
|
|
||||||
bank_label,
|
|
||||||
priority )
|
|
||||||
|
|
||||||
let update_wire =
|
let update_wire =
|
||||||
let update_wire =
|
let update_wire =
|
||||||
let master_sig = Bin_sig.MasterWireDetails.caqti in
|
Caqti_type.(t3 exchange_wire_account bool time ->. unit)
|
||||||
Caqti_type.(
|
"UPDATE wire_accounts SET conversion_url=$2, \
|
||||||
t9 payto_uri bool (option string) account_restrictions
|
debit_restrictions=$3::TEXT::JSONB, \
|
||||||
account_restrictions time master_sig (option string) (option int)
|
credit_restrictions=$4::TEXT::JSONB, master_sig=$5, bank_label=$6, \
|
||||||
->. unit)
|
priority=$7, is_active=$8, last_change=$9 WHERE payto_uri=$1"
|
||||||
"UPDATE wire_accounts SET is_active=$2, conversion_url=$3, \
|
|
||||||
debit_restrictions=$4::TEXT::JSONB, \
|
|
||||||
credit_restrictions=$5::TEXT::JSONB, last_change=$6, master_sig=$7, \
|
|
||||||
bank_label=$8, priority=$9 WHERE payto_uri=$1"
|
|
||||||
in
|
in
|
||||||
fun (module Conn : CONN)
|
fun (module Conn : CONN) ~is_active ~last_change v ->
|
||||||
~last_change
|
Conn.exec update_wire (v, is_active, last_change)
|
||||||
ExchangeWireAccount.
|
|
||||||
{
|
|
||||||
payto_uri;
|
|
||||||
conversion_url;
|
|
||||||
debit_restrictions;
|
|
||||||
credit_restrictions;
|
|
||||||
master_sig;
|
|
||||||
bank_label;
|
|
||||||
priority;
|
|
||||||
}
|
|
||||||
->
|
|
||||||
let enabled = true in
|
|
||||||
Conn.exec update_wire
|
|
||||||
( payto_uri,
|
|
||||||
enabled,
|
|
||||||
conversion_url,
|
|
||||||
debit_restrictions,
|
|
||||||
credit_restrictions,
|
|
||||||
last_change,
|
|
||||||
master_sig,
|
|
||||||
bank_label,
|
|
||||||
priority )
|
|
||||||
|
|
||||||
let disable_wire =
|
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`?
|
|
||||||
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 conversion_url=NULL, debit_restrictions=NULL, \
|
||||||
debit_restrictions=NULL::TEXT::JSONB, \
|
credit_restrictions=NULL, master_sig=NULL, bank_label=NULL, \
|
||||||
credit_restrictions=NULL::TEXT::JSONB, last_change=$2, master_sig=NULL, \
|
priority=NULL, is_active=FALSE, last_change=$2 WHERE payto_uri=$1"
|
||||||
bank_label=NULL, priority=NULL WHERE payto_uri=$1"
|
|
||||||
in
|
in
|
||||||
fun (module Conn : CONN) ~payto_uri ~validity_end ->
|
fun (module Conn : CONN) ~payto_uri ~validity_end ->
|
||||||
Conn.exec disable_wire (payto_uri, validity_end)
|
Conn.exec disable_wire (payto_uri, validity_end)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue