func (b *BadgerTreeTransaction) NewNode(left *Node, right *Node, subtreeHash chainhash.Hash) (*Node, error) {
	var leftHash *chainhash.Hash
	var rightHash *chainhash.Hash
	if left != nil {
		lh := left.GetHash()
		leftHash = &lh
	}
	if right != nil {
		rh := right.GetHash()
		rightHash = &rh
	}
	newNode := &Node{
		value: subtreeHash,
		left:  leftHash,
		right: rightHash,
	}
	return newNode, b.SetNode(newNode)
}
NewNode creates a new node with the given left and right children and adds it to the database.
package csmt
import (
	"bytes"
	"github.com/dgraph-io/badger"
	"github.com/phoreproject/synapse/chainhash"
	"github.com/phoreproject/synapse/primitives"
	"github.com/pkg/errors"
)
type BadgerTreeDB struct {
	db *badger.DB
}
func (b *BadgerTreeDB) Hash() (*chainhash.Hash, error) {
	out := primitives.EmptyTree
	err := b.View(func(transaction TreeDatabaseTransaction) error {
		h, err := transaction.Hash()
		if err != nil {
			return err
		}
		out = *h
		return nil
	})
	if err != nil {
		return nil, err
	}
	return &out, nil
}
var treeDBPrefix = []byte("tree-")
var treeKVPrefix = []byte("kv-")
func getTreeKey(key []byte) []byte {
	return append(treeDBPrefix, key...)
}
func getKVKey(key []byte) []byte {
	return append(treeKVPrefix, key...)
}
func (b *BadgerTreeTransaction) SetRoot(n *Node) error {
	nodeHash := n.GetHash()
	return b.tx.Set([]byte("root"), nodeHash[:])
}