Merge pull request #83 from MetaMask/revert-82-EtherscanProvider

Revert "Etherscan provider"
feature/default_network_editable
Dan Finlay 9 years ago
commit 888ade6a1d
  1. 3
      app/manifest.json
  2. 21
      app/scripts/background.js
  3. 31
      app/scripts/lib/config-manager.js
  4. 65
      app/scripts/lib/zero.js
  5. 2
      package.json

@ -1,7 +1,6 @@
{ {
"name": "__MSG_appName__", "name": "__MSG_appName__",
"short_name": "Metamask", "version": "1.2.1",
"version": "1.3.0",
"manifest_version": 2, "manifest_version": 2,
"description": "__MSG_appDescription__", "description": "__MSG_appDescription__",
"icons": { "icons": {

@ -6,7 +6,7 @@ const combineStreams = require('pumpify')
const extend = require('xtend') const extend = require('xtend')
const EthStore = require('eth-store') const EthStore = require('eth-store')
const PortStream = require('./lib/port-stream.js') const PortStream = require('./lib/port-stream.js')
const MetaMaskProvider = require('./lib/zero.js') const MetaMaskProvider = require('web3-provider-engine/zero.js')
const IdentityStore = require('./lib/idStore') const IdentityStore = require('./lib/idStore')
const createTxNotification = require('./lib/tx-notification.js') const createTxNotification = require('./lib/tx-notification.js')
const configManager = require('./lib/config-manager-singleton') const configManager = require('./lib/config-manager-singleton')
@ -36,9 +36,8 @@ function handleEthRpcRequestStream(stream){
// state and network // state and network
// //
var providerConfig = configManager.getProvider()
var idStore = new IdentityStore() var idStore = new IdentityStore()
var providerOpts = { var zeroClient = MetaMaskProvider({
rpcUrl: configManager.getCurrentRpcAddress(), rpcUrl: configManager.getCurrentRpcAddress(),
getAccounts: function(cb){ getAccounts: function(cb){
var selectedAddress = idStore.getSelectedAddress() var selectedAddress = idStore.getSelectedAddress()
@ -47,16 +46,14 @@ var providerOpts = {
}, },
approveTransaction: addUnconfirmedTx, approveTransaction: addUnconfirmedTx,
signTransaction: idStore.signTransaction.bind(idStore), signTransaction: idStore.signTransaction.bind(idStore),
etherscan: providerConfig.type === 'etherscan', })
}
var provider = MetaMaskProvider(providerOpts)
// log new blocks // log new blocks
provider.on('block', function(block){ zeroClient.on('block', function(block){
console.log('BLOCK CHANGED:', '#'+block.number.toString('hex'), '0x'+block.hash.toString('hex')) console.log('BLOCK CHANGED:', '#'+block.number.toString('hex'), '0x'+block.hash.toString('hex'))
}) })
var ethStore = new EthStore(provider) var ethStore = new EthStore(zeroClient)
idStore.setStore(ethStore) idStore.setStore(ethStore)
function getState(){ function getState(){
@ -71,7 +68,7 @@ function getState(){
// handle rpc requests // handle rpc requests
function onRpcRequest(remoteStream, payload){ function onRpcRequest(remoteStream, payload){
// console.log('MetaMaskPlugin - incoming payload:', payload) // console.log('MetaMaskPlugin - incoming payload:', payload)
provider.sendAsync(payload, function onPayloadHandled(err, response){ zeroClient.sendAsync(payload, function onPayloadHandled(err, response){
// provider engine errors are included in response objects // provider engine errors are included in response objects
if (!payload.isMetamaskInternal) console.log('MetaMaskPlugin - RPC complete:', payload, '->', response) if (!payload.isMetamaskInternal) console.log('MetaMaskPlugin - RPC complete:', payload, '->', response)
try { try {
@ -114,7 +111,6 @@ function linkDnode(stream){
var connection = Dnode({ var connection = Dnode({
getState: function(cb){ cb(null, getState()) }, getState: function(cb){ cb(null, getState()) },
setRpcTarget: setRpcTarget, setRpcTarget: setRpcTarget,
useEtherscanProvider: useEtherscanProvider,
// forward directly to idStore // forward directly to idStore
createNewVault: idStore.createNewVault.bind(idStore), createNewVault: idStore.createNewVault.bind(idStore),
recoverFromSeed: idStore.recoverFromSeed.bind(idStore), recoverFromSeed: idStore.recoverFromSeed.bind(idStore),
@ -183,11 +179,6 @@ function setRpcTarget(rpcTarget){
chrome.runtime.reload() chrome.runtime.reload()
} }
function useEtherscanProvider() {
configManager.useEtherscanProvider()
chrome.runtime.reload()
}
// util // util
function jsonParseStream(){ function jsonParseStream(){

@ -47,6 +47,15 @@ ConfigManager.prototype.setConfig = function(config) {
this.setData(data) this.setData(data)
} }
ConfigManager.prototype.setRpcTarget = function(rpcUrl) {
var config = this.getConfig()
config.provider = {
type: 'rpc',
rpcTarget: rpcUrl,
}
this.setConfig(config)
}
ConfigManager.prototype.getConfig = function() { ConfigManager.prototype.getConfig = function() {
var data = this.migrator.getData() var data = this.migrator.getData()
if ('config' in data) { if ('config' in data) {
@ -61,28 +70,6 @@ ConfigManager.prototype.getConfig = function() {
} }
} }
ConfigManager.prototype.setRpcTarget = function(rpcUrl) {
var config = this.getConfig()
config.provider = {
type: 'rpc',
rpcTarget: rpcUrl,
}
this.setConfig(config)
}
ConfigManager.prototype.useEtherscanProvider = function() {
var config = this.getConfig()
config.provider = {
type: 'etherscan',
}
this.setConfig(config)
}
ConfigManager.prototype.getProvider = function() {
var config = this.getConfig()
return config.provider
}
ConfigManager.prototype.setData = function(data) { ConfigManager.prototype.setData = function(data) {
this.migrator.saveData(data) this.migrator.saveData(data)
} }

@ -1,65 +0,0 @@
const ProviderEngine = require('web3-provider-engine/index.js')
const DefaultFixture = require('web3-provider-engine/subproviders/default-fixture.js')
const NonceTrackerSubprovider = require('web3-provider-engine/subproviders/nonce-tracker.js')
const CacheSubprovider = require('web3-provider-engine/subproviders/cache.js')
const FilterSubprovider = require('web3-provider-engine/subproviders/filters.js')
const HookedWalletSubprovider = require('web3-provider-engine/subproviders/hooked-wallet.js')
const RpcSubprovider = require('web3-provider-engine/subproviders/rpc.js')
const EtherscanSubprovider = require('web3-provider-engine/subproviders/etherscan.js')
module.exports = ZeroClientProvider
function ZeroClientProvider(opts){
opts = opts || {}
var engine = new ProviderEngine()
// static
var staticSubprovider = new DefaultFixture()
engine.addProvider(staticSubprovider)
// nonce tracker
engine.addProvider(new NonceTrackerSubprovider())
// cache layer
var cacheSubprovider = new CacheSubprovider()
engine.addProvider(cacheSubprovider)
// filters
var filterSubprovider = new FilterSubprovider()
engine.addProvider(filterSubprovider)
// id mgmt
var idmgmtSubprovider = new HookedWalletSubprovider({
getAccounts: opts.getAccounts,
approveTransaction: opts.approveTransaction,
signTransaction: opts.signTransaction,
})
engine.addProvider(idmgmtSubprovider)
// data source
var dataProvider
if (!opts.etherscan) {
dataProvider = new RpcSubprovider({
rpcUrl: opts.rpcUrl || 'https://testrpc.metamask.io/',
})
} else {
dataProvider = new EtherscanSubprovider()
}
engine.addProvider(dataProvider)
// // log new blocks
// engine.on('block', function(block){
// console.log('================================')
// console.log('BLOCK CHANGED:', '#'+block.number.toString('hex'), '0x'+block.hash.toString('hex'))
// console.log('================================')
// })
// start polling
engine.start()
return engine
}

@ -27,7 +27,7 @@
"readable-stream": "^2.0.5", "readable-stream": "^2.0.5",
"through2": "^2.0.1", "through2": "^2.0.1",
"web3": "^0.15.1", "web3": "^0.15.1",
"web3-provider-engine": "^7.2.1", "web3-provider-engine": "^7.0.0",
"xtend": "^4.0.1" "xtend": "^4.0.1"
}, },
"devDependencies": { "devDependencies": {

Loading…
Cancel
Save