Generate a seed when creating a new wallet if none was provided.

Previously, if a nil seed was passed into loader.CreateNewWallet, a
random seed was never generated. This would cause an error within the
waddrmgr due to the seed being of invalid (0) length.
This commit is contained in:
Olaoluwa Osuntokun 2016-01-31 13:34:46 -08:00
parent bb1102b414
commit 4c839ae3d3

View file

@ -110,14 +110,24 @@ func (l *Loader) CreateNewWallet(pubPassphrase, privPassphrase, seed []byte) (*W
return nil, err
}
// Create the address manager.
// If a seed was provided, ensure that it is of valid length. Otherwise,
// we generate a random seed for the wallet with the recommended seed
// length.
if seed != nil {
if len(seed) < hdkeychain.MinSeedBytes ||
len(seed) > hdkeychain.MaxSeedBytes {
return nil, hdkeychain.ErrInvalidSeedLen
}
} else {
hdSeed, err := hdkeychain.GenerateSeed(hdkeychain.RecommendedSeedLen)
if err != nil {
return nil, err
}
seed = hdSeed
}
// Create the address manager.
addrMgrNamespace, err := db.Namespace(waddrmgrNamespaceKey)
if err != nil {
return nil, err