Skip to content

Commit 8327d1f

Browse files
authored
accounts/usbwallet, signer/core: show accounts from ledger legacy derivation paths (#21517)
* accounts/usbwallet, signer/core: un-hide accounts from ledger legacy derivation paths * Update accounts/usbwallet/wallet.go * Update signer/core/api.go * Update signer/core/api.go
1 parent d54f2f2 commit 8327d1f

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

accounts/usbwallet/wallet.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,18 +368,22 @@ func (w *wallet) selfDerive() {
368368
w.log.Warn("USB wallet nonce retrieval failed", "err", err)
369369
break
370370
}
371-
// If the next account is empty, stop self-derivation, but add for the last base path
371+
// We've just self-derived a new account, start tracking it locally
372+
// unless the account was empty.
373+
path := make(accounts.DerivationPath, len(nextPaths[i]))
374+
copy(path[:], nextPaths[i][:])
372375
if balance.Sign() == 0 && nonce == 0 {
373376
empty = true
377+
// If it indeed was empty, make a log output for it anyway. In the case
378+
// of legacy-ledger, the first account on the legacy-path will
379+
// be shown to the user, even if we don't actively track it
374380
if i < len(nextAddrs)-1 {
381+
w.log.Info("Skipping trakcking first account on legacy path, use personal.deriveAccount(<url>,<path>, false) to track",
382+
"path", path, "address", nextAddrs[i])
375383
break
376384
}
377385
}
378-
// We've just self-derived a new account, start tracking it locally
379-
path := make(accounts.DerivationPath, len(nextPaths[i]))
380-
copy(path[:], nextPaths[i][:])
381386
paths = append(paths, path)
382-
383387
account := accounts.Account{
384388
Address: nextAddrs[i],
385389
URL: accounts.URL{Scheme: w.url.Scheme, Path: fmt.Sprintf("%s/%s", w.url.Path, path)},

signer/core/api.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -346,19 +346,28 @@ func (api *SignerAPI) startUSBListener() {
346346
case accounts.WalletOpened:
347347
status, _ := event.Wallet.Status()
348348
log.Info("New wallet appeared", "url", event.Wallet.URL(), "status", status)
349-
350-
// Derive first N accounts, hardcoded for now
351-
var nextPath = make(accounts.DerivationPath, len(accounts.DefaultBaseDerivationPath))
352-
copy(nextPath[:], accounts.DefaultBaseDerivationPath[:])
353-
354-
for i := 0; i < numberOfAccountsToDerive; i++ {
355-
acc, err := event.Wallet.Derive(nextPath, true)
356-
if err != nil {
357-
log.Warn("account derivation failed", "error", err)
358-
} else {
359-
log.Info("derived account", "address", acc.Address)
349+
var derive = func(numToDerive int, base accounts.DerivationPath) {
350+
// Derive first N accounts, hardcoded for now
351+
var nextPath = make(accounts.DerivationPath, len(base))
352+
copy(nextPath[:], base[:])
353+
354+
for i := 0; i < numToDerive; i++ {
355+
acc, err := event.Wallet.Derive(nextPath, true)
356+
if err != nil {
357+
log.Warn("Account derivation failed", "error", err)
358+
} else {
359+
log.Info("Derived account", "address", acc.Address, "path", nextPath)
360+
}
361+
nextPath[len(nextPath)-1]++
360362
}
361-
nextPath[len(nextPath)-1]++
363+
}
364+
if event.Wallet.URL().Scheme == "ledger" {
365+
log.Info("Deriving ledger default paths")
366+
derive(numberOfAccountsToDerive/2, accounts.DefaultBaseDerivationPath)
367+
log.Info("Deriving ledger legacy paths")
368+
derive(numberOfAccountsToDerive/2, accounts.LegacyLedgerBaseDerivationPath)
369+
} else {
370+
derive(numberOfAccountsToDerive, accounts.DefaultBaseDerivationPath)
362371
}
363372
case accounts.WalletDropped:
364373
log.Info("Old wallet dropped", "url", event.Wallet.URL())

0 commit comments

Comments
 (0)