This commit is contained in:
swrup 2025-11-23 15:37:05 +01:00
parent 056c111d88
commit 522e205b19
4 changed files with 122 additions and 29 deletions

105
src/pg.ml
View file

@ -20,6 +20,15 @@ module Caqti_type = struct
Amount.make ~sign:None ~currency:Config.currency ~value ~fraction)
(t2 int64 int32)
let age_mask : int t = Caqti_type.int
let rsa_public : RsaPublicKey.t t =
let open RsaPublicKey in
custom
~encode:(fun v -> Ok (to_octets v))
~decode:(fun v -> Ok (of_octets v))
octets
let eddsa_public : EddsaPublicKey.t t =
let open EddsaPublicKey in
custom
@ -34,9 +43,30 @@ module Caqti_type = struct
~decode:(fun s -> Ok (of_octets s))
octets
include struct
(* alias for hash *)
open Bin_type
let fullpayto_hash = FullPaytoHash.caqti
let nomalizaedpayto_hash = NormalizedPaytoHash.caqti
let denomination_hash = DenominationHash.caqti
let privatecontract_hash = PrivateContractHash.caqti
let extensionspolicy_hash = ExtensionsPolicyHash.caqti
let merchantwire_hash = MerchantWireHash.caqti
let agecommitment_hash = AgeCommitmentHash.caqti
let blindedcoin_hash = BlindedCoinHash.caqti
let coinpub_hash = CoinPubHash.caqti
let outputcommitment_hash = OutputCommitmentHash.caqti
let planchets_hash = HashPlanchetsP.caqti
end
include Caqti_request.Infix
end
module type CONN = Caqti_miou.CONNECTION
open Bin_type
let preflight =
let l =
List.map
@ -50,13 +80,82 @@ let preflight =
fun (module Conn : Caqti_miou.CONNECTION) ->
Syntax.list_iter (fun p -> Conn.exec p ()) l
let _lookup_signing_key =
let lookup_signing_key =
Caqti_type.(eddsa_public ->? t3 ptime ptime ptime)
"SELECT valid_from, expire_sign, expire_legal FROM exchange_sign_keys \
WHERE exchange_pub=$1"
in
fun (module Conn : CONN) (exchange_pub : EddsaPublicKey.t) ->
Conn.find_opt lookup_signing_key exchange_pub
let _lookup_denomination_key =
let lookup_denomination_key =
Caqti_type.(
denomination_hash
->? t10 ptime ptime ptime ptime amount amount amount amount amount
age_mask)
"SELECT valid_from, expire_withdraw, expire_deposit, expire_legal, coin, \
fee_withdraw, fee_deposit, fee_refresh, fee_refund, age_mask FROM \
denominations WHERE denom_pub_hash=$1"
in
fun (module Conn : CONN) (h_denom_pub : DenominationHash.t) ->
Conn.find_opt lookup_denomination_key h_denom_pub
let _add_denomination_key =
let denomination_insert =
Caqti_type.(
t12 denomination_hash rsa_public eddsa_signature ptime ptime ptime ptime
amount amount amount amount (t2 amount age_mask)
->. unit)
"INSERT INTO denominations (denom_pub_hash, denom_pub, master_sig, \
valid_from, expire_withdraw, expire_deposit, expire_legal, coin, \
fee_withdraw, fee_deposit, fee_refresh, fee_refund, age_mask) VALUES \
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)"
in
fun (module Conn : CONN) denom ->
let Denomination.
{
pub;
section_name= _;
value;
stamp_start;
stamp_expire_withdraw;
stamp_expire_deposit;
stamp_expire_legal;
fee_withdraw;
fee_deposit;
fee_refresh;
fee_refund;
age_mask;
h_pub;
sign= _;
master_sig;
} =
denom
in
let master_sig = master_sig |> Option.get in
Conn.exec denomination_insert
( h_pub,
pub,
master_sig,
stamp_start,
stamp_expire_withdraw,
stamp_expire_deposit,
stamp_expire_legal,
value,
fee_withdraw,
fee_deposit,
fee_refresh,
(fee_refund, age_mask) )
let activate_signing_key =
let insert_signkey =
Caqti_type.(t5 eddsa_public ptime ptime ptime eddsa_signature ->. unit)
"INSERT INTO exchange_sign_keys (exchange_pub, valid_from, expire_sign, \
expire_legal, master_sig) VALUES ($1, $2, $3, $4, $5);"
expire_legal, master_sig) VALUES ($1, $2, $3, $4, $5)"
in
fun (module Conn : Caqti_miou.CONNECTION) exchange_signkey ->
fun (module Conn : CONN) exchange_signkey ->
let Signkey.
{ pub; stamp_start; stamp_expire; stamp_end; master_sig= _; sign= _ }
=
@ -67,8 +166,6 @@ let activate_signing_key =
Conn.exec insert_signkey
(pub, stamp_start, stamp_expire, stamp_end, master_sig)
(* WIP: minimum db functions for basic /management *)
(* ----- *)
let pg_todo () = assert false