Skip to content

Commit 57c0982

Browse files
committed
backend/accounts: properly mark discovered accounts as watchonly
Before this commit, accounts that are added for scanning in the background (HiddenBecauseUnused) would all be marked watchonly, even though they are not shown to the user yet (the account is only shown if the user manually adds it or if it is found to be non-empty automatically). This way, the account would appear automatically once it received funds, even if it was not visible before and the keystore is never connected again. Instead, it should be marked watchonly when the account is shown to the user and when the keystore is connected, as all other accounts.
1 parent 2baf1ef commit 57c0982

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

backend/accounts.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,13 @@ func (backend *Backend) CreateAndPersistAccountConfig(
406406
if hiddenAccount != nil {
407407
hiddenAccount.HiddenBecauseUnused = false
408408
hiddenAccount.Name = name
409+
// We only really show the account to the user now, so this is the moment to set the
410+
// watchonly flag on it if the user has the global watchonly setting enabled.
411+
if backend.config.AppConfig().Backend.Watchonly {
412+
t := true
413+
hiddenAccount.Watch = &t
414+
}
415+
409416
accountCode = hiddenAccount.Code
410417
return nil
411418
}
@@ -756,7 +763,10 @@ func (backend *Backend) persistBTCAccountConfig(
756763
}
757764

758765
var accountWatch *bool
759-
if backend.config.AppConfig().Backend.Watchonly {
766+
// If the account was added in the background as part of scanning, we don't mark it watchonly.
767+
// Otherwise the account would appear automatically once it received funds, even if it was not
768+
// visible before and the keystore is never connected again.
769+
if !hiddenBecauseUnused && backend.config.AppConfig().Backend.Watchonly {
760770
t := true
761771
accountWatch = &t
762772
}
@@ -858,7 +868,7 @@ func (backend *Backend) persistETHAccountConfig(
858868
}
859869

860870
var accountWatch *bool
861-
if backend.config.AppConfig().Backend.Watchonly {
871+
if !hiddenBecauseUnused && backend.config.AppConfig().Backend.Watchonly {
862872
t := true
863873
accountWatch = &t
864874
}
@@ -1055,7 +1065,10 @@ func (backend *Backend) updatePersistedAccounts(
10551065
return nil
10561066
}
10571067
for _, account := range accounts {
1058-
if account.Watch == nil {
1068+
// If the account was added in the background as part of scanning, we don't mark it
1069+
// watchonly. Otherwise the account would appear automatically once it received funds,
1070+
// even if it was not visible before and the keystore is never connected again.
1071+
if !account.HiddenBecauseUnused && account.Watch == nil {
10591072
t := true
10601073
account.Watch = &t
10611074
}
@@ -1281,6 +1294,14 @@ func (backend *Backend) checkAccountUsed(account accounts.Interface) {
12811294
}
12821295
acct.Used = true
12831296
acct.HiddenBecauseUnused = false
1297+
1298+
// We only really show the account to the user now, so this is the moment to set the
1299+
// watchonly flag on it if the user has the global watchonly setting enabled.
1300+
if backend.config.AppConfig().Backend.Watchonly {
1301+
t := true
1302+
acct.Watch = &t
1303+
}
1304+
12841305
return nil
12851306
})
12861307
if err != nil {

0 commit comments

Comments
 (0)