Browse Source

kvdb: exclude anything bbolt related from JS builds

Since bbolt uses syscalls for memory mapping that aren't available in
JS/WASM builds, we need to make sure we don't reference that code at
all. Otherwise we can't use parts of lnd as a library in projects that
are being compiled down to a WASM binary.
master
Oliver Gugger 3 years ago
parent
commit
724ca7a358
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
  1. 2
      kvdb/backend.go
  2. 48
      kvdb/backend_js.go
  3. 2
      kvdb/bolt_compact.go

2
kvdb/backend.go

@ -1,3 +1,5 @@
// +build !js
package kvdb
import (

48
kvdb/backend_js.go

@ -0,0 +1,48 @@
package kvdb
import (
"fmt"
"time"
)
// BoltBackendConfig is a struct that holds settings specific to the bolt
// database backend.
type BoltBackendConfig struct {
// DBPath is the directory path in which the database file should be
// stored.
DBPath string
// DBFileName is the name of the database file.
DBFileName string
// NoFreelistSync, if true, prevents the database from syncing its
// freelist to disk, resulting in improved performance at the expense of
// increased startup time.
NoFreelistSync bool
// AutoCompact specifies if a Bolt based database backend should be
// automatically compacted on startup (if the minimum age of the
// database file is reached). This will require additional disk space
// for the compacted copy of the database but will result in an overall
// lower database size after the compaction.
AutoCompact bool
// AutoCompactMinAge specifies the minimum time that must have passed
// since a bolt database file was last compacted for the compaction to
// be considered again.
AutoCompactMinAge time.Duration
// DBTimeout specifies the timeout value to use when opening the wallet
// database.
DBTimeout time.Duration
}
// GetBoltBackend opens (or creates if doesn't exits) a bbolt backed database
// and returns a kvdb.Backend wrapping it.
func GetBoltBackend(cfg *BoltBackendConfig) (Backend, error) {
return nil, fmt.Errorf("bolt backend not supported in WebAssembly")
}
func GetTestBackend(path, name string) (Backend, func(), error) {
return nil, nil, fmt.Errorf("bolt backend not supported in WebAssembly")
}

2
kvdb/bolt_compact.go

@ -2,6 +2,8 @@
// implemented in this file:
// https://github.com/etcd-io/bbolt/blob/master/cmd/bbolt/main.go
// +build !js
package kvdb
import (

Loading…
Cancel
Save