Skip to content

Latest commit

 

History

History
126 lines (81 loc) · 2.09 KB

README.md

File metadata and controls

126 lines (81 loc) · 2.09 KB

firma

Blockchain focusing on security token issuance and decentralized cap table.

Testing on Ocaml's toplevel

Compile the module interface

$ ocamlc -c merkle.ml     # merkle.cmi

Find and link dependencies, then compile to module object file (.cmo)

$ ocamlfind ocamlc -package cryptokit,yojson -c merkle.ml

Instruction here is awesome for linking libraries.

then load merkle.cmo on Ocaml's toplevel / utop:

#load "merkle.cmo";;
open Merkle;;

example

(** Print out all the tree's nodes *)

tree_of_txs ["A"; "B"; "C"; "D"] |> peek_all ;;

Run JSON API server

Find the root directory where api_server.mlis located, then run:

$ dune build api_server.exe
$ ./_build/default/api_server.exe

If nothing goes wrong, you should see this being printed:

Listening for HTTP on port 8080
Try 'curl http://localhost:8080/merkle?txs=x,y,z'

The API server writes a JSON structure representing a binary Merkle tree created from the input of transactions (txs).

example

Provided transactions A, B, C, and D:

curl http://localhost:8080/merkle?txs=A,B,C,D&debug=true

The JSON string being returned is

{
  "data": {
    "hash": "ABCD",
    "children": [
      {
        "hash": "AB",
        "children": [
          {
            "hash": "A",
            "children": []
          },
          {
            "hash": "B",
            "children": []
          }
        ]
      },
      {
        "hash": "CD",
        "children": [
          {
            "hash": "C",
            "children": []
          },
          {
            "hash": "D",
            "children": []
          }
        ]
      }
    ]
  }
}

Setting debug query parameter to anything other than true or leave empty will default to debug=false and hash strings are returned instead.

JSON with null data will be returned if the number of tx is not a power of two. Read merkle.mli to find out more.

WIP