Skip to content

Commit ea13541

Browse files
committed
Merge remote-tracking branch 'benma/regression'
2 parents 46e34b2 + 2335f10 commit ea13541

File tree

3 files changed

+48
-40
lines changed

3 files changed

+48
-40
lines changed

backend/accounts.go

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,35 +1073,9 @@ func (backend *Backend) maybeAddP2TR(keystore keystore.Keystore, accounts []*con
10731073
// perform migrations, updates etc. We use it to add taproot subaccounts to Bitcoin accounts that
10741074
// were created (persisted) before the introduction of taproot support.
10751075
func (backend *Backend) updatePersistedAccounts(
1076-
keystore keystore.Keystore, accountsConfig *config.AccountsConfig) error {
1076+
keystore keystore.Keystore, accounts []*config.Account) error {
10771077

1078-
// setWatch, if the keystore Watchonly flag is enabled, sets the `Watch`
1079-
// flag to `true`, turning this account into a watch-only account.
1080-
setWatch := func() error {
1081-
rootFingerprint, err := keystore.RootFingerprint()
1082-
if err != nil {
1083-
return err
1084-
}
1085-
if !accountsConfig.IsKeystoreWatchonly(rootFingerprint) {
1086-
return nil
1087-
}
1088-
for _, account := range accountsConfig.Accounts {
1089-
// If the account was added in the background as part of scanning, we don't mark it
1090-
// watchonly. Otherwise the account would appear automatically once it received funds,
1091-
// even if it was not visible before and the keystore is never connected again.
1092-
if !account.HiddenBecauseUnused && account.Watch == nil {
1093-
t := true
1094-
account.Watch = &t
1095-
}
1096-
}
1097-
return nil
1098-
}
1099-
1100-
if err := setWatch(); err != nil {
1101-
return err
1102-
}
1103-
1104-
return backend.maybeAddP2TR(keystore, accountsConfig.Accounts)
1078+
return backend.maybeAddP2TR(keystore, accounts)
11051079
}
11061080

11071081
// The accountsAndKeystoreLock must be held when calling this function.

backend/accounts_test.go

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,16 +1381,6 @@ func TestWatchonly(t *testing.T) {
13811381
// Disable watchonly, all accounts disappear.
13821382
require.NoError(t, b.SetWatchonly(rootFingerprint, false))
13831383
checkShownAccountsLen(t, b, 0, 3)
1384-
1385-
// Re-enable watchonly - accounts do not show up yet.
1386-
require.NoError(t, b.SetWatchonly(rootFingerprint, true))
1387-
checkShownAccountsLen(t, b, 0, 3)
1388-
1389-
// Reconnecting the keystore brings back the watched accounts.
1390-
b.registerKeystore(ks)
1391-
checkShownAccountsLen(t, b, 3, 3)
1392-
b.DeregisterKeystore()
1393-
checkShownAccountsLen(t, b, 3, 3)
13941384
})
13951385

13961386
// Disable keystore's watchonly setting while keystore is connected does not make the accounts
@@ -1533,4 +1523,48 @@ func TestWatchonly(t *testing.T) {
15331523
checkShownAccountsLen(t, b, 3, 6)
15341524
})
15351525

1526+
// Adding new accounts after the keytore has been connected: new account is watched if the
1527+
// keystore is already watched.
1528+
t.Run("", func(t *testing.T) {
1529+
b := newBackend(t, testnetDisabled, regtestDisabled)
1530+
defer b.Close()
1531+
1532+
ks := makeBitBox02Multi()
1533+
1534+
rootFingerprint, err := ks.RootFingerprint()
1535+
require.NoError(t, err)
1536+
1537+
b.registerKeystore(ks)
1538+
checkShownAccountsLen(t, b, 3, 3)
1539+
require.NoError(t, b.SetWatchonly(rootFingerprint, true))
1540+
1541+
// An account may already have been added as part of autodiscover, so we add two.
1542+
newAccountCode1, err := b.CreateAndPersistAccountConfig(
1543+
coinpkg.CodeBTC,
1544+
"Bitcoin account name",
1545+
ks,
1546+
)
1547+
require.NoError(t, err)
1548+
require.Equal(t, accountsTypes.Code("v0-55555555-btc-1"), newAccountCode1)
1549+
1550+
expectedNewAccountCode2 := accountsTypes.Code("v0-55555555-btc-2")
1551+
// Make sure the account to be added has not been added yet (autodiscover), so we know we
1552+
// are testing the correct setting of the Watch flag when a new account is persisted.
1553+
require.Nil(t, b.Config().AccountsConfig().Lookup(expectedNewAccountCode2))
1554+
1555+
newAccountCode2, err := b.CreateAndPersistAccountConfig(
1556+
coinpkg.CodeBTC,
1557+
"Bitcoin account name 2",
1558+
ks,
1559+
)
1560+
require.NoError(t, err)
1561+
require.Equal(t, expectedNewAccountCode2, newAccountCode2)
1562+
1563+
require.NoError(t, err)
1564+
1565+
b.DeregisterKeystore()
1566+
1567+
// Accounts, including the newly added ones, remain loaded.
1568+
checkShownAccountsLen(t, b, 5, 5)
1569+
})
15361570
}

backend/backend.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ func (backend *Backend) registerKeystore(keystore keystore.Keystore) {
640640
// needed on the persisted accounts.
641641
accounts := backend.filterAccounts(accountsConfig, belongsToKeystore)
642642
if len(accounts) != 0 {
643-
return backend.updatePersistedAccounts(keystore, accountsConfig)
643+
return backend.updatePersistedAccounts(keystore, accounts)
644644
}
645645
return backend.persistDefaultAccountConfigs(keystore, accountsConfig)
646646
})
@@ -920,7 +920,7 @@ func (backend *Backend) SetWatchonly(rootFingerprint []byte, watchonly bool) err
920920
return backend.AccountSetWatch(
921921
func(account *config.Account) bool {
922922
// Apply to each currently loaded account.
923-
return accounts.lookup(account.Code) != nil
923+
return !account.HiddenBecauseUnused && accounts.lookup(account.Code) != nil
924924
},
925925
&t,
926926
)

0 commit comments

Comments
 (0)