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 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
|
||||
|
||||
module Exchange_secmod_rsa = struct
|
||||
|
|
|
|||
|
|
@ -19,6 +19,10 @@ let db_connection : (env, Caqti_miou.connection) Vif.Device.device =
|
|||
| Ok () -> conn)
|
||||
|
||||
module Secmod_signkey = struct
|
||||
(* TODO
|
||||
- key rotation
|
||||
- how many signkey to use?
|
||||
we just use 1 for now *)
|
||||
type t = {
|
||||
sm_key: Signkey.t;
|
||||
keys: Signkey.t list;
|
||||
|
|
@ -39,15 +43,18 @@ module Secmod_signkey = struct
|
|||
Fmt.error_msg "secmod_signkey load error: invalid store state."
|
||||
in
|
||||
let* sm_key = Data_file.load_signkey conn Fpath.(dir / "sm_key") in
|
||||
let* key_0 =
|
||||
let fname = Fpath.(dir / string_of_int 0) in
|
||||
Data_file.load_signkey conn fname
|
||||
let* keys =
|
||||
let l = List.init 1 (fun i -> Fpath.(dir / string_of_int i)) in
|
||||
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
|
||||
match (sm_key, key_0) with
|
||||
match (sm_key, keys) with
|
||||
| None, None -> Ok None
|
||||
| Some sm_key, Some key_0 ->
|
||||
let keys = [ key_0 ] in
|
||||
Ok (Some { sm_key; keys })
|
||||
| Some sm_key, Some keys -> Ok (Some { sm_key; keys })
|
||||
| _, _ -> error_invalid_state
|
||||
|
||||
let generate_fresh_secmod_data () =
|
||||
|
|
@ -94,7 +101,7 @@ module Secmod_denom = struct
|
|||
let* keys =
|
||||
let* l =
|
||||
let open Config.Coin in
|
||||
list_map
|
||||
Syntax.list_map
|
||||
(fun coin ->
|
||||
let section_name = coin.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)
|
||||
all_coins
|
||||
in
|
||||
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_invalid_state
|
||||
match Syntax.opt_list l with
|
||||
| Error () -> error_invalid_state
|
||||
| Ok opt -> Ok opt
|
||||
in
|
||||
match (sm_key, keys) with
|
||||
| None, None -> Ok None
|
||||
|
|
|
|||
|
|
@ -38,3 +38,11 @@ let list_fold_left f acc l =
|
|||
let* acc = acc in
|
||||
f acc v)
|
||||
(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