diff --git a/channeldb/channel_test.go b/channeldb/channel_test.go index 9d67af91..0de7f078 100644 --- a/channeldb/channel_test.go +++ b/channeldb/channel_test.go @@ -10,12 +10,15 @@ import ( "github.com/LightningNetwork/lnd/elkrem" "github.com/Roasbeef/btcd/txscript" "github.com/btcsuite/btcd/btcec" + "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" _ "github.com/btcsuite/btcwallet/walletdb/bdb" ) var ( + netParams = &chaincfg.SegNet4Params + key = [wire.HashSize]byte{ 0x81, 0xb6, 0x37, 0xd8, 0xfc, 0xd2, 0xc6, 0xda, 0x68, 0x59, 0xe6, 0x96, 0x31, 0x13, 0xa1, 0x17, @@ -95,7 +98,7 @@ func TestOpenChannelEncodeDecode(t *testing.T) { // Next, create channeldb for the first time, also setting a mock // EncryptorDecryptor implementation for testing purposes. - cdb, err := Open(tempDirName) + cdb, err := Open(tempDirName, netParams) if err != nil { t.Fatalf("unable to create channeldb: %v", err) } @@ -103,7 +106,7 @@ func TestOpenChannelEncodeDecode(t *testing.T) { defer cdb.Close() privKey, pubKey := btcec.PrivKeyFromBytes(btcec.S256(), key[:]) - addr, err := btcutil.NewAddressPubKey(pubKey.SerializeCompressed(), ActiveNetParams) + addr, err := btcutil.NewAddressPubKey(pubKey.SerializeCompressed(), netParams) if err != nil { t.Fatalf("unable to create delivery address") } diff --git a/channeldb/db.go b/channeldb/db.go index a962cecc..b0d3db73 100644 --- a/channeldb/db.go +++ b/channeldb/db.go @@ -9,6 +9,7 @@ import ( "sync" "github.com/boltdb/bolt" + "github.com/btcsuite/btcd/chaincfg" ) const ( @@ -37,13 +38,15 @@ type EncryptorDecryptor interface { type DB struct { store *bolt.DB + netParams *chaincfg.Params + cryptoSystem EncryptorDecryptor } // Open opens an existing channeldb created under the passed namespace with // sensitive data encrypted by the passed EncryptorDecryptor implementation. // TODO(roasbeef): versioning? -func Open(dbPath string) (*DB, error) { +func Open(dbPath string, netParams *chaincfg.Params) (*DB, error) { path := filepath.Join(dbPath, dbName) if !fileExists(path) { @@ -57,7 +60,7 @@ func Open(dbPath string) (*DB, error) { return nil, err } - return &DB{store: bdb}, nil + return &DB{store: bdb, netParams: netParams}, nil } // RegisterCryptoSystem... diff --git a/channeldb/db_test.go b/channeldb/db_test.go index 69c2d3b5..47122ce3 100644 --- a/channeldb/db_test.go +++ b/channeldb/db_test.go @@ -18,7 +18,7 @@ func TestOpenWithCreate(t *testing.T) { // Next, open thereby creating channeldb for the first time. dbPath := filepath.Join(tempDirName, "cdb") - cdb, err := Open(dbPath) + cdb, err := Open(dbPath, netParams) if err != nil { t.Fatalf("unable to create channeldb: %v", err) } diff --git a/channeldb/nodes.go b/channeldb/nodes.go index 21a496c9..686fe7bc 100644 --- a/channeldb/nodes.go +++ b/channeldb/nodes.go @@ -6,13 +6,11 @@ import ( "golang.org/x/crypto/ripemd160" "github.com/boltdb/bolt" - "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcutil" ) var ( - idBucket = []byte("i") - ActiveNetParams = &chaincfg.TestNet3Params + idBucket = []byte("i") ) // PutIdKey saves the hash160 of the public key used for our identity within @@ -52,5 +50,5 @@ func (d *DB) GetIdAdr() (*btcutil.AddressPubKeyHash, error) { } log.Infof("identity key has length %d", len(pkh)) - return btcutil.NewAddressPubKeyHash(pkh, ActiveNetParams) + return btcutil.NewAddressPubKeyHash(pkh, d.netParams) }