mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 18:10:34 +01:00
75531455da
The final database that needs to be made remote compatible is the watchtower server and client database. They are handled a bit differently because both of them are not always active, only when specifically turned on in the config.
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package wtdb
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"errors"
|
|
|
|
"github.com/lightningnetwork/lnd/kvdb"
|
|
)
|
|
|
|
var (
|
|
// metadataBkt stores all the meta information concerning the state of
|
|
// the database.
|
|
metadataBkt = []byte("metadata-bucket")
|
|
|
|
// dbVersionKey is a static key used to retrieve the database version
|
|
// number from the metadataBkt.
|
|
dbVersionKey = []byte("version")
|
|
|
|
// ErrUninitializedDB signals that top-level buckets for the database
|
|
// have not been initialized.
|
|
ErrUninitializedDB = errors.New("db not initialized")
|
|
|
|
// ErrNoDBVersion signals that the database contains no version info.
|
|
ErrNoDBVersion = errors.New("db has no version")
|
|
|
|
// byteOrder is the default endianness used when serializing integers.
|
|
byteOrder = binary.BigEndian
|
|
)
|
|
|
|
// isFirstInit returns true if the given database has not yet been initialized,
|
|
// e.g. no metadata bucket is present yet.
|
|
func isFirstInit(db kvdb.Backend) (bool, error) {
|
|
var metadataExists bool
|
|
err := kvdb.View(db, func(tx kvdb.RTx) error {
|
|
metadataExists = tx.ReadBucket(metadataBkt) != nil
|
|
return nil
|
|
}, func() {
|
|
metadataExists = false
|
|
})
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
return !metadataExists, nil
|
|
}
|