+
This commit is contained in:
parent
638cccc185
commit
26f5e392ee
6 changed files with 195 additions and 49 deletions
101
src/pg.ml
101
src/pg.ml
|
|
@ -38,13 +38,16 @@ module Caqti_type = struct
|
|||
let eddsa_pub = EddsaPublicKey.caqti
|
||||
let eddsa_sig = EddsaSignature.caqti
|
||||
|
||||
(* TODO json strings? *)
|
||||
let json_str = Caqti_type.string
|
||||
|
||||
(* todo: enum type for wire_method? *)
|
||||
let wire_method = Caqti_type.string
|
||||
let payto_uri = Caqti_type.string
|
||||
|
||||
let account_restrictions =
|
||||
custom
|
||||
~encode:(fun l -> Api.encode (Jsont.list AccountRestriction.jsont) l)
|
||||
~decode:(fun s -> Api.decode (Jsont.list AccountRestriction.jsont) s)
|
||||
string
|
||||
|
||||
include struct
|
||||
(* alias for hash *)
|
||||
|
||||
|
|
@ -324,8 +327,8 @@ let insert_wire =
|
|||
let insert_wire =
|
||||
let master_sig = Bin_sig.MasterWireDetails.caqti in
|
||||
Caqti_type.(
|
||||
t8 payto_uri string json_str json_str master_sig time (option string)
|
||||
(option int)
|
||||
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, \
|
||||
debit_restrictions, credit_restrictions, master_sig, is_active, \
|
||||
|
|
@ -333,29 +336,25 @@ let insert_wire =
|
|||
($1,$2,$3::TEXT::JSONB,$4::TEXT::JSONB,$5,true,$6,$7,$8)"
|
||||
in
|
||||
fun (module Conn : CONN)
|
||||
WireSetupMessage.
|
||||
~last_change
|
||||
ExchangeWireAccount.
|
||||
{
|
||||
payto_uri;
|
||||
master_sig_wire;
|
||||
master_sig_add= _;
|
||||
validity_start;
|
||||
conversion_url;
|
||||
debit_restrictions;
|
||||
credit_restrictions;
|
||||
master_sig;
|
||||
bank_label;
|
||||
priority;
|
||||
}
|
||||
->
|
||||
(* TODO wire
|
||||
some field are allowed to be NULL
|
||||
-> use option? *)
|
||||
let conversion_url = "" in
|
||||
let credit_restrictions = "" in
|
||||
let debit_restrictions = "" in
|
||||
Conn.exec insert_wire
|
||||
( payto_uri,
|
||||
conversion_url,
|
||||
debit_restrictions,
|
||||
credit_restrictions,
|
||||
master_sig_wire,
|
||||
validity_start,
|
||||
master_sig,
|
||||
last_change,
|
||||
bank_label,
|
||||
priority )
|
||||
|
||||
|
|
@ -363,8 +362,8 @@ let update_wire =
|
|||
let update_wire =
|
||||
let master_sig = Bin_sig.MasterWireDetails.caqti in
|
||||
Caqti_type.(
|
||||
t9 payto_uri bool string json_str json_str time master_sig (option string)
|
||||
(option int)
|
||||
t9 payto_uri bool (option string) account_restrictions
|
||||
account_restrictions time master_sig (option string) (option int)
|
||||
->. unit)
|
||||
"UPDATE wire_accounts SET is_active=$2, conversion_url=$3, \
|
||||
debit_restrictions=$4::TEXT::JSONB, \
|
||||
|
|
@ -372,20 +371,18 @@ let update_wire =
|
|||
bank_label=$8, priority=$9 WHERE payto_uri=$1"
|
||||
in
|
||||
fun (module Conn : CONN)
|
||||
WireSetupMessage.
|
||||
~last_change
|
||||
ExchangeWireAccount.
|
||||
{
|
||||
payto_uri;
|
||||
master_sig_wire;
|
||||
master_sig_add= _;
|
||||
validity_start;
|
||||
conversion_url;
|
||||
debit_restrictions;
|
||||
credit_restrictions;
|
||||
master_sig;
|
||||
bank_label;
|
||||
priority;
|
||||
}
|
||||
->
|
||||
(* TODO wire *)
|
||||
let conversion_url = "" in
|
||||
let credit_restrictions = "" in
|
||||
let debit_restrictions = "" in
|
||||
let enabled = true in
|
||||
Conn.exec update_wire
|
||||
( payto_uri,
|
||||
|
|
@ -393,8 +390,8 @@ let update_wire =
|
|||
conversion_url,
|
||||
debit_restrictions,
|
||||
credit_restrictions,
|
||||
validity_start,
|
||||
master_sig_wire,
|
||||
last_change,
|
||||
master_sig,
|
||||
bank_label,
|
||||
priority )
|
||||
|
||||
|
|
@ -485,21 +482,55 @@ let insert_partner =
|
|||
master_sig,
|
||||
partner_base_url )
|
||||
|
||||
(* TODO wire
|
||||
option for nullable fields?
|
||||
collect in a record type *)
|
||||
let get_wire_accouts =
|
||||
let get_wire_accounts =
|
||||
let master_sig = Bin_sig.MasterWireDetails.caqti in
|
||||
Caqti_type.(
|
||||
unit
|
||||
->* t7 string (option string) (option string) int (option json_str)
|
||||
(option json_str) master_sig)
|
||||
->* t7 string (option string) account_restrictions account_restrictions
|
||||
master_sig (option string) (option int))
|
||||
"SELECT payto_uri, conversion_url, debit_restrictions::TEXT, \
|
||||
credit_restrictions::TEXT, master_sig, bank_label, priority FROM \
|
||||
wire_accounts WHERE is_active"
|
||||
in
|
||||
fun (module Conn : CONN) -> Conn.collect_list get_wire_accounts ()
|
||||
fun (module Conn : CONN) ->
|
||||
let open Syntax in
|
||||
let+ l = Conn.collect_list get_wire_accounts () in
|
||||
List.map
|
||||
(fun ( payto_uri,
|
||||
conversion_url,
|
||||
debit_restrictions,
|
||||
credit_restrictions,
|
||||
master_sig,
|
||||
bank_label,
|
||||
priority ) ->
|
||||
ExchangeWireAccount.
|
||||
{
|
||||
payto_uri;
|
||||
conversion_url;
|
||||
debit_restrictions;
|
||||
credit_restrictions;
|
||||
master_sig;
|
||||
bank_label;
|
||||
priority;
|
||||
})
|
||||
l
|
||||
|
||||
let get_wire_fees =
|
||||
let get_wire_fees =
|
||||
let master_sig = Bin_sig.MasterWireFee.caqti in
|
||||
Caqti_type.(string ->* t5 amount amount time time master_sig)
|
||||
"SELECT wire_fee, closing_fee, start_date, end_date, master_sig FROM \
|
||||
wire_fee WHERE wire_method=$1"
|
||||
in
|
||||
fun (module Conn : CONN) ~wire_method ->
|
||||
let open Syntax in
|
||||
let+ l = Conn.collect_list get_wire_fees wire_method in
|
||||
List.map
|
||||
(fun (wire_fee, closing_fee, start_date, end_date, sig_) ->
|
||||
AggregateTransferFee.
|
||||
{ wire_fee; closing_fee; start_date; end_date; sig_ })
|
||||
l
|
||||
|
||||
let get_global_fees =
|
||||
let get_global_fees =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue