pass db-path+hd-seed into wallet init
This commit is contained in:
parent
b023120460
commit
1d1ba454f4
@ -107,9 +107,10 @@ func checkCreateDir(path string) error {
|
||||
// createWallet generates a new wallet. The new wallet will reside at the
|
||||
// provided path.
|
||||
// TODO(roasbeef): maybe pass in config after all for testing purposes?
|
||||
func createWallet(privPass []byte, pubPass []byte, userSeed []byte) error {
|
||||
func createWallet(privPass, pubPass, userSeed []byte,
|
||||
dbPath string) error {
|
||||
// TODO(roasbeef): replace with tadge's seed format?
|
||||
var hdSeed []byte
|
||||
hdSeed := userSeed
|
||||
var seedErr error
|
||||
if userSeed == nil {
|
||||
hdSeed, seedErr = hdkeychain.GenerateSeed(hdkeychain.RecommendedSeedLen)
|
||||
@ -119,8 +120,6 @@ func createWallet(privPass []byte, pubPass []byte, userSeed []byte) error {
|
||||
}
|
||||
|
||||
// Create the wallet.
|
||||
netDir := networkDir(defaultDataDir, ActiveNetParams)
|
||||
dbPath := filepath.Join(netDir, walletDbName)
|
||||
fmt.Println("Creating the wallet...")
|
||||
|
||||
// Create the wallet database backed by bolt db.
|
||||
@ -209,10 +208,8 @@ func promptPrivPassPhrase() ([]byte, error) {
|
||||
// openWallet returns a wallet. The function handles opening an existing wallet
|
||||
// database, the address manager and the transaction store and uses the values
|
||||
// to open a wallet.Wallet
|
||||
func openWallet(pubPass []byte) (*wallet.Wallet, walletdb.DB, error) {
|
||||
netdir := networkDir(defaultDataDir, ActiveNetParams)
|
||||
|
||||
db, err := openDb(netdir, walletDbName)
|
||||
func openWallet(pubPass []byte, dbDir string) (*wallet.Wallet, walletdb.DB, error) {
|
||||
db, err := openDb(dbDir, walletDbName)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("Failed to open database: %v", err)
|
||||
}
|
||||
|
@ -163,8 +163,8 @@ type LightningWallet struct {
|
||||
}
|
||||
|
||||
// NewLightningWallet...
|
||||
// TODO(roasbeef): fin...
|
||||
func NewLightningWallet(privWalletPass, pubWalletPass []byte) (*LightningWallet, error) {
|
||||
// TODO(roasbeef): fin...add config
|
||||
func NewLightningWallet(privWalletPass, pubWalletPass, hdSeed []byte, dataDir string) (*LightningWallet, error) {
|
||||
// Ensure the wallet exists or create it when the create flag is set.
|
||||
netDir := networkDir(defaultDataDir, ActiveNetParams)
|
||||
dbPath := filepath.Join(netDir, walletDbName)
|
||||
@ -178,6 +178,7 @@ func NewLightningWallet(privWalletPass, pubWalletPass []byte) (*LightningWallet,
|
||||
|
||||
// Wallet has never been created, perform initial set up.
|
||||
if !fileExists(dbPath) {
|
||||
fmt.Println("wallet doesn't exist, creating")
|
||||
// Ensure the data directory for the network exists.
|
||||
if err := checkCreateDir(netDir); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
@ -185,8 +186,7 @@ func NewLightningWallet(privWalletPass, pubWalletPass []byte) (*LightningWallet,
|
||||
}
|
||||
|
||||
// Attempt to create a new wallet
|
||||
// TODO(roasbeef): optionally accept userseed from constructor
|
||||
if err := createWallet(privWalletPass, pubPass, nil); err != nil {
|
||||
if err := createWallet(privWalletPass, pubPass, hdSeed, dbPath); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
return nil, err
|
||||
}
|
||||
@ -194,7 +194,7 @@ func NewLightningWallet(privWalletPass, pubWalletPass []byte) (*LightningWallet,
|
||||
|
||||
// Wallet has been created and been initialized at this point, open it
|
||||
// along with all the required DB namepsaces, and the DB itself.
|
||||
wallet, db, err := openWallet(pubPass)
|
||||
wallet, db, err := openWallet(pubPass, netDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user