aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-03-30 05:31:25 +0800
committerDan Finlay <dan@danfinlay.com>2016-03-30 05:31:25 +0800
commite5bb94b5c7a5a99488cf98695fc09767d0002373 (patch)
treee1e54b77cda1c00430e583d6fdec894efd589783
parent18b75e679f148f973346bd12d90f2bb0203769c0 (diff)
downloadtangerine-wallet-browser-e5bb94b5c7a5a99488cf98695fc09767d0002373.tar
tangerine-wallet-browser-e5bb94b5c7a5a99488cf98695fc09767d0002373.tar.gz
tangerine-wallet-browser-e5bb94b5c7a5a99488cf98695fc09767d0002373.tar.bz2
tangerine-wallet-browser-e5bb94b5c7a5a99488cf98695fc09767d0002373.tar.lz
tangerine-wallet-browser-e5bb94b5c7a5a99488cf98695fc09767d0002373.tar.xz
tangerine-wallet-browser-e5bb94b5c7a5a99488cf98695fc09767d0002373.tar.zst
tangerine-wallet-browser-e5bb94b5c7a5a99488cf98695fc09767d0002373.zip
Created etherscan provider (untested)
-rw-r--r--.gitignore3
-rw-r--r--app/scripts/lib/etherscan-provider.js62
2 files changed, 64 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 0ef0ceb2e..476b197db 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,4 +8,5 @@ app/bower_components
test/bower_components
package
-.DS_Store \ No newline at end of file
+.DS_Store
+builds/
diff --git a/app/scripts/lib/etherscan-provider.js b/app/scripts/lib/etherscan-provider.js
new file mode 100644
index 000000000..a2334c367
--- /dev/null
+++ b/app/scripts/lib/etherscan-provider.js
@@ -0,0 +1,62 @@
+const xhr = process.browser ? require('xhr') : require('request')
+const inherits = require('util').inherits
+const createPayload = require('../util/create-payload.js')
+
+module.exports = EtherScanProvider
+
+function EtherScanProvider(opts) {
+
+ this.url = opts.url || 'http://testnet.etherscan.io/api?module=proxy&'
+
+}
+
+EtherScanProvider.prototype.setEngine = function(engine) {
+ const self = this
+ self.engine = engine
+ engine.on('block', function(block) {
+ self.currentBlock = block
+ })
+}
+
+EtherScanProvider.prototype.handleRequest = function(payload, next, end) {
+
+ const self = this
+ var method = payload.method
+ var targetUrl = self.rpcUrl + 'action=' + method
+ var params = payload.params
+
+ var newPayload = createPayload(payload)
+
+ xhr({
+ uri: targetUrl,
+ method: 'POST',
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify(newPayload),
+ rejectUnauthorized: false,
+ }, function(err, res, body) {
+ if (err) return end(err)
+
+ // parse response into raw account
+ var data
+ try {
+ data = JSON.parse(body)
+ if (data.error) return end(data.error)
+ } catch (err) {
+ console.error(err.stack)
+ return end(err)
+ }
+
+ // console.log('network:', payload.method, payload.params, '->', data.result)
+
+ end(null, data.result)
+ })
+
+}
+
+EtherScanProvider.prototype.emitPayload = function(payload, cb){
+ const self = this
+ self.engine.sendAsync(createPayload(payload), cb)
+}