channeldb: remove hardcoded netparams

This commit is contained in:
Olaoluwa Osuntokun 2016-04-24 12:35:52 -07:00
parent 1e35018e89
commit fa1e7a332f
4 changed files with 13 additions and 9 deletions

@ -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")
}

@ -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...

@ -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)
}

@ -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)
}