From 2fe1b0549287b0b7fd7a3540545bd6b1f0834c27 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Tue, 14 Aug 2018 10:09:59 -0400 Subject: [PATCH] use embarkJS secureSend --- lib/modules/blockchain_connector/index.js | 4 +- lib/modules/ens/embarkjs.js | 2 +- lib/modules/ens/index.js | 5 +- lib/utils/secureSend.js | 64 ----------------------- 4 files changed, 5 insertions(+), 70 deletions(-) delete mode 100644 lib/utils/secureSend.js diff --git a/lib/modules/blockchain_connector/index.js b/lib/modules/blockchain_connector/index.js index b2b6f245..5142234e 100644 --- a/lib/modules/blockchain_connector/index.js +++ b/lib/modules/blockchain_connector/index.js @@ -3,7 +3,7 @@ const async = require('async'); const Provider = require('./provider.js'); const utils = require('../../utils/utils'); const constants = require('../../constants'); -const secureSend = require('../../utils/secureSend'); +const embarkJsUtils = require('embarkjs').Utils; const WEB3_READY = 'web3Ready'; @@ -232,7 +232,7 @@ class BlockchainConnector { } deployContractFromObject(deployContractObject, params, cb) { - secureSend(this.web3, deployContractObject, { + embarkJsUtils.secureSend(this.web3, deployContractObject, { from: params.from, gas: params.gas, gasPrice: params.gasPrice }, true, cb); } diff --git a/lib/modules/ens/embarkjs.js b/lib/modules/ens/embarkjs.js index 5a48f4a3..cac08229 100644 --- a/lib/modules/ens/embarkjs.js +++ b/lib/modules/ens/embarkjs.js @@ -1,4 +1,4 @@ -/*global EmbarkJS, web3, registerSubDomain, namehash, secureSend*/ +/*global EmbarkJS, web3, registerSubDomain, namehash*/ let __embarkENS = {}; diff --git a/lib/modules/ens/index.js b/lib/modules/ens/index.js index 7116b0ba..73954cbb 100644 --- a/lib/modules/ens/index.js +++ b/lib/modules/ens/index.js @@ -2,7 +2,7 @@ const fs = require('../../core/fs.js'); const utils = require('../../utils/utils.js'); const namehash = require('eth-ens-namehash'); const async = require('async'); - +const embarkJsUtils = require('embarkjs').Utils; const reverseAddrSuffix = '.addr.reverse'; class ENS { @@ -147,7 +147,7 @@ class ENS { registerConfigDomains(config, cb) { const self = this; const register = require('./register'); - const secureSend = require('../../utils/secureSend'); + const secureSend = embarkJsUtils.secureSend; self.events.request("blockchain:defaultAccount:get", (defaultAccount) => { async.parallel([ function createRegistryContract(paraCb) { @@ -202,7 +202,6 @@ class ENS { }); let code = fs.readFileSync(utils.joinPath(__dirname, 'register.js')).toString(); - code += "\n" + fs.readFileSync(utils.joinPath(__dirname, '../../utils/secureSend.js')).toString(); code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'embarkjs.js')).toString(); code += "\nEmbarkJS.Names.registerProvider('ens', __embarkENS);"; diff --git a/lib/utils/secureSend.js b/lib/utils/secureSend.js deleted file mode 100644 index 4fa468b4..00000000 --- a/lib/utils/secureSend.js +++ /dev/null @@ -1,64 +0,0 @@ - -function secureSend(web3, toSend, params, isContractDeploy, cb) { - cb = cb || function(){}; - return new Promise((resolve, reject) => { - let hash; - let calledBacked = false; - - function callback(err, receipt) { - if (calledBacked) { - return; - } - if (!err && (isContractDeploy && !receipt.contractAddress)) { - return; // Not deployed yet. Need to wait - } - if (interval) { - clearInterval(interval); - } - calledBacked = true; - cb(err, receipt); - if (err) { - return reject(err); - } - resolve(receipt); - } - - // This interval is there to compensate for the event that sometimes doesn't get triggered when using WebSocket - // FIXME The issue somehow only happens when the blockchain node is started in the same terminal - const interval = setInterval(() => { - if (!hash) { - return; // Wait until we receive the hash - } - web3.eth.getTransactionReceipt(hash, (err, receipt) => { - if (!err && !receipt) { - return; // Transaction is not yet complete - } - callback(err, receipt); - }); - }, 100); - - toSend.estimateGas() - .then(gasEstimated => { - params.gas = gasEstimated + 1000; - return toSend.send(params, function(err, transactionHash) { - if (err) { - return callback(err); - } - hash = transactionHash; - }).on('receipt', function(receipt) { - if (!isContractDeploy || receipt.contractAddress) { - callback(null, receipt); - } - }).then(function(_contract) { - if (!hash) { - return; // Somehow we didn't get the receipt yet... Interval will catch it - } - web3.eth.getTransactionReceipt(hash, callback); - }).catch(callback); - }); - }); -} - -if (typeof module !== 'undefined' && module.exports) { - module.exports = secureSend; -}