Skip to content

backend/accounts: skip unsupported coins when adding hidden accounts #3432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions backend/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,14 @@ func (backend *Backend) maybeAddHiddenUnusedAccounts() {
coinCodes = []coinpkg.Code{coinpkg.CodeBTC, coinpkg.CodeLTC}
}
for _, coinCode := range coinCodes {
coin, err := backend.Coin(coinCode)
if err != nil {
backend.log.Errorf("could not find coin %s", coinCode)
continue
}
if !backend.keystore.SupportsCoin(coin) {
continue
}
var newAccountCode *accountsTypes.Code
err = backend.config.ModifyAccountsConfig(func(cfg *config.AccountsConfig) error {
newAccountCode = do(cfg, coinCode)
Expand All @@ -1509,11 +1517,6 @@ func (backend *Backend) maybeAddHiddenUnusedAccounts() {
continue
}
if newAccountCode != nil {
coin, err := backend.Coin(coinCode)
if err != nil {
backend.log.Errorf("could not find coin %s", coinCode)
continue
}
accountConfig := backend.config.AccountsConfig().Lookup(*newAccountCode)
if accountConfig == nil {
backend.log.Errorf("could not find newly persisted account %s", *newAccountCode)
Expand Down
21 changes: 21 additions & 0 deletions backend/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ func TestNextAccountNumber(t *testing.T) {
fingerprintEmpty := []byte{0x77, 0x77, 0x77, 0x77}
ks := func(fingerprint []byte, supportsMultipleAccounts bool) *keystoremock.KeystoreMock {
return &keystoremock.KeystoreMock{
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
return true
},
RootFingerprintFunc: func() ([]byte, error) {
return fingerprint, nil
},
Expand Down Expand Up @@ -373,6 +376,9 @@ func TestCreateAndPersistAccountConfig(t *testing.T) {
RootFingerprintFunc: func() ([]byte, error) {
return rootFingerprint1, nil
},
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
return true
},
SupportsAccountFunc: func(coin coinpkg.Coin, meta interface{}) bool {
switch coin.(type) {
case *btc.Coin:
Expand Down Expand Up @@ -704,6 +710,9 @@ func TestCreateAndPersistAccountConfig(t *testing.T) {
RootFingerprintFunc: func() ([]byte, error) {
return rootFingerprint1, nil
},
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
return true
},
SupportsAccountFunc: func(coin coinpkg.Coin, meta interface{}) bool {
return true
},
Expand Down Expand Up @@ -950,6 +959,9 @@ func TestTaprootUpgrade(t *testing.T) {
RootFingerprintFunc: func() ([]byte, error) {
return fingerprint, nil
},
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
return true
},
SupportsAccountFunc: func(coin coinpkg.Coin, meta interface{}) bool {
switch coin.(type) {
case *btc.Coin:
Expand All @@ -975,6 +987,9 @@ func TestTaprootUpgrade(t *testing.T) {
RootFingerprintFunc: func() ([]byte, error) {
return fingerprint, nil
},
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
return true
},
SupportsAccountFunc: func(coin coinpkg.Coin, meta interface{}) bool {
switch coin.(type) {
case *btc.Coin:
Expand Down Expand Up @@ -1283,6 +1298,9 @@ func TestWatchonly(t *testing.T) {
RootFingerprintFunc: func() ([]byte, error) {
return rootFingerprint1, nil
},
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
return true
},
SupportsAccountFunc: func(coin coinpkg.Coin, meta interface{}) bool {
switch coin.(type) {
case *btc.Coin:
Expand All @@ -1304,6 +1322,9 @@ func TestWatchonly(t *testing.T) {
RootFingerprintFunc: func() ([]byte, error) {
return rootFingerprint2, nil
},
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
return true
},
SupportsAccountFunc: func(coin coinpkg.Coin, meta interface{}) bool {
switch coin.(type) {
case *btc.Coin:
Expand Down
3 changes: 3 additions & 0 deletions backend/aopp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ func makeKeystore(
RootFingerprintFunc: func() ([]byte, error) {
return rootFingerprint1, nil
},
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
return true
},
SupportsAccountFunc: func(coin coinpkg.Coin, meta interface{}) bool {
switch coin.(type) {
case *btc.Coin:
Expand Down
12 changes: 12 additions & 0 deletions backend/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ func makeBitBox02Multi() *keystoremock.KeystoreMock {
RootFingerprintFunc: func() ([]byte, error) {
return rootFingerprint1, nil
},
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
return true
},
SupportsAccountFunc: func(coin coinpkg.Coin, meta interface{}) bool {
switch coin.(type) {
case *btc.Coin:
Expand All @@ -110,6 +113,9 @@ func makeBitBox02Multi() *keystoremock.KeystoreMock {
// accounts, no legacy P2PKH.
func makeBitBox02BTCOnly() *keystoremock.KeystoreMock {
ks := makeBitBox02Multi()
ks.SupportsCoinFunc = func(coin coinpkg.Coin) bool {
return coin.Code() == coinpkg.CodeBTC || coin.Code() == coinpkg.CodeTBTC || coin.Code() == coinpkg.CodeRBTC
}
ks.SupportsAccountFunc = func(coin coinpkg.Coin, meta interface{}) bool {
switch coin.(type) {
case *btc.Coin:
Expand Down Expand Up @@ -340,6 +346,9 @@ func TestRegisterKeystore(t *testing.T) {
RootFingerprintFunc: func() ([]byte, error) {
return rootFingerprint1, nil
},
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
return true
},
SupportsAccountFunc: func(coin coinpkg.Coin, meta interface{}) bool {
switch coin.(type) {
case *btc.Coin:
Expand All @@ -361,6 +370,9 @@ func TestRegisterKeystore(t *testing.T) {
RootFingerprintFunc: func() ([]byte, error) {
return rootFingerprint2, nil
},
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
return true
},
SupportsAccountFunc: func(coin coinpkg.Coin, meta interface{}) bool {
switch coin.(type) {
case *btc.Coin:
Expand Down