fix exchange_sig: correctly group and order denominations
This commit is contained in:
parent
72b0c3012a
commit
c8863e1a95
5 changed files with 141 additions and 104 deletions
|
|
@ -15,3 +15,98 @@ type t = {
|
|||
h_pub: denom_hash;
|
||||
master_sig: Signatures.DenominationKeyValidity.t;
|
||||
}
|
||||
|
||||
let make_denom_group_sorted denominations =
|
||||
let open Syntax in
|
||||
let ht = Hashtbl.create 0xff in
|
||||
List.iter
|
||||
(fun coin ->
|
||||
let open Config.Coin in
|
||||
assert (coin.cipher = `RSA);
|
||||
let k =
|
||||
( coin.value,
|
||||
coin.fee_withdraw,
|
||||
coin.fee_deposit,
|
||||
coin.fee_refresh,
|
||||
coin.fee_refund )
|
||||
in
|
||||
let v = [] in
|
||||
Hashtbl.replace ht k v)
|
||||
Config.Coin.all_coins;
|
||||
let+ () =
|
||||
list_iter
|
||||
(fun {
|
||||
pub;
|
||||
value;
|
||||
stamp_start;
|
||||
stamp_expire_withdraw;
|
||||
stamp_expire_deposit;
|
||||
stamp_expire_legal;
|
||||
fee_withdraw;
|
||||
fee_deposit;
|
||||
fee_refresh;
|
||||
fee_refund;
|
||||
age_mask= _;
|
||||
h_pub= _;
|
||||
master_sig;
|
||||
} ->
|
||||
let k = (value, fee_withdraw, fee_deposit, fee_refresh, fee_refund) in
|
||||
let v =
|
||||
Api.RsaDenom.
|
||||
{
|
||||
rsa_pub= pub;
|
||||
master_sig;
|
||||
stamp_start;
|
||||
stamp_expire_withdraw;
|
||||
stamp_expire_deposit;
|
||||
stamp_expire_legal;
|
||||
lost= None;
|
||||
}
|
||||
in
|
||||
let+ l =
|
||||
match Hashtbl.find_opt ht k with
|
||||
| None ->
|
||||
Error "denomination does not match any coin in configuration"
|
||||
| Some l -> Ok l
|
||||
in
|
||||
Hashtbl.replace ht k (v :: l))
|
||||
denominations
|
||||
in
|
||||
|
||||
(* ! important for /keys .exchange_sig
|
||||
each group must be ordered in _reverse_ chronological order
|
||||
order of groups to compute hash, must be the same as the order
|
||||
in /keys .denominations *)
|
||||
let open Api in
|
||||
let open DenomGroup in
|
||||
let open RsaDenomGroup in
|
||||
let open RsaDenom in
|
||||
let cmp_denom b a = Timestamp.compare a.stamp_start b.stamp_start in
|
||||
let cmp_group =
|
||||
let cmp_amount a b =
|
||||
let open Amount in
|
||||
match Int64.unsigned_compare a.value b.value with
|
||||
| 0 -> Int32.unsigned_compare a.fraction b.fraction
|
||||
| n -> n
|
||||
in
|
||||
fun (Rsa a) (Rsa b) -> cmp_amount a.value b.value
|
||||
in
|
||||
let l =
|
||||
Hashtbl.to_seq ht
|
||||
|> List.of_seq
|
||||
|> List.map
|
||||
(fun
|
||||
((value, fee_withdraw, fee_deposit, fee_refresh, fee_refund), denoms)
|
||||
->
|
||||
Rsa
|
||||
{
|
||||
denoms= List.sort cmp_denom denoms;
|
||||
value;
|
||||
fee_withdraw;
|
||||
fee_deposit;
|
||||
fee_refresh;
|
||||
fee_refund;
|
||||
})
|
||||
|> List.sort cmp_group
|
||||
in
|
||||
l
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue