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 --- shared/librelational_engine/library.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 shared/librelational_engine/library.cpp (limited to 'shared/librelational_engine/library.cpp') diff --git a/shared/librelational_engine/library.cpp b/shared/librelational_engine/library.cpp new file mode 100644 index 0000000..8048486 --- /dev/null +++ b/shared/librelational_engine/library.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +#include +extern "C" { +#include "library.h" + extern void merkle_generate_root(char** hashes, const int n, char* root) { + merkle::Tree tree; + for (int i = 0; i < n; i++){ + tree.insert(merkle::Hash(hashes[i])); + } + std::memcpy(root, tree.root().to_string().c_str(), HASH_SIZE); + } + extern void compute_hash(char* computed_hash, const char *content) { + + unsigned char hash[SHA256_DIGEST_LENGTH]; + SHA256_CTX sha256; + SHA256_Init(&sha256); + SHA256_Update(&sha256, content, sizeof(content)); + SHA256_Final(hash, &sha256); + std::stringstream ss; + for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) + ss << std::hex << std::setw(2) << std::setfill('0') << static_cast(hash[i]); + + std::memcpy(computed_hash, ss.str().c_str(), HASH_SIZE); + std::cout << "⚙️ COMPUTED HASH: " << computed_hash << std::endl; + } + + extern int trash() { return 100; } +} \ No newline at end of file -- cgit v1.2.3