diff options
author | Dan Finlay <dan@danfinlay.com> | 2016-04-01 03:30:27 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2016-04-01 03:30:27 +0800 |
commit | 091938a2c5a465582b93a7aff809de126e1319f8 (patch) | |
tree | 6a90bf33bf6785d700e67899cbf210483515190c | |
parent | d9cadb9efbd8a38522ce638b8def37c935bb6be0 (diff) | |
download | tangerine-wallet-browser-091938a2c5a465582b93a7aff809de126e1319f8.tar tangerine-wallet-browser-091938a2c5a465582b93a7aff809de126e1319f8.tar.gz tangerine-wallet-browser-091938a2c5a465582b93a7aff809de126e1319f8.tar.bz2 tangerine-wallet-browser-091938a2c5a465582b93a7aff809de126e1319f8.tar.lz tangerine-wallet-browser-091938a2c5a465582b93a7aff809de126e1319f8.tar.xz tangerine-wallet-browser-091938a2c5a465582b93a7aff809de126e1319f8.tar.zst tangerine-wallet-browser-091938a2c5a465582b93a7aff809de126e1319f8.zip |
Add custom zeroclient that supports etherscan (still not working)
The Etherscan Subprovider is not providing some methods we need, such as `eth_getCode`. I'll probably be enhancing it after lunch.
-rw-r--r-- | app/scripts/background.js | 14 | ||||
-rw-r--r-- | app/scripts/lib/zero.js | 65 |
2 files changed, 68 insertions, 11 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js index cc137616a..14293ab05 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -6,8 +6,7 @@ const combineStreams = require('pumpify') const extend = require('xtend') const EthStore = require('eth-store') const PortStream = require('./lib/port-stream.js') -const MetaMaskProvider = require('web3-provider-engine/zero.js') -const EtherscanProvider = require('web3-provider-engine/subproviders/etherscan') +const MetaMaskProvider = require('./lib/zero.js') const IdentityStore = require('./lib/idStore') const createTxNotification = require('./lib/tx-notification.js') const configManager = require('./lib/config-manager-singleton') @@ -48,16 +47,9 @@ var providerOpts = { }, approveTransaction: addUnconfirmedTx, signTransaction: idStore.signTransaction.bind(idStore), + etherscan: providerConfig.type === 'etherscan', } -var provider -switch (providerConfig.type) { - case 'rpc': - provider = MetaMaskProvider(providerOpts) - break - case 'etherscan': - provider = EtherscanProvider(providerOpts) - break -} +var provider = MetaMaskProvider(providerOpts) // log new blocks provider.on('block', function(block){ diff --git a/app/scripts/lib/zero.js b/app/scripts/lib/zero.js new file mode 100644 index 000000000..d33f099d3 --- /dev/null +++ b/app/scripts/lib/zero.js @@ -0,0 +1,65 @@ +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 + +} |