mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-05 17:05:50 +02:00
walletrpc+btcwallet: no custom account with various key scopes
Currently, a user can create a custom account with various key scopes. This is not a desired behaviour.
This commit is contained in:
@@ -843,6 +843,10 @@ func (b *BtcWallet) ListAddresses(name string,
|
||||
// The address type can usually be inferred from the key's version, but may be
|
||||
// required for certain keys to map them into the proper scope.
|
||||
//
|
||||
// For custom accounts, we will first check if there is no account with the same
|
||||
// name (even with a different key scope). No custom account should have various
|
||||
// key scopes as it will result in non-deterministic behaviour.
|
||||
//
|
||||
// For BIP-0044 keys, an address type must be specified as we intend to not
|
||||
// support importing BIP-0044 keys into the wallet using the legacy
|
||||
// pay-to-pubkey-hash (P2PKH) scheme. A nested witness address type will force
|
||||
@@ -860,6 +864,22 @@ func (b *BtcWallet) ImportAccount(name string, accountPubKey *hdkeychain.Extende
|
||||
dryRun bool) (*waddrmgr.AccountProperties, []btcutil.Address,
|
||||
[]btcutil.Address, error) {
|
||||
|
||||
// For custom accounts, we first check if there is no existing account
|
||||
// with the same name.
|
||||
if name != lnwallet.DefaultAccountName &&
|
||||
name != waddrmgr.ImportedAddrAccountName {
|
||||
|
||||
_, err := b.ListAccounts(name, nil)
|
||||
if err == nil {
|
||||
return nil, nil, nil,
|
||||
fmt.Errorf("account '%s' already exists",
|
||||
name)
|
||||
}
|
||||
if !waddrmgr.IsError(err, waddrmgr.ErrAccountNotFound) {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if !dryRun {
|
||||
accountProps, err := b.wallet.ImportAccount(
|
||||
name, accountPubKey, masterKeyFingerprint, addrType,
|
||||
|
Reference in New Issue
Block a user