···11+open Mist
22+13type commit =
24 { did: string
35 ; version: int (* always 3 *)
···3638type signing_key = P256 of bytes | K256 of bytes
37393840module Make (Store : Storage.Writable_blockstore) = struct
3939- type store = Store.t
4040-4141- let read_commit store cid : (signed_commit, string) Lwt_result.t =
4242- let%lwt bytes = Store.get_bytes store cid in
4343- match bytes with
4444- | Some b ->
4545- b |> Dag_cbor.decode_to_yojson |> signed_commit_of_yojson |> Lwt.return
4646- | None ->
4747- Lwt.return_error ("commit not found in blockstore: " ^ Cid.to_string cid)
4141+ type t = {store: Store.t; key: signing_key}
4842end
+18-7
mist/test/test_mst.ml
···11open Mist
22open Lwt.Infix
33module MemMst = Mst.Make (Storage.Memory_blockstore)
44-module MemRepo = Repository.Make (Storage.Memory_blockstore)
54module StringMap = Dag_cbor.StringMap
6576let cid_of_string_exn s =
···826825 in
827826 let store = Storage.Memory_blockstore.create ~blocks:bm () in
828827 let%lwt commit =
829829- MemRepo.read_commit store root
830830- >|= function Ok commit -> commit | Error msg -> failwith msg
828828+ match%lwt Storage.Memory_blockstore.get_bytes store root with
829829+ | Some b -> (
830830+ match Dag_cbor.decode b with
831831+ | `Map commit ->
832832+ Lwt.return commit
833833+ | _ ->
834834+ failwith "non-object commit" )
835835+ | None ->
836836+ failwith "root not found in blockstore"
831837 in
832832- let mst = MemMst.create store commit.data in
838838+ let mst =
839839+ MemMst.create store
840840+ ( match StringMap.find "data" commit with
841841+ | `Link cid ->
842842+ cid
843843+ | _ ->
844844+ failwith "non-cid data in commit" )
845845+ in
833846 Lwt.return (commit, mst)
834847 in
835848 let%lwt ic = Lwt_io.open_file ~mode:Lwt_io.input "sample.car" in
···837850 let%lwt () = Lwt_io.close ic in
838851 let%lwt commit, mst = mst_of_car_bytes car in
839852 let mst_stream = MemMst.to_blocks_stream mst in
840840- let commit_bytes =
841841- Dag_cbor.encode_yojson (Repository.signed_commit_to_yojson commit)
842842- in
853853+ let commit_bytes = Dag_cbor.encode (`Map commit) in
843854 let commit_cid = Cid.create Dcbor commit_bytes in
844855 let%lwt car' =
845856 Car.blocks_to_car (Some commit_cid)