Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
fix(neutrino): handle numbers and strings
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed Aug 13, 2018
1 parent 843711c commit 4ca96a9
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions app/lib/lnd/neutrino.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ class Neutrino extends EventEmitter {

if (height) {
this.setState(CHAIN_SYNC_IN_PROGRESS)
this.setLndBlockHeight(Number(height))
this.setLndBlockHeight(height)
}

if (cfilter) {
this.setState(CHAIN_SYNC_IN_PROGRESS)
this.setLndCfilterHeight(Number(cfilter))
this.setLndCfilterHeight(cfilter)
}

// Lnd syncing has completed.
Expand Down Expand Up @@ -248,30 +248,32 @@ class Neutrino extends EventEmitter {
* Set the current block height and emit an event to notify others if it has changed.
* @param {String|Number} height Block height
*/
setCurrentBlockHeight(height: number) {
const changed = Neutrino.incrementIfHigher(this, 'currentBlockHeight', height)
setCurrentBlockHeight(height: number | string) {
const heightAsNumber = Number(height)
const changed = Neutrino.incrementIfHigher(this, 'currentBlockHeight', heightAsNumber)
if (changed) {
this.emit(GOT_CURRENT_BLOCK_HEIGHT, height)
this.emit(GOT_CURRENT_BLOCK_HEIGHT, heightAsNumber)
}
}

/**
* Set the lnd block height and emit an event to notify others if it has changed.
* @param {String|Number} height Block height
*/
setLndBlockHeight(height: number) {
const changed = Neutrino.incrementIfHigher(this, 'lndBlockHeight', height)
setLndBlockHeight(height: number | string) {
const heightAsNumber = Number(height)
const changed = Neutrino.incrementIfHigher(this, 'lndBlockHeight', heightAsNumber)
if (changed) {
this.emit(GOT_LND_BLOCK_HEIGHT, height)
this.setCurrentBlockHeight(height)
this.emit(GOT_LND_BLOCK_HEIGHT, heightAsNumber)
this.setCurrentBlockHeight(heightAsNumber)
}
}

/**
* Set the lnd cfilter height and emit an event to notify others if it has changed.
* @param {String|Number} height Block height
*/
setLndCfilterHeight(height: number) {
setLndCfilterHeight(height: number | string) {
const heightAsNumber = Number(height)
this.lndCfilterHeight = heightAsNumber
this.emit(GOT_LND_CFILTER_HEIGHT, heightAsNumber)
Expand Down

0 comments on commit 4ca96a9

Please sign in to comment.