+ fix taler_amount: lookup_denomination_key
This commit is contained in:
parent
0c8ea5ba65
commit
3b5e5dba5a
3 changed files with 50 additions and 6 deletions
|
|
@ -179,6 +179,42 @@ let update_master_signatures ~db_conn ~sm_signkey ~sm_denom
|
||||||
(h_denom_pub, master_sig))
|
(h_denom_pub, master_sig))
|
||||||
|> Secmod_denom.add_master_signatures db_conn sm_denom
|
|> Secmod_denom.add_master_signatures db_conn sm_denom
|
||||||
in
|
in
|
||||||
|
let* () =
|
||||||
|
(* TODO move to test *)
|
||||||
|
Secmod_denom.get_denoms sm_denom
|
||||||
|
|> list_iter (fun denom ->
|
||||||
|
let error = Error "update_master_signatures sanity check failure" in
|
||||||
|
let* opt =
|
||||||
|
Pg.lookup_denomination_key db_conn denom.Denomination.h_pub
|
||||||
|
|> unwrap_err_caqti
|
||||||
|
in
|
||||||
|
let* ( valid_from,
|
||||||
|
_expire_withdraw,
|
||||||
|
_expire_deposit,
|
||||||
|
_expire_legal,
|
||||||
|
coin,
|
||||||
|
_fee_withdraw,
|
||||||
|
_fee_deposit,
|
||||||
|
_fee_refresh,
|
||||||
|
fee_refund,
|
||||||
|
age_mask ) =
|
||||||
|
match opt with None -> error | Some v -> Ok v
|
||||||
|
in
|
||||||
|
let check = function false -> error | true -> Ok () in
|
||||||
|
(* TODO time *)
|
||||||
|
let timestamp_equal a b =
|
||||||
|
let timestamp_to_int64 = function
|
||||||
|
| None -> None
|
||||||
|
| Some v -> v |> Ptime.to_float_s |> Int64.of_float |> Option.some
|
||||||
|
in
|
||||||
|
timestamp_to_int64 a = timestamp_to_int64 b
|
||||||
|
in
|
||||||
|
let* () = check (timestamp_equal valid_from denom.stamp_start) in
|
||||||
|
let* () = check (coin = denom.value) in
|
||||||
|
let* () = check (fee_refund = denom.fee_refund) in
|
||||||
|
let* () = check (age_mask = denom.age_mask) in
|
||||||
|
Ok ())
|
||||||
|
in
|
||||||
Ok ()
|
Ok ()
|
||||||
|
|
||||||
(* --- *)
|
(* --- *)
|
||||||
|
|
@ -200,7 +236,10 @@ let respond_with_ok_json content req =
|
||||||
|
|
||||||
let respond_with_res res req =
|
let respond_with_res res req =
|
||||||
match res with
|
match res with
|
||||||
| Error err -> respond_with_plain_text_error err req
|
| Error err ->
|
||||||
|
Logs.err (fun m -> m "%s." err);
|
||||||
|
let err = Fmt.str "%s@." err in
|
||||||
|
respond_with_plain_text_error err req
|
||||||
| Ok content -> respond_with_ok_json content req
|
| Ok content -> respond_with_ok_json content req
|
||||||
|
|
||||||
let keys_get req server _env =
|
let keys_get req server _env =
|
||||||
|
|
|
||||||
12
src/pg.ml
12
src/pg.ml
|
|
@ -1,10 +1,12 @@
|
||||||
|
(* TODO
|
||||||
|
how to fix postgres/caqti tuple type?
|
||||||
|
need to add boilerplate in each query for amounts *)
|
||||||
|
|
||||||
open Crypto
|
open Crypto
|
||||||
|
|
||||||
module Caqti_type = struct
|
module Caqti_type = struct
|
||||||
include Caqti_type
|
include Caqti_type
|
||||||
|
|
||||||
(* TODO add a dune stanza like for prelude:
|
|
||||||
"(flags (:standard -open Prelude))" *)
|
|
||||||
(* we want to use int64 timestamps,
|
(* we want to use int64 timestamps,
|
||||||
not postgresql built-in timestamp type *)
|
not postgresql built-in timestamp type *)
|
||||||
let ptime : Ptime.t option t = Timestamp.caqti
|
let ptime : Ptime.t option t = Timestamp.caqti
|
||||||
|
|
@ -110,8 +112,10 @@ let lookup_denomination_key =
|
||||||
Caqti_type.(
|
Caqti_type.(
|
||||||
denomination_hash
|
denomination_hash
|
||||||
->? t10 time time time time amount amount amount amount amount age_mask)
|
->? t10 time time time time amount amount amount amount amount age_mask)
|
||||||
"SELECT valid_from, expire_withdraw, expire_deposit, expire_legal, coin, \
|
"SELECT valid_from, expire_withdraw, expire_deposit, expire_legal, \
|
||||||
fee_withdraw, fee_deposit, fee_refresh, fee_refund, age_mask FROM \
|
(coin).val, (coin).frac, (fee_withdraw).val, (fee_withdraw).frac, \
|
||||||
|
(fee_deposit).val, (fee_deposit).frac, (fee_refresh).val, \
|
||||||
|
(fee_refresh).frac, (fee_refund).val, (fee_refund).frac, age_mask FROM \
|
||||||
denominations WHERE denom_pub_hash=$1"
|
denominations WHERE denom_pub_hash=$1"
|
||||||
in
|
in
|
||||||
fun (module Conn : CONN) (h_denom_pub : DenominationHash.t) ->
|
fun (module Conn : CONN) (h_denom_pub : DenominationHash.t) ->
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
(* TODO time
|
(* TODO time
|
||||||
not sure about this *)
|
uhuh!
|
||||||
|
need to be int64 for binary/pg round trip *)
|
||||||
|
|
||||||
type t = Ptime.t option
|
type t = Ptime.t option
|
||||||
type span = Ptime.Span.t option
|
type span = Ptime.Span.t option
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue