lnwallet: add dirty config

This commit is contained in:
Olaoluwa Osuntokun 2015-12-29 15:59:57 -06:00
parent f1717b9620
commit 7640e57cdc
3 changed files with 13 additions and 27 deletions

@ -30,7 +30,6 @@ import (
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcutil/hdkeychain"
"github.com/btcsuite/btcwallet/waddrmgr"
"github.com/btcsuite/btcwallet/wallet"
@ -38,25 +37,6 @@ import (
_ "github.com/btcsuite/btcwallet/walletdb/bdb"
)
var (
// TODO(roasbeef): lnwallet config file
lnwalletHomeDir = btcutil.AppDataDir("lnwallet", false)
defaultDataDir = lnwalletHomeDir
defaultLogFilename = "lnwallet.log"
defaultLogDirname = "logs"
// defaultPubPassphrase is the default public wallet passphrase which is
// used when the user indicates they do not want additional protection
// provided by having all public data in the wallet encrypted by a
// passphrase only known to them.
defaultPubPassphrase = []byte("public")
defaultLogDir = filepath.Join(lnwalletHomeDir, defaultLogDirname)
walletDbName = "lnwallet.db"
)
// filesExists reports whether the named file or directory exists.
func fileExists(name string) bool {
if _, err := os.Stat(name); err != nil {

@ -228,6 +228,8 @@ type LightningWallet struct {
// TODO(roasbeef): zombie garbage collection routine to solve
// lost-object/starvation problem/attack.
cfg *Config
started int32
shutdown int32
quit chan struct{}
@ -241,16 +243,16 @@ type LightningWallet struct {
// If the wallet has never been created (according to the passed dataDir), first-time
// setup is executed.
// TODO(roasbeef): fin...add config
func NewLightningWallet(privWalletPass, pubWalletPass, hdSeed []byte, dataDir string) (*LightningWallet, error) {
func NewLightningWallet(config *Config) (*LightningWallet, error) {
// Ensure the wallet exists or create it when the create flag is set.
netDir := networkDir(dataDir, ActiveNetParams)
netDir := networkDir(config.DataDir, ActiveNetParams)
dbPath := filepath.Join(netDir, walletDbName)
var pubPass []byte
if pubWalletPass == nil {
if config.PublicPass == nil {
pubPass = defaultPubPassphrase
} else {
pubPass = pubWalletPass
pubPass = config.PublicPass
}
// Wallet has never been created, perform initial set up.
@ -262,7 +264,8 @@ func NewLightningWallet(privWalletPass, pubWalletPass, hdSeed []byte, dataDir st
}
// Attempt to create a new wallet
if err := createWallet(privWalletPass, pubPass, hdSeed, dbPath); err != nil {
if err := createWallet(config.PrivatePass, pubPass,
config.HdSeed, dbPath); err != nil {
fmt.Fprintln(os.Stderr, err)
return nil, err
}
@ -294,6 +297,7 @@ func NewLightningWallet(privWalletPass, pubWalletPass, hdSeed []byte, dataDir st
// faster, locks or CAS? I'm guessing CAS because assembly:
// * https://golang.org/src/sync/atomic/asm_amd64.s
nextFundingID: 0,
cfg: config,
fundingLimbo: make(map[uint64]*ChannelReservation),
quit: make(chan struct{}),
}, nil
@ -309,7 +313,7 @@ func (l *LightningWallet) Startup() error {
// TODO(roasbeef): config...
rpcc, err := chain.NewClient(ActiveNetParams,
"host", "user", "pass", []byte("cert"), true)
l.cfg.RpcHost, l.cfg.RpcUser, l.cfg.RpcPass, l.cfg.CACert, true)
if err != nil {
return err
}

@ -299,7 +299,9 @@ func createTestWallet() (string, *LightningWallet, error) {
return "", nil, nil
}
wallet, err := NewLightningWallet(privPass, nil, testHdSeed[:], tempTestDir)
config := &Config{PrivatePass: privPass, HdSeed: testHdSeed[:],
DataDir: tempTestDir}
wallet, err := NewLightningWallet(config)
if err != nil {
return "", nil, err
}