This commit is contained in:
parent
dfb0b476c0
commit
5bc1a4d987
4 changed files with 69 additions and 3 deletions
|
|
@ -70,6 +70,7 @@ module B32 = struct
|
||||||
~decode:B32.decode Caqti_type.string
|
~decode:B32.decode Caqti_type.string
|
||||||
end
|
end
|
||||||
|
|
||||||
|
(* TODO use DenominationHash directly *)
|
||||||
module HashCode : sig
|
module HashCode : sig
|
||||||
type t
|
type t
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -102,12 +102,18 @@ module Hash_32 = struct
|
||||||
let open Bin in
|
let open Bin in
|
||||||
map (bytes 32) of_octets to_octets
|
map (bytes 32) of_octets to_octets
|
||||||
|
|
||||||
|
(* hashes are not b32 encoded in the database *)
|
||||||
let caqti : t Caqti_type.t =
|
let caqti : t Caqti_type.t =
|
||||||
let open Caqti_type in
|
let open Caqti_type in
|
||||||
custom
|
custom
|
||||||
~encode:(fun v -> Ok (to_octets v))
|
~encode:(fun v -> Ok (to_octets v))
|
||||||
~decode:(fun v -> Ok (of_octets v))
|
~decode:(fun v -> Ok (of_octets v))
|
||||||
octets
|
octets
|
||||||
|
|
||||||
|
let jsont =
|
||||||
|
let dec s = Result.map of_octets (B32.decode s) in
|
||||||
|
let enc v = B32.encode (to_octets v) in
|
||||||
|
Jsont.of_of_string ~kind:"Hash 32" dec ~enc
|
||||||
end
|
end
|
||||||
|
|
||||||
module Hash_64 = struct
|
module Hash_64 = struct
|
||||||
|
|
@ -130,12 +136,18 @@ module Hash_64 = struct
|
||||||
let open Bin in
|
let open Bin in
|
||||||
map (bytes 64) of_octets to_octets
|
map (bytes 64) of_octets to_octets
|
||||||
|
|
||||||
|
(* hashes are not b32 encoded in the database *)
|
||||||
let caqti : t Caqti_type.t =
|
let caqti : t Caqti_type.t =
|
||||||
let open Caqti_type in
|
let open Caqti_type in
|
||||||
custom
|
custom
|
||||||
~encode:(fun v -> Ok (to_octets v))
|
~encode:(fun v -> Ok (to_octets v))
|
||||||
~decode:(fun v -> Ok (of_octets v))
|
~decode:(fun v -> Ok (of_octets v))
|
||||||
octets
|
octets
|
||||||
|
|
||||||
|
let jsont =
|
||||||
|
let dec s = Result.map of_octets (B32.decode s) in
|
||||||
|
let enc v = B32.encode (to_octets v) in
|
||||||
|
Jsont.of_of_string ~kind:"Hash 64" dec ~enc
|
||||||
end
|
end
|
||||||
|
|
||||||
(* Hash over string + '\0' *)
|
(* Hash over string + '\0' *)
|
||||||
|
|
|
||||||
56
src/pg.ml
56
src/pg.ml
|
|
@ -9,7 +9,9 @@
|
||||||
GNU Taler db-events?
|
GNU Taler db-events?
|
||||||
it seems caqti/pgx does not support it
|
it seems caqti/pgx does not support it
|
||||||
|
|
||||||
transaction *)
|
transaction
|
||||||
|
|
||||||
|
should check validity of signatures got from db, for /management at least *)
|
||||||
|
|
||||||
module type CONN = Caqti_miou.CONNECTION
|
module type CONN = Caqti_miou.CONNECTION
|
||||||
|
|
||||||
|
|
@ -185,7 +187,7 @@ let insert_auditor_denom_sig =
|
||||||
fun (module Conn : CONN) ~auditor_pub ~h_denom_pub ~auditor_sig ->
|
fun (module Conn : CONN) ~auditor_pub ~h_denom_pub ~auditor_sig ->
|
||||||
Conn.exec insert_auditor_denom_sig (auditor_pub, h_denom_pub, auditor_sig)
|
Conn.exec insert_auditor_denom_sig (auditor_pub, h_denom_pub, auditor_sig)
|
||||||
|
|
||||||
let get_auditors =
|
let _get_auditors =
|
||||||
let get_auditors =
|
let get_auditors =
|
||||||
Caqti_type.(unit ->* t3 eddsa_pub string string)
|
Caqti_type.(unit ->* t3 eddsa_pub string string)
|
||||||
"SELECT auditor_pub, auditor_url, auditor_name FROM auditors WHERE \
|
"SELECT auditor_pub, auditor_url, auditor_name FROM auditors WHERE \
|
||||||
|
|
@ -193,7 +195,7 @@ let get_auditors =
|
||||||
in
|
in
|
||||||
fun (module Conn : CONN) () -> Conn.collect_list get_auditors ()
|
fun (module Conn : CONN) () -> Conn.collect_list get_auditors ()
|
||||||
|
|
||||||
let get_auditor_denoms =
|
let _get_auditor_denoms =
|
||||||
let get_auditor_denoms =
|
let get_auditor_denoms =
|
||||||
let auditor_sig = Bin_sig.ExchangeKeyValidity.caqti in
|
let auditor_sig = Bin_sig.ExchangeKeyValidity.caqti in
|
||||||
Caqti_type.(unit ->* t3 eddsa_pub denomination_hash auditor_sig)
|
Caqti_type.(unit ->* t3 eddsa_pub denomination_hash auditor_sig)
|
||||||
|
|
@ -204,6 +206,54 @@ let get_auditor_denoms =
|
||||||
in
|
in
|
||||||
fun (module Conn : CONN) () -> Conn.collect_list get_auditor_denoms ()
|
fun (module Conn : CONN) () -> Conn.collect_list get_auditor_denoms ()
|
||||||
|
|
||||||
|
(* TODO maybe check that url and name are unique/same for each auditor_pub *)
|
||||||
|
let get_auditor_keys =
|
||||||
|
let get_auditor_keys =
|
||||||
|
let auditor_sig = Bin_sig.ExchangeKeyValidity.caqti in
|
||||||
|
Caqti_type.(
|
||||||
|
unit ->* t5 eddsa_pub string string denomination_hash auditor_sig)
|
||||||
|
"SELECT auditors.auditor_pub, auditors.url, auditors.name, \
|
||||||
|
denominations.denom_pub_hash, auditor_denom_sigs.auditor_sig FROM \
|
||||||
|
auditor_denom_sigs JOIN auditors USING (auditor_uuid) JOIN \
|
||||||
|
denominations USING (denominations_serial) WHERE auditors.is_active"
|
||||||
|
in
|
||||||
|
fun (module Conn : CONN) () ->
|
||||||
|
let open Syntax in
|
||||||
|
let* l = Conn.collect_list get_auditor_keys () |> unwrap_err_caqti in
|
||||||
|
let* l =
|
||||||
|
(* TODO improve DenominationHash/HashCode situation
|
||||||
|
conversion here is probably bad *)
|
||||||
|
list_map
|
||||||
|
(fun (pub, url, name, denom_pub_h, auditor_sig) ->
|
||||||
|
let denom_pub_h = Bin_type.DenominationHash.to_octets denom_pub_h in
|
||||||
|
let* denom_pub_h = HashCode.of_b32 denom_pub_h in
|
||||||
|
Ok (pub, url, name, denom_pub_h, auditor_sig))
|
||||||
|
l
|
||||||
|
in
|
||||||
|
let ht = Hashtbl.create 0xff in
|
||||||
|
List.iter
|
||||||
|
(fun (pub, url, name, denom_pub_h, auditor_sig) ->
|
||||||
|
let k = (pub, url, name) in
|
||||||
|
match Hashtbl.find_opt ht k with
|
||||||
|
| None -> Hashtbl.replace ht k [ (denom_pub_h, auditor_sig) ]
|
||||||
|
| Some l -> Hashtbl.replace ht k ((denom_pub_h, auditor_sig) :: l))
|
||||||
|
l;
|
||||||
|
let l = Hashtbl.to_seq ht |> List.of_seq in
|
||||||
|
let l =
|
||||||
|
List.map
|
||||||
|
(fun ((auditor_pub, auditor_url, auditor_name), auditor_denoms) ->
|
||||||
|
let denomination_keys =
|
||||||
|
List.map
|
||||||
|
(fun (denom_pub_h, auditor_sig) ->
|
||||||
|
AuditorDenominationKey.{ denom_pub_h; auditor_sig })
|
||||||
|
auditor_denoms
|
||||||
|
in
|
||||||
|
AuditorKeys.
|
||||||
|
{ auditor_pub; auditor_url; auditor_name; denomination_keys })
|
||||||
|
l
|
||||||
|
in
|
||||||
|
Ok l
|
||||||
|
|
||||||
let insert_wire_fee =
|
let insert_wire_fee =
|
||||||
let insert_wire_fee =
|
let insert_wire_fee =
|
||||||
let master_sig = Bin_sig.MasterWireFee.caqti in
|
let master_sig = Bin_sig.MasterWireFee.caqti in
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,9 @@ open Bin_type
|
||||||
open Api
|
open Api
|
||||||
open Caqti_type
|
open Caqti_type
|
||||||
|
|
||||||
|
(* TODO
|
||||||
|
check that we use Caqti_type.octets for binary data *)
|
||||||
|
|
||||||
let amount : Amount.t t =
|
let amount : Amount.t t =
|
||||||
let open Amount in
|
let open Amount in
|
||||||
custom
|
custom
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue