func (bdb *BoltDB) SetSync(key, value []byte) error {
	return bdb.Set(key, value)
}
SetSync implements DB.
package boltdb
import (
	"errors"
	"fmt"
	"os"
	"path/filepath"
	tmdb "github.com/tendermint/tm-db"
	"go.etcd.io/bbolt"
)
var bucket = []byte("tm")
type BoltDB struct {
	db *bbolt.DB
}
var _ tmdb.DB = (*BoltDB)(nil)
func NewDB(name, dir string) (tmdb.DB, error) {
	return NewDBWithOpts(name, dir, bbolt.DefaultOptions)
}
func NewDBWithOpts(name string, dir string, opts *bbolt.Options) (tmdb.DB, error) {
	if opts.ReadOnly {
		return nil, errors.New("ReadOnly: true is not supported")
	}
	dbPath := filepath.Join(dir, name+".db")
	db, err := bbolt.Open(dbPath, os.ModePerm, opts)
	if err != nil {
		return nil, err
	}
	err = db.Update(func(tx *bbolt.Tx) error {
		_, err := tx.CreateBucketIfNotExists(bucket)
		return err
	})
	if err != nil {
		return nil, err
	}
	return &BoltDB{db: db}, nil
}
func (bdb *BoltDB) Get(key []byte) (value []byte, err error) {
	if len(key) == 0 {
		return nil, tmdb.ErrKeyEmpty
	}
	err = bdb.db.View(func(tx *bbolt.Tx) error {
		b := tx.Bucket(bucket)
		if v := b.Get(key); v != nil {
			value = append([]byte{}, v...)
		}
		return nil
	})
	if err != nil {
		return nil, err
	}
	return
}
func (bdb *BoltDB) Has(key []byte) (bool, error) {
	bytes, err := bdb.Get(key)
	if err != nil {
		return false, err
	}
	return bytes != nil, nil
}
func (bdb *BoltDB) Set(key, value []byte) error {
	if len(key) == 0 {
		return tmdb.ErrKeyEmpty
	}
	if value == nil {
		return tmdb.ErrValueNil
	}
	err := bdb.db.Update(func(tx *bbolt.Tx) error {
		b := tx.Bucket(bucket)
		return b.Put(key, value)
	})
	if err != nil {
		return err
	}
	return nil
}