store

package module
v0.0.1-alpha.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2022 License: MIT Imports: 5 Imported by: 1

README

smt-bolt - Bolt db storage for https://github.com/iden3/go-merkletree-sql

Install

go get -u github.com/demonsh/smt-bolt

Usage

package main

import (
	"context"
	"fmt"
	"log"
	"math/big"
	"time"

	store "github.com/demonsh/smt-bolt"
	"github.com/iden3/go-merkletree-sql"
	bolt "go.etcd.io/bbolt"
)

var db = "./mt.db"

func main() {

	b, err := bolt.Open(db, 0600, nil)
	if err != nil {
		log.Fatal(err)
	}

	s, err := store.NewBoltStorage(b)
	if err != nil {
		log.Fatal(err)
	}

	mt, err := merkletree.NewMerkleTree(context.Background(), s, 10)
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	mt.Add(ctx, big.NewInt(1), big.NewInt(1))
	mt.Update(ctx, big.NewInt(1), big.NewInt(2))
	proof, value, err := mt.GenerateProof(ctx, big.NewInt(1), nil)
	fmt.Println(value)
	fmt.Println(proof)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoltStore

type BoltStore struct {
	// contains filtered or unexported fields
}

BoltStore implements the db.BoltStore interface

func NewBoltStorage

func NewBoltStorage(db *bolt.DB) (*BoltStore, error)

NewMemoryBoldStor returns a new BoltStore

func (*BoltStore) Get

func (m *BoltStore) Get(_ context.Context, key []byte) (*merkletree.Node, error)

Get retrieves a value from a key in the db.Storage

func (*BoltStore) GetRoot

func (m *BoltStore) GetRoot(_ context.Context) (*merkletree.Hash, error)

GetRoot returns current merkletree root

func (*BoltStore) Iterate

func (m *BoltStore) Iterate(_ context.Context,
	f func([]byte, *merkletree.Node) (bool, error)) error

Iterate implements the method Iterate of the interface db.Storage

func (*BoltStore) List

func (m *BoltStore) List(_ context.Context, limit int) ([]merkletree.KV, error)

List implements the method List of the interface db.Storage

func (*BoltStore) Put

func (m *BoltStore) Put(_ context.Context, key []byte,
	node *merkletree.Node) error

Put inserts new node into merkletree

func (*BoltStore) SetRoot

func (m *BoltStore) SetRoot(_ context.Context, hash *merkletree.Hash) error

SetRoot updates current merkletree root

func (*BoltStore) WithPrefix

func (m *BoltStore) WithPrefix(prefix []byte) merkletree.Storage

WithPrefix implements the method WithPrefix of the interface db.Storage

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL