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