mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-30 18:43:42 +02:00
lnwallet: add dirty config
This commit is contained in:
@ -30,7 +30,6 @@ import (
|
|||||||
|
|
||||||
"github.com/btcsuite/btcd/chaincfg"
|
"github.com/btcsuite/btcd/chaincfg"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
|
||||||
"github.com/btcsuite/btcutil/hdkeychain"
|
"github.com/btcsuite/btcutil/hdkeychain"
|
||||||
"github.com/btcsuite/btcwallet/waddrmgr"
|
"github.com/btcsuite/btcwallet/waddrmgr"
|
||||||
"github.com/btcsuite/btcwallet/wallet"
|
"github.com/btcsuite/btcwallet/wallet"
|
||||||
@ -38,25 +37,6 @@ import (
|
|||||||
_ "github.com/btcsuite/btcwallet/walletdb/bdb"
|
_ "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.
|
// filesExists reports whether the named file or directory exists.
|
||||||
func fileExists(name string) bool {
|
func fileExists(name string) bool {
|
||||||
if _, err := os.Stat(name); err != nil {
|
if _, err := os.Stat(name); err != nil {
|
||||||
|
@ -228,6 +228,8 @@ type LightningWallet struct {
|
|||||||
// TODO(roasbeef): zombie garbage collection routine to solve
|
// TODO(roasbeef): zombie garbage collection routine to solve
|
||||||
// lost-object/starvation problem/attack.
|
// lost-object/starvation problem/attack.
|
||||||
|
|
||||||
|
cfg *Config
|
||||||
|
|
||||||
started int32
|
started int32
|
||||||
shutdown int32
|
shutdown int32
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
@ -241,16 +243,16 @@ type LightningWallet struct {
|
|||||||
// If the wallet has never been created (according to the passed dataDir), first-time
|
// If the wallet has never been created (according to the passed dataDir), first-time
|
||||||
// setup is executed.
|
// setup is executed.
|
||||||
// TODO(roasbeef): fin...add config
|
// 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.
|
// 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)
|
dbPath := filepath.Join(netDir, walletDbName)
|
||||||
|
|
||||||
var pubPass []byte
|
var pubPass []byte
|
||||||
if pubWalletPass == nil {
|
if config.PublicPass == nil {
|
||||||
pubPass = defaultPubPassphrase
|
pubPass = defaultPubPassphrase
|
||||||
} else {
|
} else {
|
||||||
pubPass = pubWalletPass
|
pubPass = config.PublicPass
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wallet has never been created, perform initial set up.
|
// 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
|
// 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)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
return nil, 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:
|
// faster, locks or CAS? I'm guessing CAS because assembly:
|
||||||
// * https://golang.org/src/sync/atomic/asm_amd64.s
|
// * https://golang.org/src/sync/atomic/asm_amd64.s
|
||||||
nextFundingID: 0,
|
nextFundingID: 0,
|
||||||
|
cfg: config,
|
||||||
fundingLimbo: make(map[uint64]*ChannelReservation),
|
fundingLimbo: make(map[uint64]*ChannelReservation),
|
||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
}, nil
|
}, nil
|
||||||
@ -309,7 +313,7 @@ func (l *LightningWallet) Startup() error {
|
|||||||
// TODO(roasbeef): config...
|
// TODO(roasbeef): config...
|
||||||
|
|
||||||
rpcc, err := chain.NewClient(ActiveNetParams,
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -299,7 +299,9 @@ func createTestWallet() (string, *LightningWallet, error) {
|
|||||||
return "", nil, nil
|
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 {
|
if err != nil {
|
||||||
return "", nil, err
|
return "", nil, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user