@@ -164,7 +164,10 @@ type Backend struct {
164164 accounts accountsList
165165 // keystore is nil if no keystore is connected.
166166 keystore keystore.Keystore
167- aopp AOPP
167+
168+ connectKeystore connectKeystore
169+
170+ aopp AOPP
168171
169172 // makeBtcAccount creates a BTC account. In production this is `btc.NewAccount`, but can be
170173 // overridden in unit tests for mocking.
@@ -505,7 +508,11 @@ func (backend *Backend) Keystore() keystore.Keystore {
505508func (backend * Backend ) registerKeystore (keystore keystore.Keystore ) {
506509 defer backend .accountsAndKeystoreLock .Lock ()()
507510 // Only for logging, if there is an error we continue anyway.
508- fingerprint , _ := keystore .RootFingerprint ()
511+ fingerprint , err := keystore .RootFingerprint ()
512+ if err != nil {
513+ backend .log .WithError (err ).Error ("could not retrieve keystore fingerprint" )
514+ return
515+ }
509516 log := backend .log .WithField ("rootFingerprint" , fingerprint )
510517 log .Info ("registering keystore" )
511518 backend .keystore = keystore
@@ -515,19 +522,10 @@ func (backend *Backend) registerKeystore(keystore keystore.Keystore) {
515522 })
516523
517524 belongsToKeystore := func (account * config.Account ) bool {
518- fingerprint , err := keystore .RootFingerprint ()
519- if err != nil {
520- log .WithError (err ).Error ("Could not retrieve root fingerprint" )
521- return false
522- }
523525 return account .SigningConfigurations .ContainsRootFingerprint (fingerprint )
524526 }
525527
526528 persistKeystore := func (accountsConfig * config.AccountsConfig ) error {
527- fingerprint , err := keystore .RootFingerprint ()
528- if err != nil {
529- return errp .WithMessage (err , "could not retrieve root fingerprint" )
530- }
531529 keystoreName , err := keystore .Name ()
532530 if err != nil {
533531 return errp .WithMessage (err , "could not retrieve keystore name" )
@@ -538,7 +536,7 @@ func (backend *Backend) registerKeystore(keystore keystore.Keystore) {
538536 return nil
539537 }
540538
541- err : = backend .config .ModifyAccountsConfig (func (accountsConfig * config.AccountsConfig ) error {
539+ err = backend .config .ModifyAccountsConfig (func (accountsConfig * config.AccountsConfig ) error {
542540 // Persist keystore with its name in the config.
543541 if err := persistKeystore (accountsConfig ); err != nil {
544542 log .WithError (err ).Error ("Could not persist keystore" )
@@ -559,6 +557,8 @@ func (backend *Backend) registerKeystore(keystore keystore.Keystore) {
559557 backend .initAccounts (false )
560558
561559 backend .aoppKeystoreRegistered ()
560+
561+ backend .connectKeystore .onConnect (backend .keystore )
562562}
563563
564564// DeregisterKeystore removes the registered keystore.
@@ -784,3 +784,8 @@ func (backend *Backend) GetAccountFromCode(code string) (accounts.Interface, err
784784
785785 return acct , nil
786786}
787+
788+ // CancelConnectKeystore cancels a pending keystore connection request if one exists.
789+ func (backend * Backend ) CancelConnectKeystore () {
790+ backend .connectKeystore .cancel (errUserAbort )
791+ }
0 commit comments