This commit is contained in:
parent
56c00f9c9a
commit
4893fdbe20
3 changed files with 26 additions and 25 deletions
|
|
@ -175,17 +175,6 @@ module Coin = struct
|
||||||
}
|
}
|
||||||
|
|
||||||
let all_coins = List.map parse_coin coin_sections
|
let all_coins = List.map parse_coin coin_sections
|
||||||
|
|
||||||
let get_coin name =
|
|
||||||
match List.find_opt (fun v -> v.section_name = name) all_coins with
|
|
||||||
| None ->
|
|
||||||
fail_with
|
|
||||||
(Fmt.str "section `[coin_%s]` not found, coin `%s` is not defined"
|
|
||||||
name name)
|
|
||||||
| Some v -> v
|
|
||||||
|
|
||||||
let kudo_1 = get_coin "kudo_1"
|
|
||||||
let kudo_2 = get_coin "kudo_2"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Exchange_secmod_rsa = struct
|
module Exchange_secmod_rsa = struct
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,10 @@ let db_connection : (env, Caqti_miou.connection) Vif.Device.device =
|
||||||
| Ok () -> conn)
|
| Ok () -> conn)
|
||||||
|
|
||||||
module Secmod_signkey = struct
|
module Secmod_signkey = struct
|
||||||
|
(* TODO
|
||||||
|
- key rotation
|
||||||
|
- how many signkey to use?
|
||||||
|
we just use 1 for now *)
|
||||||
type t = {
|
type t = {
|
||||||
sm_key: Signkey.t;
|
sm_key: Signkey.t;
|
||||||
keys: Signkey.t list;
|
keys: Signkey.t list;
|
||||||
|
|
@ -39,15 +43,18 @@ module Secmod_signkey = struct
|
||||||
Fmt.error_msg "secmod_signkey load error: invalid store state."
|
Fmt.error_msg "secmod_signkey load error: invalid store state."
|
||||||
in
|
in
|
||||||
let* sm_key = Data_file.load_signkey conn Fpath.(dir / "sm_key") in
|
let* sm_key = Data_file.load_signkey conn Fpath.(dir / "sm_key") in
|
||||||
let* key_0 =
|
let* keys =
|
||||||
let fname = Fpath.(dir / string_of_int 0) in
|
let l = List.init 1 (fun i -> Fpath.(dir / string_of_int i)) in
|
||||||
Data_file.load_signkey conn fname
|
let* l =
|
||||||
|
Syntax.list_map (fun fname -> Data_file.load_signkey conn fname) l
|
||||||
|
in
|
||||||
|
match Syntax.opt_list l with
|
||||||
|
| Error () -> error_invalid_state
|
||||||
|
| Ok opt -> Ok opt
|
||||||
in
|
in
|
||||||
match (sm_key, key_0) with
|
match (sm_key, keys) with
|
||||||
| None, None -> Ok None
|
| None, None -> Ok None
|
||||||
| Some sm_key, Some key_0 ->
|
| Some sm_key, Some keys -> Ok (Some { sm_key; keys })
|
||||||
let keys = [ key_0 ] in
|
|
||||||
Ok (Some { sm_key; keys })
|
|
||||||
| _, _ -> error_invalid_state
|
| _, _ -> error_invalid_state
|
||||||
|
|
||||||
let generate_fresh_secmod_data () =
|
let generate_fresh_secmod_data () =
|
||||||
|
|
@ -94,7 +101,7 @@ module Secmod_denom = struct
|
||||||
let* keys =
|
let* keys =
|
||||||
let* l =
|
let* l =
|
||||||
let open Config.Coin in
|
let open Config.Coin in
|
||||||
list_map
|
Syntax.list_map
|
||||||
(fun coin ->
|
(fun coin ->
|
||||||
let section_name = coin.section_name in
|
let section_name = coin.section_name in
|
||||||
let fname = Fpath.(dir / section_name) in
|
let fname = Fpath.(dir / section_name) in
|
||||||
|
|
@ -102,12 +109,9 @@ module Secmod_denom = struct
|
||||||
Data_file.load_denom conn ~section_name fname)
|
Data_file.load_denom conn ~section_name fname)
|
||||||
all_coins
|
all_coins
|
||||||
in
|
in
|
||||||
match (List.for_all Option.is_none l, List.for_all Option.is_some l) with
|
match Syntax.opt_list l with
|
||||||
| _, true ->
|
| Error () -> error_invalid_state
|
||||||
let l = List.map Option.get l in
|
| Ok opt -> Ok opt
|
||||||
Ok (Some l)
|
|
||||||
| true, _ -> Ok None
|
|
||||||
| _, _ -> error_invalid_state
|
|
||||||
in
|
in
|
||||||
match (sm_key, keys) with
|
match (sm_key, keys) with
|
||||||
| None, None -> Ok None
|
| None, None -> Ok None
|
||||||
|
|
|
||||||
|
|
@ -38,3 +38,11 @@ let list_fold_left f acc l =
|
||||||
let* acc = acc in
|
let* acc = acc in
|
||||||
f acc v)
|
f acc v)
|
||||||
(Ok acc) l
|
(Ok acc) l
|
||||||
|
|
||||||
|
let opt_list l =
|
||||||
|
match (List.for_all Option.is_none l, List.for_all Option.is_some l) with
|
||||||
|
| _, true ->
|
||||||
|
let l = List.map Option.get l in
|
||||||
|
Ok (Some l)
|
||||||
|
| true, _ -> Ok None
|
||||||
|
| _, _ -> Error ()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue