Browse Source

Merge pull request #546 from Empact/log-line-matching

fix: improve lnd log line matching
renovate/lint-staged-8.x
Ben Woosley 6 years ago
committed by GitHub
parent
commit
82cbcf4e84
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .eslintrc
  2. 26
      app/lnd/lib/neutrino.js

1
.eslintrc

@ -46,6 +46,7 @@
"react/require-default-props": 0, "react/require-default-props": 0,
"max-len": ["error", { "code": 120, "ignoreUrls": true }], "max-len": ["error", { "code": 120, "ignoreUrls": true }],
"import/no-extraneous-dependencies": 0, "import/no-extraneous-dependencies": 0,
"no-cond-assign": ["error", "except-parens"],
"no-confusing-arrow": "error", "no-confusing-arrow": "error",
"no-mixed-operators": "error", "no-mixed-operators": "error",
"no-new": 0, "no-new": 0,

26
app/lnd/lib/neutrino.js

@ -77,8 +77,9 @@ class Neutrino extends EventEmitter {
// LND syncing has started. // LND syncing has started.
if (!this.state.chainSyncStarted) { if (!this.state.chainSyncStarted) {
if (line.includes('Syncing to block height')) { const match = line.match(/Syncing to block height (\d+)/)
const height = line.match(/Syncing to block height (\d+)/)[1] if (match) {
const height = match[1]
this.state.chainSyncStarted = true this.state.chainSyncStarted = true
this.state.targetBlockHeight = height this.state.targetBlockHeight = height
this.emit('chain-sync-started') this.emit('chain-sync-started')
@ -96,18 +97,15 @@ class Neutrino extends EventEmitter {
// Pass current block height progress to front end for loading state UX // Pass current block height progress to front end for loading state UX
if (this.state.chainSyncStarted) { if (this.state.chainSyncStarted) {
if (line.includes('Downloading headers for blocks')) { let match
const height = line.match(/Downloading headers for blocks (\d+) to \d+/)[1] if ((match = line.match(/Downloading headers for blocks (\d+) to \d+/))) {
this.emit('got-current-block-height', height) this.emit('got-current-block-height', match[1])
} else if (line.includes('Rescanned through block')) { } else if ((match = line.match(/Rescanned through block.+\(height (\d+)/))) {
const height = line.match(/Rescanned through block.+\(height (\d+)/)[1] this.emit('got-current-block-height', match[1])
this.emit('got-current-block-height', height) } else if ((match = line.match(/Caught up to height (\d+)/))) {
} else if (line.includes('Caught up to height')) { this.emit('got-current-block-height', match[1])
const height = line.match(/Caught up to height (\d+)/)[1] } else if ((match = line.match(/Processed \d* blocks? in the last.+\(height (\d+)/))) {
this.emit('got-current-block-height', height) this.emit('got-current-block-height', match[1])
} else if (line.includes('in the last')) {
const height = line.match(/Processed \d* blocks? in the last.+\(height (\d+)/)[1]
this.emit('got-current-block-height', height)
} }
} }
}) })

Loading…
Cancel
Save