···136136 ; mutable block_map: Cid.t StringMap.t option
137137 ; mutable commit: Cid.t option }
138138139139+let load did : t Lwt.t =
140140+ let%lwt actor_store_conn =
141141+ Util.connect_sqlite Util.Constants.pegasus_db_location
142142+ in
143143+ let%lwt db = Util.connect_sqlite (Util.Constants.user_db_location did) in
144144+ let%lwt {signing_key; _} =
145145+ match%lwt Actor_store.get_actor_by_identifier did actor_store_conn with
146146+ | Some actor ->
147147+ Lwt.return actor
148148+ | None ->
149149+ failwith ("failed to retrieve actor for " ^ did)
150150+ in
151151+ let key =
152152+ match Kleidos.parse_multikey_str signing_key with
153153+ | key, (module M) when M.name = "K256" ->
154154+ K256 key
155155+ | key, (module M) when M.name = "P256" ->
156156+ P256 key
157157+ | _ ->
158158+ failwith "unsupported key type"
159159+ in
160160+ let%lwt commit =
161161+ match%lwt User_store.get_commit db with
162162+ | Some (cid, _) ->
163163+ Lwt.return_some cid
164164+ | None ->
165165+ Lwt.return_none
166166+ in
167167+ Lwt.return {key; did; db; block_map= None; commit}
168168+139169let get_map t : Cid.t StringMap.t Lwt.t =
140170 let%lwt root, commit =
141171 match%lwt User_store.get_commit t.db with
+17
pegasus/lib/util.ml
···22 exception XrpcError of (string * string)
33end
4455+module Constants = struct
66+ let pegasus_db_location =
77+ Env.load ()
88+ |> fun {database_dir; _} -> Filename.concat database_dir "pegasus.db"
99+1010+ let user_db_location did =
1111+ let rec last (lst : 'a list) : 'a option =
1212+ match lst with [] -> None | [x] -> Some x | _ :: xs -> last xs
1313+ in
1414+ let filename =
1515+ did |> String.split_on_char ':' |> last |> Option.get
1616+ |> Printf.sprintf "%s.db"
1717+ in
1818+ Env.load ()
1919+ |> fun {database_dir; _} -> Filename.concat database_dir filename
2020+end
2121+522module Syntax = struct
623 (* unwraps an Lwt result, raising an exception if there's an error *)
724 let ( let$! ) m f =