···001type commit =
2 { did: string
3 ; version: int (* always 3 *)
···36type signing_key = P256 of bytes | K256 of bytes
3738module Make (Store : Storage.Writable_blockstore) = struct
39- type store = Store.t
40-41- let read_commit store cid : (signed_commit, string) Lwt_result.t =
42- let%lwt bytes = Store.get_bytes store cid in
43- match bytes with
44- | Some b ->
45- b |> Dag_cbor.decode_to_yojson |> signed_commit_of_yojson |> Lwt.return
46- | None ->
47- Lwt.return_error ("commit not found in blockstore: " ^ Cid.to_string cid)
48end
···1+open Mist
2+3type commit =
4 { did: string
5 ; version: int (* always 3 *)
···38type signing_key = P256 of bytes | K256 of bytes
3940module Make (Store : Storage.Writable_blockstore) = struct
41+ type t = {store: Store.t; key: signing_key}
0000000042end
+18-7
mist/test/test_mst.ml
···1open Mist
2open Lwt.Infix
3module MemMst = Mst.Make (Storage.Memory_blockstore)
4-module MemRepo = Repository.Make (Storage.Memory_blockstore)
5module StringMap = Dag_cbor.StringMap
67let cid_of_string_exn s =
···826 in
827 let store = Storage.Memory_blockstore.create ~blocks:bm () in
828 let%lwt commit =
829- MemRepo.read_commit store root
830- >|= function Ok commit -> commit | Error msg -> failwith msg
0000000831 in
832- let mst = MemMst.create store commit.data in
0000000833 Lwt.return (commit, mst)
834 in
835 let%lwt ic = Lwt_io.open_file ~mode:Lwt_io.input "sample.car" in
···837 let%lwt () = Lwt_io.close ic in
838 let%lwt commit, mst = mst_of_car_bytes car in
839 let mst_stream = MemMst.to_blocks_stream mst in
840- let commit_bytes =
841- Dag_cbor.encode_yojson (Repository.signed_commit_to_yojson commit)
842- in
843 let commit_cid = Cid.create Dcbor commit_bytes in
844 let%lwt car' =
845 Car.blocks_to_car (Some commit_cid)
···1open Mist
2open Lwt.Infix
3module MemMst = Mst.Make (Storage.Memory_blockstore)
04module StringMap = Dag_cbor.StringMap
56let cid_of_string_exn s =
···825 in
826 let store = Storage.Memory_blockstore.create ~blocks:bm () in
827 let%lwt commit =
828+ match%lwt Storage.Memory_blockstore.get_bytes store root with
829+ | Some b -> (
830+ match Dag_cbor.decode b with
831+ | `Map commit ->
832+ Lwt.return commit
833+ | _ ->
834+ failwith "non-object commit" )
835+ | None ->
836+ failwith "root not found in blockstore"
837 in
838+ let mst =
839+ MemMst.create store
840+ ( match StringMap.find "data" commit with
841+ | `Link cid ->
842+ cid
843+ | _ ->
844+ failwith "non-cid data in commit" )
845+ in
846 Lwt.return (commit, mst)
847 in
848 let%lwt ic = Lwt_io.open_file ~mode:Lwt_io.input "sample.car" in
···850 let%lwt () = Lwt_io.close ic in
851 let%lwt commit, mst = mst_of_car_bytes car in
852 let mst_stream = MemMst.to_blocks_stream mst in
853+ let commit_bytes = Dag_cbor.encode (`Map commit) in
00854 let commit_cid = Cid.create Dcbor commit_bytes in
855 let%lwt car' =
856 Car.blocks_to_car (Some commit_cid)