GithubHelp home page GithubHelp logo

smt-rocksdb-store's Introduction

Sparse merkle tree rocksdb store implementation

This is a rust implementation of a sparse merkle tree store using rocksdb as the backend.

Usage

Please refer to the unit tests for usage examples.

Examples

Start a rocksdb store backed sparse merkle tree

cargo run --example rpc_server -- /tmp/smt-store-dir 127.0.0.1:10000

call rpc server to update the tree

echo '{
    "id": 2,
    "jsonrpc": "2.0",
    "method": "update_all",
    "params": [
        [
            ["2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a", "2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a"],
            ["2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b", "2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b"],
            ["2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"],
            ["1111111111111111111111111111111111111111111111111111111111111111", "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"],
            ["3333333333333333333333333333333333333333333333333333333333333333", "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"]
        ]
    ]
}' \
| curl -H 'content-type: application/json' -d @- \
http://localhost:10000

call rpc server to get the proof:

echo '{
    "id": 2,
    "jsonrpc": "2.0",
    "method": "merkle_proof",
    "params": [
        ["2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b", "1111111111111111111111111111111111111111111111111111111111111111"]
    ]
}' \
| curl -H 'content-type: application/json' -d @- \
http://localhost:10000

Start a rocksdb store backed with multiple sparse merkle trees

Please be aware that the tree name is used as the prefix of the key to store the leaf and branch, so the tree name should be unique. Otherwise, the data of the tree with the same prefix name may be overwritten. Suggest to add a fixed suffix to the tree name to make it unique, for example. add a . to the tree name, like "tree." and "tree1."

Or you may use the ColumnFamilyStore to replace the DefaultStore in the rpc_server_multi_tree.rs example, which will use two different column families to store the smt branch and leaf data.

cargo run --example rpc_server_multi_tree -- /tmp/smt-store-dir 127.0.0.1:10000

call rpc server to update the tree

echo '{
    "id": 2,
    "jsonrpc": "2.0",
    "method": "update_all",
    "params": [
        "tree1.",
        [
            ["2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a", "2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a"],
            ["2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b", "2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b"],
            ["2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"],
            ["1111111111111111111111111111111111111111111111111111111111111111", "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"],
            ["3333333333333333333333333333333333333333333333333333333333333333", "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"]
        ]
    ]
}' \
| curl -H 'content-type: application/json' -d @- \
http://localhost:10000

call rpc server to get the proof:

echo '{
    "id": 2,
    "jsonrpc": "2.0",
    "method": "merkle_proof",
    "params": [
        "tree1.",
        ["2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b", "1111111111111111111111111111111111111111111111111111111111111111"]
    ]
}' \
| curl -H 'content-type: application/json' -d @- \
http://localhost:10000

call rpc server to clear a tree:

echo '{
    "id": 2,
    "jsonrpc": "2.0",
    "method": "clear",
    "params": [
        "tree1."
    ]
}' \
| curl -H 'content-type: application/json' -d @- \
http://localhost:10000

smt-rocksdb-store's People

Contributors

quake avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.