use embarkJS secureSend

This commit is contained in:
Jonathan Rainville 2018-08-14 10:09:59 -04:00 committed by Iuri Matias
parent c211430fbd
commit 2fe1b05492
4 changed files with 5 additions and 70 deletions

View File

@ -3,7 +3,7 @@ const async = require('async');
const Provider = require('./provider.js'); const Provider = require('./provider.js');
const utils = require('../../utils/utils'); const utils = require('../../utils/utils');
const constants = require('../../constants'); const constants = require('../../constants');
const secureSend = require('../../utils/secureSend'); const embarkJsUtils = require('embarkjs').Utils;
const WEB3_READY = 'web3Ready'; const WEB3_READY = 'web3Ready';
@ -232,7 +232,7 @@ class BlockchainConnector {
} }
deployContractFromObject(deployContractObject, params, cb) { deployContractFromObject(deployContractObject, params, cb) {
secureSend(this.web3, deployContractObject, { embarkJsUtils.secureSend(this.web3, deployContractObject, {
from: params.from, gas: params.gas, gasPrice: params.gasPrice from: params.from, gas: params.gas, gasPrice: params.gasPrice
}, true, cb); }, true, cb);
} }

View File

@ -1,4 +1,4 @@
/*global EmbarkJS, web3, registerSubDomain, namehash, secureSend*/ /*global EmbarkJS, web3, registerSubDomain, namehash*/
let __embarkENS = {}; let __embarkENS = {};

View File

@ -2,7 +2,7 @@ const fs = require('../../core/fs.js');
const utils = require('../../utils/utils.js'); const utils = require('../../utils/utils.js');
const namehash = require('eth-ens-namehash'); const namehash = require('eth-ens-namehash');
const async = require('async'); const async = require('async');
const embarkJsUtils = require('embarkjs').Utils;
const reverseAddrSuffix = '.addr.reverse'; const reverseAddrSuffix = '.addr.reverse';
class ENS { class ENS {
@ -147,7 +147,7 @@ class ENS {
registerConfigDomains(config, cb) { registerConfigDomains(config, cb) {
const self = this; const self = this;
const register = require('./register'); const register = require('./register');
const secureSend = require('../../utils/secureSend'); const secureSend = embarkJsUtils.secureSend;
self.events.request("blockchain:defaultAccount:get", (defaultAccount) => { self.events.request("blockchain:defaultAccount:get", (defaultAccount) => {
async.parallel([ async.parallel([
function createRegistryContract(paraCb) { function createRegistryContract(paraCb) {
@ -202,7 +202,6 @@ class ENS {
}); });
let code = fs.readFileSync(utils.joinPath(__dirname, 'register.js')).toString(); 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 += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'embarkjs.js')).toString();
code += "\nEmbarkJS.Names.registerProvider('ens', __embarkENS);"; code += "\nEmbarkJS.Names.registerProvider('ens', __embarkENS);";

View File

@ -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;
}