diff --git a/README.md b/README.md index 7a3722e1..97a25da7 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,8 @@ change. import ( "github.com/conformal/btcdb" _ "github.com/conformal/btcdb/ldb" + "github.com/conformal/btcnet" "github.com/conformal/btcutil" - "github.com/conformal/btcwire" ) // Create a database and schedule it to be closed on exit. @@ -34,7 +34,7 @@ change. // Insert the main network genesis block. - genesis := btcutil.NewBlock(&btcwire.GenesisBlock) + genesis := btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock) newHeight, err := db.InsertBlock(genesis) if err != nil { // Log and handle the error diff --git a/common_test.go b/common_test.go index ffe2653f..2d283b1a 100644 --- a/common_test.go +++ b/common_test.go @@ -11,6 +11,7 @@ import ( "github.com/conformal/btcdb" _ "github.com/conformal/btcdb/ldb" _ "github.com/conformal/btcdb/memdb" + "github.com/conformal/btcnet" "github.com/conformal/btcutil" "github.com/conformal/btcwire" "io" @@ -138,7 +139,7 @@ func setupDB(dbType, dbName string) (btcdb.Db, func(), error) { // Insert the main network genesis block. This is part of the initial // database setup. - genesisBlock := btcutil.NewBlock(&btcwire.GenesisBlock) + genesisBlock := btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock) _, err = db.InsertBlock(genesisBlock) if err != nil { teardown() @@ -177,7 +178,7 @@ func loadBlocks(t *testing.T) ([]*btcutil.Block, error) { // Set the first block as the genesis block. blocks := make([]*btcutil.Block, 0, 256) - genesis := btcutil.NewBlock(&btcwire.GenesisBlock) + genesis := btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock) blocks = append(blocks, genesis) for height := int64(1); err == nil; height++ { diff --git a/doc.go b/doc.go index eb5e426d..5a89f75d 100644 --- a/doc.go +++ b/doc.go @@ -33,8 +33,8 @@ referenced parent block to already exist. In a more concrete example: import ( "github.com/conformal/btcdb" _ "github.com/conformal/btcdb/ldb" + "github.com/conformal/btcnet" "github.com/conformal/btcutil" - "github.com/conformal/btcwire" ) // Create a database and schedule it to be closed on exit. @@ -47,7 +47,7 @@ referenced parent block to already exist. In a more concrete example: // Insert the main network genesis block. - genesis := btcutil.NewBlock(&btcwire.GenesisBlock) + genesis := btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock) newHeight, err := db.InsertBlock(genesis) if err != nil { // Log and handle the error diff --git a/ldb/operational_test.go b/ldb/operational_test.go index d9a6b2ea..2e8f82db 100644 --- a/ldb/operational_test.go +++ b/ldb/operational_test.go @@ -9,6 +9,7 @@ import ( "encoding/binary" "fmt" "github.com/conformal/btcdb" + "github.com/conformal/btcnet" "github.com/conformal/btcutil" "github.com/conformal/btcwire" "io" @@ -246,7 +247,7 @@ func loadBlocks(t *testing.T, file string) (blocks []*btcutil.Block, err error) }() // Set the first block as the genesis block. - genesis := btcutil.NewBlock(&btcwire.GenesisBlock) + genesis := btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock) blocks = append(blocks, genesis) var block *btcutil.Block diff --git a/memdb/memdb_test.go b/memdb/memdb_test.go index 4d96b149..f5684483 100644 --- a/memdb/memdb_test.go +++ b/memdb/memdb_test.go @@ -7,6 +7,7 @@ package memdb_test import ( "github.com/conformal/btcdb" "github.com/conformal/btcdb/memdb" + "github.com/conformal/btcnet" "github.com/conformal/btcutil" "github.com/conformal/btcwire" "reflect" @@ -23,13 +24,13 @@ func TestClosed(t *testing.T) { t.Errorf("Failed to open test database %v", err) return } - _, err = db.InsertBlock(btcutil.NewBlock(&btcwire.GenesisBlock)) + _, err = db.InsertBlock(btcutil.NewBlock(btcnet.MainNetParams.GenesisBlock)) if err != nil { t.Errorf("InsertBlock: %v", err) } db.Close() - genesisHash := &btcwire.GenesisHash + genesisHash := btcnet.MainNetParams.GenesisHash if err := db.DropAfterBlockBySha(genesisHash); err != memdb.ErrDbClosed { t.Errorf("DropAfterBlockBySha: unexpected error %v", err) } @@ -50,10 +51,14 @@ func TestClosed(t *testing.T) { t.Errorf("FetchHeightRange: unexpected error %v", err) } - genesisMerkleRoot := &btcwire.GenesisMerkleRoot - if exists := db.ExistsTxSha(genesisMerkleRoot); exists != false { + genesisCoinbaseTx := btcnet.MainNetParams.GenesisBlock.Transactions[0] + coinbaseHash, err := genesisCoinbaseTx.TxSha() + if err != nil { + t.Errorf("TxSha: unexpected error %v", err) + } + if exists := db.ExistsTxSha(&coinbaseHash); exists != false { t.Errorf("ExistsTxSha: hash %v exists when it shouldn't", - genesisMerkleRoot) + &coinbaseHash) } if _, err := db.FetchTxBySha(genesisHash); err != memdb.ErrDbClosed {