From aefab0a605a8432cbb5f35a019a9d9c677f857eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Tue, 17 Jul 2018 15:32:10 +0200 Subject: [PATCH] ETH/ETC: always scan 9 empty accounts ahead for better discoverability --- src/bridge/EthereumJSBridge.js | 21 ++++++++++++++++----- src/helpers/derivations.js | 18 +++++++++++------- src/logger/logger-storybook.js | 2 ++ src/logger/logger.js | 8 ++++++++ 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/bridge/EthereumJSBridge.js b/src/bridge/EthereumJSBridge.js index 48972922..3c366449 100644 --- a/src/bridge/EthereumJSBridge.js +++ b/src/bridge/EthereumJSBridge.js @@ -1,5 +1,6 @@ // @flow import { Observable } from 'rxjs' +import logger from 'logger' import React from 'react' import FeesField from 'components/FeesField/EthereumKind' import AdvancedOptions from 'components/AdvancedOptions/EthereumKind' @@ -176,7 +177,7 @@ const EthereumBridge: WalletBridge = { index, { address, path: freshAddressPath, publicKey }, isStandard, - mandatoryCount, + shouldSkipEmpty, ): { account?: Account, complete?: boolean } { const balance = await api.getAccountBalance(address) if (finished) return { complete: true } @@ -213,7 +214,7 @@ const EthereumBridge: WalletBridge = { newAccountCount++ } - if (index < mandatoryCount) { + if (shouldSkipEmpty) { return {} } // NB for legacy addresses maybe we will continue at least for the first 10 addresses @@ -254,6 +255,8 @@ const EthereumBridge: WalletBridge = { const last = derivations[derivations.length - 1] for (const derivation of derivations) { const isStandard = last === derivation + let emptyCount = 0 + const mandatoryEmptyAccountSkip = derivation.mandatoryEmptyAccountSkip || 0 for (let index = 0; index < 255; index++) { const freshAddressPath = derivation({ currency, x: index, segwit: false }) const res = await getAddressCommand @@ -263,10 +266,18 @@ const EthereumBridge: WalletBridge = { index, res, isStandard, - // $FlowFixMe i know i know, not part of function - derivation.mandatoryCount || 0, + emptyCount < mandatoryEmptyAccountSkip, ) - if (r.account) o.next(r.account) + logger.log( + `scanning ${currency.id} at ${freshAddressPath}: ${res.address} resulted of ${ + r.account ? `Account with ${r.account.operations.length} txs` : 'no account' + }. ${r.complete ? 'ALL SCANNED' : ''}`, + ) + if (r.account) { + o.next(r.account) + } else { + emptyCount++ + } if (r.complete) { break } diff --git a/src/helpers/derivations.js b/src/helpers/derivations.js index 8579e4f4..f80e0e22 100644 --- a/src/helpers/derivations.js +++ b/src/helpers/derivations.js @@ -1,17 +1,21 @@ // @flow import type { CryptoCurrency } from '@ledgerhq/live-common/lib/types' -type Derivation = ({ - currency: CryptoCurrency, - segwit: boolean, - x: number, -}) => string +type Derivation = { + ({ + currency: CryptoCurrency, + segwit: boolean, + x: number, + }): string, + + mandatoryEmptyAccountSkip?: number, +} const ethLegacyMEW: Derivation = ({ x }) => `44'/60'/0'/${x}` -ethLegacyMEW.mandatoryCount = 5 +ethLegacyMEW.mandatoryEmptyAccountSkip = 10 const etcLegacyMEW: Derivation = ({ x }) => `44'/60'/160720'/${x}'/0` -etcLegacyMEW.mandatoryCount = 5 +etcLegacyMEW.mandatoryEmptyAccountSkip = 10 const rippleLegacy: Derivation = ({ x }) => `44'/144'/0'/${x}'` diff --git a/src/logger/logger-storybook.js b/src/logger/logger-storybook.js index eee5c550..81069e5f 100644 --- a/src/logger/logger-storybook.js +++ b/src/logger/logger-storybook.js @@ -16,6 +16,8 @@ module.exports = { analyticsTrack: noop, analyticsPage: noop, log: noop, + info: noop, + debug: noop, warn: noop, error: noop, critical: noop, diff --git a/src/logger/logger.js b/src/logger/logger.js index 234e017f..13fcdee1 100644 --- a/src/logger/logger.js +++ b/src/logger/logger.js @@ -350,6 +350,14 @@ export default { // General functions in case the hooks don't apply + debug: (...args: any) => { + logger.log('debug', ...args) + }, + + info: (...args: any) => { + logger.log('info', ...args) + }, + log: (...args: any) => { logger.log('info', ...args) },