btcwallet: use already unlocked wallet if available
This commit is contained in:
parent
8f2a8d6682
commit
4cefb6b8dc
@ -81,35 +81,43 @@ func New(cfg Config) (*BtcWallet, error) {
|
|||||||
Coin: cfg.CoinType,
|
Coin: cfg.CoinType,
|
||||||
}
|
}
|
||||||
|
|
||||||
var pubPass []byte
|
// Maybe the wallet has already been opened and unlocked by the
|
||||||
if cfg.PublicPass == nil {
|
// WalletUnlocker. So if we get a non-nil value from the config,
|
||||||
pubPass = defaultPubPassphrase
|
// we assume everything is in order.
|
||||||
} else {
|
var wallet = cfg.Wallet
|
||||||
pubPass = cfg.PublicPass
|
if wallet == nil {
|
||||||
}
|
// No ready wallet was passed, so try to open an existing one.
|
||||||
|
var pubPass []byte
|
||||||
loader := base.NewLoader(cfg.NetParams, netDir, cfg.RecoveryWindow)
|
if cfg.PublicPass == nil {
|
||||||
walletExists, err := loader.WalletExists()
|
pubPass = defaultPubPassphrase
|
||||||
if err != nil {
|
} else {
|
||||||
return nil, err
|
pubPass = cfg.PublicPass
|
||||||
}
|
}
|
||||||
|
loader := base.NewLoader(cfg.NetParams, netDir,
|
||||||
var wallet *base.Wallet
|
cfg.RecoveryWindow)
|
||||||
if !walletExists {
|
walletExists, err := loader.WalletExists()
|
||||||
// Wallet has never been created, perform initial set up.
|
|
||||||
wallet, err = loader.CreateNewWallet(
|
|
||||||
pubPass, cfg.PrivatePass, cfg.HdSeed, cfg.Birthday,
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Wallet has been created and been initialized at this point,
|
if !walletExists {
|
||||||
// open it along with all the required DB namespaces, and the
|
// Wallet has never been created, perform initial
|
||||||
// DB itself.
|
// set up.
|
||||||
wallet, err = loader.OpenExistingWallet(pubPass, false)
|
wallet, err = loader.CreateNewWallet(
|
||||||
if err != nil {
|
pubPass, cfg.PrivatePass, cfg.HdSeed,
|
||||||
return nil, err
|
cfg.Birthday,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Wallet has been created and been initialized at
|
||||||
|
// this point, open it along with all the required DB
|
||||||
|
// namespaces, and the DB itself.
|
||||||
|
wallet, err = loader.OpenExistingWallet(pubPass, false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user