From 2eab114a120c7818861c0640ecdc300cf7366e53 Mon Sep 17 00:00:00 2001 From: Marcos Magueta Date: Sat, 26 Oct 2024 14:26:10 -0300 Subject: Basic storage with C interop (#1) * writer command design * dune build with shared core lib * port c lib project inside ocaml * os specific dynamic link * fix project name on flake * fix: cmake cxx version breaking merklecpp * finish write to disk and update maps func * add non atomic commit to transaction graph * merkle tree binding for generating root hash * disk module refactor --------- Co-authored-by: Renan Lopes --- lib/interop.ml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 lib/interop.ml (limited to 'lib/interop.ml') diff --git a/lib/interop.ml b/lib/interop.ml new file mode 100644 index 0000000..fdfde5f --- /dev/null +++ b/lib/interop.ml @@ -0,0 +1,19 @@ +open Ctypes + +module Sha256 = struct + let compute_hash content = + let size_with_null_terminator = C.Types.hash_size + 1 in + let buf = Ctypes.allocate_n char ~count:size_with_null_terminator in + let () = C.Functions.compute_hash buf (Bytes.to_string content) in + Ctypes.coerce (ptr char) Ctypes.string buf +end + +module Merkle = struct + let merkle_generate_root hashes = + let size_with_null_terminator = C.Types.hash_size + 1 in + let buf = Ctypes.allocate_n char ~count:size_with_null_terminator in + let len = List.length hashes in + let hashes = CArray.of_list string hashes in + C.Functions.merkle_generate_root (CArray.start hashes) len buf; + Ctypes.coerce (ptr char) Ctypes.string buf +end -- cgit v1.2.3