|
|
@ -41,24 +41,6 @@ module.exports = class NetworkController extends EventEmitter { |
|
|
|
this.emit('networkDidChange') |
|
|
|
this.emit('networkDidChange') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_setProvider (provider) { |
|
|
|
|
|
|
|
// collect old block tracker events
|
|
|
|
|
|
|
|
const oldProvider = this._provider |
|
|
|
|
|
|
|
let blockTrackerHandlers |
|
|
|
|
|
|
|
if (oldProvider) { |
|
|
|
|
|
|
|
// capture old block handlers
|
|
|
|
|
|
|
|
blockTrackerHandlers = oldProvider._blockTracker.proxyEventHandlers |
|
|
|
|
|
|
|
// tear down
|
|
|
|
|
|
|
|
oldProvider.removeAllListeners() |
|
|
|
|
|
|
|
oldProvider.stop() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// override block tracler
|
|
|
|
|
|
|
|
provider._blockTracker = createEventEmitterProxy(provider._blockTracker, blockTrackerHandlers) |
|
|
|
|
|
|
|
// set as new provider
|
|
|
|
|
|
|
|
this._provider = provider |
|
|
|
|
|
|
|
this._proxy.setTarget(provider) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verifyNetwork () { |
|
|
|
verifyNetwork () { |
|
|
|
// Check network when restoring connectivity:
|
|
|
|
// Check network when restoring connectivity:
|
|
|
|
if (this.isNetworkLoading()) this.lookupNetwork() |
|
|
|
if (this.isNetworkLoading()) this.lookupNetwork() |
|
|
@ -112,6 +94,24 @@ module.exports = class NetworkController extends EventEmitter { |
|
|
|
return provider && provider.rpcTarget ? provider.rpcTarget : DEFAULT_RPC |
|
|
|
return provider && provider.rpcTarget ? provider.rpcTarget : DEFAULT_RPC |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_setProvider (provider) { |
|
|
|
|
|
|
|
// collect old block tracker events
|
|
|
|
|
|
|
|
const oldProvider = this._provider |
|
|
|
|
|
|
|
let blockTrackerHandlers |
|
|
|
|
|
|
|
if (oldProvider) { |
|
|
|
|
|
|
|
// capture old block handlers
|
|
|
|
|
|
|
|
blockTrackerHandlers = oldProvider._blockTracker.proxyEventHandlers |
|
|
|
|
|
|
|
// tear down
|
|
|
|
|
|
|
|
oldProvider.removeAllListeners() |
|
|
|
|
|
|
|
oldProvider.stop() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// override block tracler
|
|
|
|
|
|
|
|
provider._blockTracker = createEventEmitterProxy(provider._blockTracker, blockTrackerHandlers) |
|
|
|
|
|
|
|
// set as new provider
|
|
|
|
|
|
|
|
this._provider = provider |
|
|
|
|
|
|
|
this._proxy.setTarget(provider) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_logBlock (block) { |
|
|
|
_logBlock (block) { |
|
|
|
log.info(`BLOCK CHANGED: #${block.number.toString('hex')} 0x${block.hash.toString('hex')}`) |
|
|
|
log.info(`BLOCK CHANGED: #${block.number.toString('hex')} 0x${block.hash.toString('hex')}`) |
|
|
|
this.verifyNetwork() |
|
|
|
this.verifyNetwork() |
|
|
|