atproto libraries implementation in ocaml
1(* Debug script to compare MST encoding *)
2open Atproto_mst
3open Atproto_ipld
4
5let leaf_value =
6 match
7 Cid.of_string "bafyreie5cvv4h45feadgeuwhbcutmh6t2ceseocckahdoe6uat64zmz454"
8 with
9 | Ok cid -> cid
10 | Error _ -> failwith "Invalid CID"
11
12let keys =
13 [
14 "A0/374913"; "B1/986427"; "C0/451630"; "E0/670489"; "F1/085263"; "G0/765327";
15 ]
16
17let () =
18 Printf.printf "=== MST Debug ===\n\n";
19
20 (* Print key heights *)
21 Printf.printf "Key heights:\n";
22 List.iter
23 (fun k -> Printf.printf " %-15s -> height %d\n" k (key_height k))
24 keys;
25
26 let store = Memory_blockstore.create () in
27 let module M = Make (Memory_blockstore) in
28 (* Build MST *)
29 let entries = List.map (fun k -> (k, leaf_value)) keys in
30 let root = M.of_entries store entries in
31
32 Printf.printf "\nRoot CID: %s\n" (Cid.to_string root);
33 Printf.printf
34 "Expected: bafyreicraprx2xwnico4tuqir3ozsxpz46qkcpox3obf5bagicqwurghpy\n";
35
36 (* Dump the encoded node *)
37 let blocks = Memory_blockstore.blocks store in
38 Printf.printf "\n%d blocks in store:\n" (List.length blocks);
39 List.iter
40 (fun (cid, data) ->
41 Printf.printf "\nCID: %s\n" (Cid.to_string cid);
42 Printf.printf " Raw bytes (%d): " (String.length data);
43 String.iter (fun c -> Printf.printf "%02x" (Char.code c)) data;
44 Printf.printf "\n";
45 match decode_node_raw data with
46 | Ok node ->
47 Printf.printf " Left: %s\n"
48 (match node.l with Some c -> Cid.to_string c | None -> "None");
49 Printf.printf " Entries (%d):\n" (List.length node.e);
50 List.iter
51 (fun e ->
52 Printf.printf " p=%d k=%S v=%s t=%s\n" e.p e.k
53 (Cid.to_string e.v)
54 (match e.t with Some c -> Cid.to_string c | None -> "None"))
55 node.e
56 | Error (`Decode_error msg) -> Printf.printf " DECODE ERROR: %s\n" msg)
57 blocks