working database~~
This commit is contained in:
parent
0c5622324c
commit
056c111d88
5 changed files with 99 additions and 92 deletions
120
src/pg.ml
120
src/pg.ml
|
|
@ -1,83 +1,77 @@
|
|||
(* TODO be sure to not use postgres ptime
|
||||
add a dune stanza like for prelude:
|
||||
"(flags (:standard -open Prelude))" *)
|
||||
open Crypto
|
||||
|
||||
module Caqti_type = struct
|
||||
include Caqti_type
|
||||
|
||||
(* TODO add a dune stanza like for prelude:
|
||||
"(flags (:standard -open Prelude))" *)
|
||||
(* we want to use int64 timestamps,
|
||||
not postgresql built-in timestamp type *)
|
||||
let ptime : Ptime.t Caqti_type.t =
|
||||
let ptime : Ptime.t t =
|
||||
let encode i = Ok (Util.ptime_to_int64 i) in
|
||||
let decode = Util.ptime_of_int64 in
|
||||
Caqti_type.custom ~encode ~decode Caqti_type.(int64)
|
||||
custom ~encode ~decode int64
|
||||
|
||||
let amount : Amount.t t =
|
||||
let open Amount in
|
||||
custom
|
||||
~encode:(fun amount -> Ok (amount.value, amount.fraction))
|
||||
~decode:(fun (value, fraction) ->
|
||||
Amount.make ~sign:None ~currency:Config.currency ~value ~fraction)
|
||||
(t2 int64 int32)
|
||||
|
||||
let eddsa_public : EddsaPublicKey.t t =
|
||||
let open EddsaPublicKey in
|
||||
custom
|
||||
~encode:(fun v -> Ok (to_octets v))
|
||||
~decode:(fun v -> Ok (of_octets v))
|
||||
octets
|
||||
|
||||
let eddsa_signature : EddsaSignature.t t =
|
||||
let open EddsaSignature in
|
||||
custom
|
||||
~encode:(fun v -> Ok (to_octets v))
|
||||
~decode:(fun s -> Ok (of_octets s))
|
||||
octets
|
||||
|
||||
include Caqti_request.Infix
|
||||
end
|
||||
|
||||
open Crypto
|
||||
(*open Bin_type*)
|
||||
|
||||
let amount_t : Amount.t Caqti_type.t =
|
||||
let open Amount in
|
||||
Caqti_type.custom
|
||||
~encode:(fun amount -> Ok (amount.value, amount.fraction))
|
||||
~decode:(fun (value, fraction) ->
|
||||
Amount.make ~sign:None ~currency:Config.currency ~value ~fraction)
|
||||
Caqti_type.(t2 int64 int32)
|
||||
|
||||
let eddsa_signature_t : EddsaSignature.t Caqti_type.t =
|
||||
let open EddsaSignature in
|
||||
Caqti_type.custom
|
||||
~encode:(fun master_sig -> Ok (to_octets master_sig))
|
||||
~decode:(fun s -> Ok (of_octets s))
|
||||
Caqti_type.octets
|
||||
|
||||
(* WIP: minimum db functions for basic /management *)
|
||||
|
||||
let pg_todo () = assert false
|
||||
|
||||
open Caqti_request.Infix
|
||||
|
||||
(* signkey *)
|
||||
(* todo:
|
||||
- what type to use for TALER_ExchangePublicKeyP + TALER_EXCHANGEDB_SignkeyMetaData
|
||||
-> I think it could be something = to FutureSignKey.t
|
||||
- master signature: over smthing? *)
|
||||
let activate_signing_key _cls (exchange_public_key : Signkey.t) =
|
||||
(*let open Bin_type in*)
|
||||
let _exchange_pub = EddsaPublicKey.(to_octets exchange_public_key.pub) in
|
||||
let _master_sig =
|
||||
exchange_public_key.master_sig |> Option.get
|
||||
(*|> EddsaSignature.to_octets*)
|
||||
let preflight =
|
||||
let l =
|
||||
List.map
|
||||
Caqti_type.(unit ->. unit)
|
||||
[
|
||||
"SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL \
|
||||
SERIALIZABLE;"; "SET enable_sort=OFF;"; "SET enable_seqscan=OFF;";
|
||||
"SET enable_mergejoin=OFF;"; "SET search_path TO exchange;";
|
||||
]
|
||||
in
|
||||
let _insert_signkey =
|
||||
Caqti_type.(t5 string ptime ptime ptime string ->! int)
|
||||
fun (module Conn : Caqti_miou.CONNECTION) ->
|
||||
Syntax.list_iter (fun p -> Conn.exec p ()) l
|
||||
|
||||
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);"
|
||||
in
|
||||
pg_todo ()
|
||||
fun (module Conn : Caqti_miou.CONNECTION) exchange_signkey ->
|
||||
let Signkey.
|
||||
{ pub; stamp_start; stamp_expire; stamp_end; master_sig= _; sign= _ }
|
||||
=
|
||||
exchange_signkey
|
||||
in
|
||||
(*let master_sig = master_sig |> Option.get in*)
|
||||
let master_sig = EddsaSignature.of_octets (String.make 64 'x') in
|
||||
Conn.exec insert_signkey
|
||||
(pub, stamp_start, stamp_expire, stamp_end, master_sig)
|
||||
|
||||
(*
|
||||
|
||||
enum GNUNET_DB_QueryStatus
|
||||
TEH_PG_activate_signing_key (
|
||||
void *cls,
|
||||
const struct TALER_ExchangePublicKeyP *exchange_pub,
|
||||
const struct TALER_EXCHANGEDB_SignkeyMetaData *meta,
|
||||
const struct TALER_MasterSignatureP *master_sig)
|
||||
{
|
||||
struct PostgresClosure *pg = cls;
|
||||
struct GNUNET_PQ_QueryParam iparams[] = {
|
||||
GNUNET_PQ_query_param_auto_from_type (exchange_pub),
|
||||
GNUNET_PQ_query_param_timestamp (&meta->start),
|
||||
GNUNET_PQ_query_param_timestamp (&meta->expire_sign),
|
||||
GNUNET_PQ_query_param_timestamp (&meta->expire_legal),
|
||||
GNUNET_PQ_query_param_auto_from_type (master_sig),
|
||||
GNUNET_PQ_query_param_end
|
||||
};
|
||||
}
|
||||
*)
|
||||
(* WIP: minimum db functions for basic /management *)
|
||||
|
||||
(* ----- *)
|
||||
|
||||
let pg_todo () = assert false
|
||||
let lookup_signing_key = pg_todo
|
||||
let iterate_active_signkeys = pg_todo
|
||||
let insert_signkey_revocation = pg_todo
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue