Skip to content

Commit

Permalink
Update database import paths to new location.
Browse files Browse the repository at this point in the history
  • Loading branch information
davecgh committed Jan 27, 2015
1 parent 8d7780e commit 309a9ea
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 80 deletions.
14 changes: 7 additions & 7 deletions blockmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"time"

"github.com/btcsuite/btcchain"
"github.com/btcsuite/btcdb"
"github.com/btcsuite/btcd/database"
"github.com/btcsuite/btcnet"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcwire"
Expand Down Expand Up @@ -1456,13 +1456,13 @@ func warnMultipeDBs() {
// such warning the user if there are multiple databases which consume space on
// the file system and ensuring the regression test database is clean when in
// regression test mode.
func setupBlockDB() (btcdb.Db, error) {
func setupBlockDB() (database.Db, error) {
// The memdb backend does not have a file path associated with it, so
// handle it uniquely. We also don't want to worry about the multiple
// database type warnings when running with the memory database.
if cfg.DbType == "memdb" {
btcdLog.Infof("Creating block database in memory.")
db, err := btcdb.CreateDB(cfg.DbType)
db, err := database.CreateDB(cfg.DbType)
if err != nil {
return nil, err
}
Expand All @@ -1479,11 +1479,11 @@ func setupBlockDB() (btcdb.Db, error) {
removeRegressionDB(dbPath)

btcdLog.Infof("Loading block database from '%s'", dbPath)
db, err := btcdb.OpenDB(cfg.DbType, dbPath)
db, err := database.OpenDB(cfg.DbType, dbPath)
if err != nil {
// Return the error if it's not because the database
// doesn't exist.
if err != btcdb.ErrDbDoesNotExist {
if err != database.ErrDbDoesNotExist {
return nil, err
}

Expand All @@ -1492,7 +1492,7 @@ func setupBlockDB() (btcdb.Db, error) {
if err != nil {
return nil, err
}
db, err = btcdb.CreateDB(cfg.DbType, dbPath)
db, err = database.CreateDB(cfg.DbType, dbPath)
if err != nil {
return nil, err
}
Expand All @@ -1502,7 +1502,7 @@ func setupBlockDB() (btcdb.Db, error) {
}

// loadBlockDB opens the block database and returns a handle to it.
func loadBlockDB() (btcdb.Db, error) {
func loadBlockDB() (database.Db, error) {
db, err := setupBlockDB()
if err != nil {
return nil, err
Expand Down
14 changes: 7 additions & 7 deletions cmd/addblock/addblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"runtime"

"github.com/btcsuite/btcchain"
"github.com/btcsuite/btcd/database"
_ "github.com/btcsuite/btcd/database/ldb"
"github.com/btcsuite/btcd/limits"
"github.com/btcsuite/btcdb"
_ "github.com/btcsuite/btcdb/ldb"
"github.com/btcsuite/btclog"
)

Expand All @@ -27,7 +27,7 @@ var (
)

// loadBlockDB opens the block database and returns a handle to it.
func loadBlockDB() (btcdb.Db, error) {
func loadBlockDB() (database.Db, error) {
// The database name is based on the database type.
dbName := blockDbNamePrefix + "_" + cfg.DbType
if cfg.DbType == "sqlite" {
Expand All @@ -36,11 +36,11 @@ func loadBlockDB() (btcdb.Db, error) {
dbPath := filepath.Join(cfg.DataDir, dbName)

log.Infof("Loading block database from '%s'", dbPath)
db, err := btcdb.OpenDB(cfg.DbType, dbPath)
db, err := database.OpenDB(cfg.DbType, dbPath)
if err != nil {
// Return the error if it's not because the database doesn't
// exist.
if err != btcdb.ErrDbDoesNotExist {
if err != database.ErrDbDoesNotExist {
return nil, err
}

Expand All @@ -49,7 +49,7 @@ func loadBlockDB() (btcdb.Db, error) {
if err != nil {
return nil, err
}
db, err = btcdb.CreateDB(cfg.DbType, dbPath)
db, err = database.CreateDB(cfg.DbType, dbPath)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -80,7 +80,7 @@ func realMain() error {
backendLogger := btclog.NewDefaultBackendLogger()
defer backendLogger.Flush()
log = btclog.NewSubsystemLogger(backendLogger, "")
btcdb.UseLogger(btclog.NewSubsystemLogger(backendLogger, "BCDB: "))
database.UseLogger(btclog.NewSubsystemLogger(backendLogger, "BCDB: "))
btcchain.UseLogger(btclog.NewSubsystemLogger(backendLogger, "CHAN: "))

// Load the block database.
Expand Down
6 changes: 3 additions & 3 deletions cmd/addblock/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"os"
"path/filepath"

"github.com/btcsuite/btcdb"
_ "github.com/btcsuite/btcdb/ldb"
"github.com/btcsuite/btcd/database"
_ "github.com/btcsuite/btcd/database/ldb"
"github.com/btcsuite/btcnet"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcwire"
Expand All @@ -26,7 +26,7 @@ const (
var (
btcdHomeDir = btcutil.AppDataDir("btcd", false)
defaultDataDir = filepath.Join(btcdHomeDir, "data")
knownDbTypes = btcdb.SupportedDBs()
knownDbTypes = database.SupportedDBs()
activeNetParams = &btcnet.MainNetParams
)

Expand Down
8 changes: 4 additions & 4 deletions cmd/addblock/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"time"

"github.com/btcsuite/btcchain"
"github.com/btcsuite/btcdb"
_ "github.com/btcsuite/btcdb/ldb"
"github.com/btcsuite/btcd/database"
_ "github.com/btcsuite/btcd/database/ldb"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcwire"
)
Expand All @@ -30,7 +30,7 @@ type importResults struct {
// blockImporter houses information about an ongoing import from a block data
// file to the block database.
type blockImporter struct {
db btcdb.Db
db database.Db
chain *btcchain.BlockChain
medianTime btcchain.MedianTimeSource
r io.ReadSeeker
Expand Down Expand Up @@ -299,7 +299,7 @@ func (bi *blockImporter) Import() chan *importResults {

// newBlockImporter returns a new importer for the provided file reader seeker
// and database.
func newBlockImporter(db btcdb.Db, r io.ReadSeeker) *blockImporter {
func newBlockImporter(db database.Db, r io.ReadSeeker) *blockImporter {
return &blockImporter{
db: db,
r: r,
Expand Down
10 changes: 5 additions & 5 deletions cmd/dropafter/dropafter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"path/filepath"
"strconv"

"github.com/btcsuite/btcdb"
_ "github.com/btcsuite/btcdb/ldb"
"github.com/btcsuite/btcd/database"
_ "github.com/btcsuite/btcd/database/ldb"
"github.com/btcsuite/btclog"
"github.com/btcsuite/btcnet"
"github.com/btcsuite/btcutil"
Expand Down Expand Up @@ -78,7 +78,7 @@ func main() {
backendLogger := btclog.NewDefaultBackendLogger()
defer backendLogger.Flush()
log = btclog.NewSubsystemLogger(backendLogger, "")
btcdb.UseLogger(log)
database.UseLogger(log)

// Multiple networks can't be selected simultaneously.
funcName := "main"
Expand Down Expand Up @@ -115,7 +115,7 @@ func main() {
dbPath := filepath.Join(cfg.DataDir, dbName)

log.Infof("loading db")
db, err := btcdb.OpenDB(cfg.DbType, dbPath)
db, err := database.OpenDB(cfg.DbType, dbPath)
if err != nil {
log.Warnf("db open failed: %v", err)
return
Expand All @@ -139,7 +139,7 @@ func main() {

}

func getSha(db btcdb.Db, str string) (btcwire.ShaHash, error) {
func getSha(db database.Db, str string) (btcwire.ShaHash, error) {
argtype, idx, sha, err := parsesha(str)
if err != nil {
log.Warnf("unable to decode [%v] %v", str, err)
Expand Down
6 changes: 3 additions & 3 deletions cmd/findcheckpoint/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"os"
"path/filepath"

"github.com/btcsuite/btcdb"
_ "github.com/btcsuite/btcdb/ldb"
"github.com/btcsuite/btcd/database"
_ "github.com/btcsuite/btcd/database/ldb"
"github.com/btcsuite/btcnet"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcwire"
Expand All @@ -27,7 +27,7 @@ const (
var (
btcdHomeDir = btcutil.AppDataDir("btcd", false)
defaultDataDir = filepath.Join(btcdHomeDir, "data")
knownDbTypes = btcdb.SupportedDBs()
knownDbTypes = database.SupportedDBs()
activeNetParams = &btcnet.MainNetParams
)

Expand Down
10 changes: 5 additions & 5 deletions cmd/findcheckpoint/findcheckpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"path/filepath"

"github.com/btcsuite/btcchain"
"github.com/btcsuite/btcdb"
_ "github.com/btcsuite/btcdb/ldb"
"github.com/btcsuite/btcd/database"
_ "github.com/btcsuite/btcd/database/ldb"
"github.com/btcsuite/btcnet"
"github.com/btcsuite/btcwire"
)
Expand All @@ -23,7 +23,7 @@ var (
)

// loadBlockDB opens the block database and returns a handle to it.
func loadBlockDB() (btcdb.Db, error) {
func loadBlockDB() (database.Db, error) {
// The database name is based on the database type.
dbType := cfg.DbType
dbName := blockDbNamePrefix + "_" + dbType
Expand All @@ -32,7 +32,7 @@ func loadBlockDB() (btcdb.Db, error) {
}
dbPath := filepath.Join(cfg.DataDir, dbName)
fmt.Printf("Loading block database from '%s'\n", dbPath)
db, err := btcdb.OpenDB(dbType, dbPath)
db, err := database.OpenDB(dbType, dbPath)
if err != nil {
return nil, err
}
Expand All @@ -44,7 +44,7 @@ func loadBlockDB() (btcdb.Db, error) {
// candidates at the last checkpoint that is already hard coded into btcchain
// since there is no point in finding candidates before already existing
// checkpoints.
func findCandidates(db btcdb.Db, latestHash *btcwire.ShaHash) ([]*btcnet.Checkpoint, error) {
func findCandidates(db database.Db, latestHash *btcwire.ShaHash) ([]*btcnet.Checkpoint, error) {
// Start with the latest block of the main chain.
block, err := db.FetchBlockBySha(latestHash)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions cmd/showblock/showblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"path/filepath"
"strconv"

"github.com/btcsuite/btcdb"
_ "github.com/btcsuite/btcdb/ldb"
"github.com/btcsuite/btcd/database"
_ "github.com/btcsuite/btcd/database/ldb"
"github.com/btcsuite/btclog"
"github.com/btcsuite/btcnet"
"github.com/btcsuite/btcutil"
Expand Down Expand Up @@ -89,7 +89,7 @@ func main() {
backendLogger := btclog.NewDefaultBackendLogger()
defer backendLogger.Flush()
log = btclog.NewSubsystemLogger(backendLogger, "")
btcdb.UseLogger(log)
database.UseLogger(log)

// Multiple networks can't be selected simultaneously.
funcName := "main"
Expand Down Expand Up @@ -126,7 +126,7 @@ func main() {
dbPath := filepath.Join(cfg.DataDir, dbName)

log.Infof("loading db %v", cfg.DbType)
db, err := btcdb.OpenDB(cfg.DbType, dbPath)
db, err := database.OpenDB(cfg.DbType, dbPath)
if err != nil {
log.Warnf("db open failed: %v", err)
return
Expand Down Expand Up @@ -179,7 +179,7 @@ func main() {
}
}

func getHeight(db btcdb.Db, str string) (int64, error) {
func getHeight(db database.Db, str string) (int64, error) {
argtype, idx, sha, err := parsesha(str)
if err != nil {
log.Warnf("unable to decode [%v] %v", str, err)
Expand All @@ -201,7 +201,7 @@ func getHeight(db btcdb.Db, str string) (int64, error) {
return idx, nil
}

func DumpBlock(db btcdb.Db, height int64, fo io.Writer, rflag bool, fflag bool, tflag bool) error {
func DumpBlock(db database.Db, height int64, fo io.Writer, rflag bool, fflag bool, tflag bool) error {
sha, err := db.FetchBlockShaByHeight(height)

if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
"strings"
"time"

"github.com/btcsuite/btcdb"
_ "github.com/btcsuite/btcdb/ldb"
_ "github.com/btcsuite/btcdb/memdb"
"github.com/btcsuite/btcd/database"
_ "github.com/btcsuite/btcd/database/ldb"
_ "github.com/btcsuite/btcd/database/memdb"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcwire"
flags "github.com/btcsuite/go-flags"
Expand Down Expand Up @@ -50,7 +50,7 @@ var (
btcdHomeDir = btcutil.AppDataDir("btcd", false)
defaultConfigFile = filepath.Join(btcdHomeDir, defaultConfigFilename)
defaultDataDir = filepath.Join(btcdHomeDir, defaultDataDirname)
knownDbTypes = btcdb.SupportedDBs()
knownDbTypes = database.SupportedDBs()
defaultRPCKeyFile = filepath.Join(btcdHomeDir, "rpc.key")
defaultRPCCertFile = filepath.Join(btcdHomeDir, "rpc.cert")
defaultLogDir = filepath.Join(btcdHomeDir, defaultLogDirname)
Expand Down
23 changes: 12 additions & 11 deletions database/ldb/operational_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"bytes"
"compress/bzip2"
"encoding/binary"
"fmt"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -36,9 +35,8 @@ type testDb struct {
cleanUpFunc func()
}

func setUpTestDb(t *testing.T) (*testDb, error) {
func setUpTestDb(t *testing.T, dbname string) (*testDb, error) {
// Ignore db remove errors since it means we didn't have an old one.
dbname := fmt.Sprintf("tstdbop1")
dbnamever := dbname + ".ver"
_ = os.RemoveAll(dbname)
_ = os.RemoveAll(dbnamever)
Expand Down Expand Up @@ -160,7 +158,7 @@ func testAddrIndexOperations(t *testing.T, db database.Db, newestBlock *btcutil.
db.Close()

// Re-Open, tip still should be updated to current height and sha.
db, err = database.OpenDB("leveldb", "tstdbop1")
db, err = database.OpenDB("leveldb", "tstdbopmode")
if err != nil {
t.Fatalf("Unable to re-open created db, err %v", err)
}
Expand Down Expand Up @@ -209,12 +207,12 @@ func testOperationalMode(t *testing.T) {
// 2) look up all txin (except coinbase in db)
// 3) insert block
// 4) exercise the optional addridex
testDb, err := setUpTestDb(t)
defer testDb.cleanUpFunc()
testDb, err := setUpTestDb(t, "tstdbopmode")
if err != nil {
t.Errorf("Unable to load blocks from test data: %v", err)
t.Errorf("Failed to open test database %v", err)
return
}
defer testDb.cleanUpFunc()
err = nil
out:
for height := int64(0); height < int64(len(testDb.blocks)); height++ {
Expand Down Expand Up @@ -295,13 +293,12 @@ func testBackout(t *testing.T) {
// 2) look up all txin (except coinbase in db)
// 3) insert block

testDb, err := setUpTestDb(t)
defer testDb.cleanUpFunc()

testDb, err := setUpTestDb(t, "tstdbbackout")
if err != nil {
t.Errorf("Failed to open test database %v", err)
return
}
defer testDb.cleanUpFunc()

if len(testDb.blocks) < 120 {
t.Errorf("test data too small")
Expand Down Expand Up @@ -516,7 +513,11 @@ func testFetchHeightRange(t *testing.T, db database.Db, blocks []*btcutil.Block)
}

func TestLimitAndSkipFetchTxsForAddr(t *testing.T) {
testDb, err := setUpTestDb(t)
testDb, err := setUpTestDb(t, "tstdbtxaddr")
if err != nil {
t.Errorf("Failed to open test database %v", err)
return
}
defer testDb.cleanUpFunc()

// Insert a block with some fake test transactions. The block will have
Expand Down
Loading

0 comments on commit 309a9ea

Please sign in to comment.