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
This commit is contained in:
Martin Holst Swende 2020-09-08 13:07:55 +02:00 committed by GitHub
parent d54f2f2e5e
commit 8327d1fdfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 16 deletions

View File

@ -368,18 +368,22 @@ func (w *wallet) selfDerive() {
w.log.Warn("USB wallet nonce retrieval failed", "err", err) w.log.Warn("USB wallet nonce retrieval failed", "err", err)
break break
} }
// If the next account is empty, stop self-derivation, but add for the last base path // We've just self-derived a new account, start tracking it locally
// unless the account was empty.
path := make(accounts.DerivationPath, len(nextPaths[i]))
copy(path[:], nextPaths[i][:])
if balance.Sign() == 0 && nonce == 0 { if balance.Sign() == 0 && nonce == 0 {
empty = true empty = true
// If it indeed was empty, make a log output for it anyway. In the case
// of legacy-ledger, the first account on the legacy-path will
// be shown to the user, even if we don't actively track it
if i < len(nextAddrs)-1 { if i < len(nextAddrs)-1 {
w.log.Info("Skipping trakcking first account on legacy path, use personal.deriveAccount(<url>,<path>, false) to track",
"path", path, "address", nextAddrs[i])
break break
} }
} }
// We've just self-derived a new account, start tracking it locally
path := make(accounts.DerivationPath, len(nextPaths[i]))
copy(path[:], nextPaths[i][:])
paths = append(paths, path) paths = append(paths, path)
account := accounts.Account{ account := accounts.Account{
Address: nextAddrs[i], Address: nextAddrs[i],
URL: accounts.URL{Scheme: w.url.Scheme, Path: fmt.Sprintf("%s/%s", w.url.Path, path)}, URL: accounts.URL{Scheme: w.url.Scheme, Path: fmt.Sprintf("%s/%s", w.url.Path, path)},

View File

@ -346,19 +346,28 @@ func (api *SignerAPI) startUSBListener() {
case accounts.WalletOpened: case accounts.WalletOpened:
status, _ := event.Wallet.Status() status, _ := event.Wallet.Status()
log.Info("New wallet appeared", "url", event.Wallet.URL(), "status", status) log.Info("New wallet appeared", "url", event.Wallet.URL(), "status", status)
var derive = func(numToDerive int, base accounts.DerivationPath) {
// Derive first N accounts, hardcoded for now
var nextPath = make(accounts.DerivationPath, len(base))
copy(nextPath[:], base[:])
// Derive first N accounts, hardcoded for now for i := 0; i < numToDerive; i++ {
var nextPath = make(accounts.DerivationPath, len(accounts.DefaultBaseDerivationPath)) acc, err := event.Wallet.Derive(nextPath, true)
copy(nextPath[:], accounts.DefaultBaseDerivationPath[:]) if err != nil {
log.Warn("Account derivation failed", "error", err)
for i := 0; i < numberOfAccountsToDerive; i++ { } else {
acc, err := event.Wallet.Derive(nextPath, true) log.Info("Derived account", "address", acc.Address, "path", nextPath)
if err != nil { }
log.Warn("account derivation failed", "error", err) nextPath[len(nextPath)-1]++
} else {
log.Info("derived account", "address", acc.Address)
} }
nextPath[len(nextPath)-1]++ }
if event.Wallet.URL().Scheme == "ledger" {
log.Info("Deriving ledger default paths")
derive(numberOfAccountsToDerive/2, accounts.DefaultBaseDerivationPath)
log.Info("Deriving ledger legacy paths")
derive(numberOfAccountsToDerive/2, accounts.LegacyLedgerBaseDerivationPath)
} else {
derive(numberOfAccountsToDerive, accounts.DefaultBaseDerivationPath)
} }
case accounts.WalletDropped: case accounts.WalletDropped:
log.Info("Old wallet dropped", "url", event.Wallet.URL()) log.Info("Old wallet dropped", "url", event.Wallet.URL())