mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-26 12:29:06 +01:00
Merge branch 'master' of github.com:MetaMask/metamask-plugin into infura-block-tracker
This commit is contained in:
commit
adb3de5283
@ -1,7 +1,6 @@
|
|||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const EventEmitter = require('events')
|
const EventEmitter = require('events')
|
||||||
const createMetamaskProvider = require('web3-provider-engine/zero.js')
|
const createMetamaskProvider = require('web3-provider-engine/zero.js')
|
||||||
const createInfuraProvider = require('eth-json-rpc-infura/src/createProvider')
|
|
||||||
const ObservableStore = require('obs-store')
|
const ObservableStore = require('obs-store')
|
||||||
const ComposedStore = require('obs-store/lib/composed')
|
const ComposedStore = require('obs-store/lib/composed')
|
||||||
const extend = require('xtend')
|
const extend = require('xtend')
|
||||||
@ -9,7 +8,6 @@ const EthQuery = require('eth-query')
|
|||||||
const createEventEmitterProxy = require('../lib/events-proxy.js')
|
const createEventEmitterProxy = require('../lib/events-proxy.js')
|
||||||
const RPC_ADDRESS_LIST = require('../config.js').network
|
const RPC_ADDRESS_LIST = require('../config.js').network
|
||||||
const DEFAULT_RPC = RPC_ADDRESS_LIST['rinkeby']
|
const DEFAULT_RPC = RPC_ADDRESS_LIST['rinkeby']
|
||||||
const INFURA_PROVIDER_TYPES = ['ropsten', 'rinkeby', 'kovan', 'mainnet']
|
|
||||||
|
|
||||||
module.exports = class NetworkController extends EventEmitter {
|
module.exports = class NetworkController extends EventEmitter {
|
||||||
|
|
||||||
@ -26,13 +24,8 @@ module.exports = class NetworkController extends EventEmitter {
|
|||||||
|
|
||||||
initializeProvider (_providerParams) {
|
initializeProvider (_providerParams) {
|
||||||
this._baseProviderParams = _providerParams
|
this._baseProviderParams = _providerParams
|
||||||
const { type, rpcTarget } = this.providerStore.getState()
|
const rpcUrl = this.getCurrentRpcAddress()
|
||||||
// map rpcTarget to rpcUrl
|
this._configureStandardProvider({ rpcUrl })
|
||||||
const opts = {
|
|
||||||
type,
|
|
||||||
rpcUrl: rpcTarget,
|
|
||||||
}
|
|
||||||
this._configureProvider(opts)
|
|
||||||
this._proxy.on('block', this._logBlock.bind(this))
|
this._proxy.on('block', this._logBlock.bind(this))
|
||||||
this._proxy.on('error', this.verifyNetwork.bind(this))
|
this._proxy.on('error', this.verifyNetwork.bind(this))
|
||||||
this.ethQuery = new EthQuery(this._proxy)
|
this.ethQuery = new EthQuery(this._proxy)
|
||||||
@ -90,7 +83,7 @@ module.exports = class NetworkController extends EventEmitter {
|
|||||||
const rpcTarget = this.getRpcAddressForType(type)
|
const rpcTarget = this.getRpcAddressForType(type)
|
||||||
assert(rpcTarget, `NetworkController - unknown rpc address for type "${type}"`)
|
assert(rpcTarget, `NetworkController - unknown rpc address for type "${type}"`)
|
||||||
this.providerStore.updateState({ type, rpcTarget })
|
this.providerStore.updateState({ type, rpcTarget })
|
||||||
this._switchNetwork({ type })
|
this._switchNetwork({ rpcUrl: rpcTarget })
|
||||||
}
|
}
|
||||||
|
|
||||||
getProviderConfig () {
|
getProviderConfig () {
|
||||||
@ -106,50 +99,14 @@ module.exports = class NetworkController extends EventEmitter {
|
|||||||
// Private
|
// Private
|
||||||
//
|
//
|
||||||
|
|
||||||
_switchNetwork (opts) {
|
_switchNetwork (providerParams) {
|
||||||
this.setNetworkState('loading')
|
this.setNetworkState('loading')
|
||||||
this._configureProvider(opts)
|
this._configureStandardProvider(providerParams)
|
||||||
this.emit('networkDidChange')
|
this.emit('networkDidChange')
|
||||||
}
|
}
|
||||||
|
|
||||||
_configureProvider (opts) {
|
_configureStandardProvider (_providerParams) {
|
||||||
// type-based rpc endpoints
|
const providerParams = extend(this._baseProviderParams, _providerParams, {
|
||||||
const { type } = opts
|
|
||||||
if (type) {
|
|
||||||
// type-based infura rpc endpoints
|
|
||||||
const isInfura = INFURA_PROVIDER_TYPES.includes(type)
|
|
||||||
opts.rpcUrl = this.getRpcAddressForType(type)
|
|
||||||
if (isInfura) {
|
|
||||||
this._configureInfuraProvider(opts)
|
|
||||||
// other type-based rpc endpoints
|
|
||||||
} else {
|
|
||||||
this._configureStandardProvider(opts)
|
|
||||||
}
|
|
||||||
// url-based rpc endpoints
|
|
||||||
} else {
|
|
||||||
this._configureStandardProvider(opts)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_configureInfuraProvider (opts) {
|
|
||||||
console.log('_configureInfuraProvider', opts)
|
|
||||||
const blockTrackerProvider = createInfuraProvider({
|
|
||||||
network: opts.type,
|
|
||||||
})
|
|
||||||
const providerParams = extend(this._baseProviderParams, {
|
|
||||||
rpcUrl: opts.rpcUrl,
|
|
||||||
engineParams: {
|
|
||||||
pollingInterval: 8000,
|
|
||||||
blockTrackerProvider,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
const provider = createMetamaskProvider(providerParams)
|
|
||||||
this._setProvider(provider)
|
|
||||||
}
|
|
||||||
|
|
||||||
_configureStandardProvider ({ rpcUrl }) {
|
|
||||||
const providerParams = extend(this._baseProviderParams, {
|
|
||||||
rpcUrl,
|
|
||||||
engineParams: {
|
engineParams: {
|
||||||
pollingInterval: 8000,
|
pollingInterval: 8000,
|
||||||
},
|
},
|
||||||
|
@ -117,8 +117,6 @@ class AccountTracker extends EventEmitter {
|
|||||||
const query = this._query
|
const query = this._query
|
||||||
async.parallel({
|
async.parallel({
|
||||||
balance: query.getBalance.bind(query, address),
|
balance: query.getBalance.bind(query, address),
|
||||||
nonce: query.getTransactionCount.bind(query, address),
|
|
||||||
code: query.getCode.bind(query, address),
|
|
||||||
}, cb)
|
}, cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@
|
|||||||
"valid-url": "^1.0.9",
|
"valid-url": "^1.0.9",
|
||||||
"vreme": "^3.0.2",
|
"vreme": "^3.0.2",
|
||||||
"web3": "^0.20.1",
|
"web3": "^0.20.1",
|
||||||
"web3-provider-engine": "^13.4.0",
|
"web3-provider-engine": "^13.3.4",
|
||||||
"web3-stream-provider": "^3.0.1",
|
"web3-stream-provider": "^3.0.1",
|
||||||
"xtend": "^4.0.1"
|
"xtend": "^4.0.1"
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user