aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib
diff options
context:
space:
mode:
authorDan Finlay <somniac@me.com>2016-04-01 07:32:35 +0800
committerDan Finlay <somniac@me.com>2016-04-01 07:32:35 +0800
commitb3e5fc2cf6b054f1e30f3bcdd0149fbade01caad (patch)
tree99d9a7549ec9a0f9967aa688d6a9c88791ed9990 /app/scripts/lib
parent888ade6a1d0fde9fe7a029124007d08dc337578f (diff)
downloadtangerine-wallet-browser-b3e5fc2cf6b054f1e30f3bcdd0149fbade01caad.tar
tangerine-wallet-browser-b3e5fc2cf6b054f1e30f3bcdd0149fbade01caad.tar.gz
tangerine-wallet-browser-b3e5fc2cf6b054f1e30f3bcdd0149fbade01caad.tar.bz2
tangerine-wallet-browser-b3e5fc2cf6b054f1e30f3bcdd0149fbade01caad.tar.lz
tangerine-wallet-browser-b3e5fc2cf6b054f1e30f3bcdd0149fbade01caad.tar.xz
tangerine-wallet-browser-b3e5fc2cf6b054f1e30f3bcdd0149fbade01caad.tar.zst
tangerine-wallet-browser-b3e5fc2cf6b054f1e30f3bcdd0149fbade01caad.zip
Revert "Revert "Etherscan provider""
Diffstat (limited to 'app/scripts/lib')
-rw-r--r--app/scripts/lib/config-manager.js31
-rw-r--r--app/scripts/lib/zero.js65
2 files changed, 87 insertions, 9 deletions
diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js
index 682b34637..121ede838 100644
--- a/app/scripts/lib/config-manager.js
+++ b/app/scripts/lib/config-manager.js
@@ -47,15 +47,6 @@ ConfigManager.prototype.setConfig = function(config) {
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() {
var data = this.migrator.getData()
if ('config' in data) {
@@ -70,6 +61,28 @@ 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) {
this.migrator.saveData(data)
}
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
+
+}