Browse Source

ETH/ETC: always scan 9 empty accounts ahead for better discoverability

master
Gaëtan Renaudeau 7 years ago
parent
commit
aefab0a605
  1. 21
      src/bridge/EthereumJSBridge.js
  2. 18
      src/helpers/derivations.js
  3. 2
      src/logger/logger-storybook.js
  4. 8
      src/logger/logger.js

21
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<Transaction> = {
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<Transaction> = {
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<Transaction> = {
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<Transaction> = {
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
}

18
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}'`

2
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,

8
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)
},

Loading…
Cancel
Save