Skip to content

Commit 9a41336

Browse files
committed
backend/accounts: skip unsupported coins when adding hidden accounts
With a BB02 BTC-only version, the log showed attempts to add LTC accounts, which were then skipped as unsupported. We can abort earlier in this case, which prevents the log from showing 'automatically created hidden account' for LTC accounts when LTC is not supported.
1 parent 0be83dd commit 9a41336

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

backend/accounts.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,14 @@ func (backend *Backend) maybeAddHiddenUnusedAccounts() {
14961496
coinCodes = []coinpkg.Code{coinpkg.CodeBTC, coinpkg.CodeLTC}
14971497
}
14981498
for _, coinCode := range coinCodes {
1499+
coin, err := backend.Coin(coinCode)
1500+
if err != nil {
1501+
backend.log.Errorf("could not find coin %s", coinCode)
1502+
continue
1503+
}
1504+
if !backend.keystore.SupportsCoin(coin) {
1505+
continue
1506+
}
14991507
var newAccountCode *accountsTypes.Code
15001508
err = backend.config.ModifyAccountsConfig(func(cfg *config.AccountsConfig) error {
15011509
newAccountCode = do(cfg, coinCode)
@@ -1509,11 +1517,6 @@ func (backend *Backend) maybeAddHiddenUnusedAccounts() {
15091517
continue
15101518
}
15111519
if newAccountCode != nil {
1512-
coin, err := backend.Coin(coinCode)
1513-
if err != nil {
1514-
backend.log.Errorf("could not find coin %s", coinCode)
1515-
continue
1516-
}
15171520
accountConfig := backend.config.AccountsConfig().Lookup(*newAccountCode)
15181521
if accountConfig == nil {
15191522
backend.log.Errorf("could not find newly persisted account %s", *newAccountCode)

backend/accounts_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ func TestNextAccountNumber(t *testing.T) {
208208
fingerprintEmpty := []byte{0x77, 0x77, 0x77, 0x77}
209209
ks := func(fingerprint []byte, supportsMultipleAccounts bool) *keystoremock.KeystoreMock {
210210
return &keystoremock.KeystoreMock{
211+
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
212+
return true
213+
},
211214
RootFingerprintFunc: func() ([]byte, error) {
212215
return fingerprint, nil
213216
},
@@ -373,6 +376,9 @@ func TestCreateAndPersistAccountConfig(t *testing.T) {
373376
RootFingerprintFunc: func() ([]byte, error) {
374377
return rootFingerprint1, nil
375378
},
379+
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
380+
return true
381+
},
376382
SupportsAccountFunc: func(coin coinpkg.Coin, meta interface{}) bool {
377383
switch coin.(type) {
378384
case *btc.Coin:
@@ -704,6 +710,9 @@ func TestCreateAndPersistAccountConfig(t *testing.T) {
704710
RootFingerprintFunc: func() ([]byte, error) {
705711
return rootFingerprint1, nil
706712
},
713+
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
714+
return true
715+
},
707716
SupportsAccountFunc: func(coin coinpkg.Coin, meta interface{}) bool {
708717
return true
709718
},
@@ -950,6 +959,9 @@ func TestTaprootUpgrade(t *testing.T) {
950959
RootFingerprintFunc: func() ([]byte, error) {
951960
return fingerprint, nil
952961
},
962+
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
963+
return true
964+
},
953965
SupportsAccountFunc: func(coin coinpkg.Coin, meta interface{}) bool {
954966
switch coin.(type) {
955967
case *btc.Coin:
@@ -975,6 +987,9 @@ func TestTaprootUpgrade(t *testing.T) {
975987
RootFingerprintFunc: func() ([]byte, error) {
976988
return fingerprint, nil
977989
},
990+
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
991+
return true
992+
},
978993
SupportsAccountFunc: func(coin coinpkg.Coin, meta interface{}) bool {
979994
switch coin.(type) {
980995
case *btc.Coin:
@@ -1283,6 +1298,9 @@ func TestWatchonly(t *testing.T) {
12831298
RootFingerprintFunc: func() ([]byte, error) {
12841299
return rootFingerprint1, nil
12851300
},
1301+
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
1302+
return true
1303+
},
12861304
SupportsAccountFunc: func(coin coinpkg.Coin, meta interface{}) bool {
12871305
switch coin.(type) {
12881306
case *btc.Coin:
@@ -1304,6 +1322,9 @@ func TestWatchonly(t *testing.T) {
13041322
RootFingerprintFunc: func() ([]byte, error) {
13051323
return rootFingerprint2, nil
13061324
},
1325+
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
1326+
return true
1327+
},
13071328
SupportsAccountFunc: func(coin coinpkg.Coin, meta interface{}) bool {
13081329
switch coin.(type) {
13091330
case *btc.Coin:

backend/aopp_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ func makeKeystore(
6363
RootFingerprintFunc: func() ([]byte, error) {
6464
return rootFingerprint1, nil
6565
},
66+
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
67+
return true
68+
},
6669
SupportsAccountFunc: func(coin coinpkg.Coin, meta interface{}) bool {
6770
switch coin.(type) {
6871
case *btc.Coin:

backend/backend_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ func makeBitBox02Multi() *keystoremock.KeystoreMock {
8787
RootFingerprintFunc: func() ([]byte, error) {
8888
return rootFingerprint1, nil
8989
},
90+
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
91+
return true
92+
},
9093
SupportsAccountFunc: func(coin coinpkg.Coin, meta interface{}) bool {
9194
switch coin.(type) {
9295
case *btc.Coin:
@@ -110,6 +113,9 @@ func makeBitBox02Multi() *keystoremock.KeystoreMock {
110113
// accounts, no legacy P2PKH.
111114
func makeBitBox02BTCOnly() *keystoremock.KeystoreMock {
112115
ks := makeBitBox02Multi()
116+
ks.SupportsCoinFunc = func(coin coinpkg.Coin) bool {
117+
return coin.Code() == coinpkg.CodeBTC || coin.Code() == coinpkg.CodeTBTC || coin.Code() == coinpkg.CodeRBTC
118+
}
113119
ks.SupportsAccountFunc = func(coin coinpkg.Coin, meta interface{}) bool {
114120
switch coin.(type) {
115121
case *btc.Coin:
@@ -340,6 +346,9 @@ func TestRegisterKeystore(t *testing.T) {
340346
RootFingerprintFunc: func() ([]byte, error) {
341347
return rootFingerprint1, nil
342348
},
349+
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
350+
return true
351+
},
343352
SupportsAccountFunc: func(coin coinpkg.Coin, meta interface{}) bool {
344353
switch coin.(type) {
345354
case *btc.Coin:
@@ -361,6 +370,9 @@ func TestRegisterKeystore(t *testing.T) {
361370
RootFingerprintFunc: func() ([]byte, error) {
362371
return rootFingerprint2, nil
363372
},
373+
SupportsCoinFunc: func(coin coinpkg.Coin) bool {
374+
return true
375+
},
364376
SupportsAccountFunc: func(coin coinpkg.Coin, meta interface{}) bool {
365377
switch coin.(type) {
366378
case *btc.Coin:

0 commit comments

Comments
 (0)