mirror of https://github.com/embarklabs/embark.git
fix most rebase issues
This commit is contained in:
parent
5c5715d480
commit
56d541fb8d
|
@ -94,7 +94,13 @@ class ProcessLauncher {
|
|||
_handleLog(msg) {
|
||||
const timestamp = new Date().getTime();
|
||||
this.events.emit('process-log-' + this.name, msg.type, msg.message, this.name, timestamp);
|
||||
this.logs.push({msg: msg.message, msg_clear: msg.message.stripColors, logLevel: msg.logLevel, name: this.name, timestamp});
|
||||
this.logs.push({
|
||||
msg: msg.message,
|
||||
msg_clear: msg.message.stripColors,
|
||||
logLevel: msg.logLevel,
|
||||
name: this.name,
|
||||
timestamp
|
||||
});
|
||||
if (this.silent && msg.type !== 'error') {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -205,7 +205,7 @@ class BlockchainConnector {
|
|||
const self = this;
|
||||
const NO_NODE = 'noNode';
|
||||
|
||||
this.events.request("services:register", 'Ethereum', function (cb) {
|
||||
this.events.request("services:register", 'Ethereum', function(cb) {
|
||||
async.waterfall([
|
||||
function checkNodeConnection(next) {
|
||||
if (!self.provider || !self.provider.connected()) {
|
||||
|
@ -324,7 +324,7 @@ class BlockchainConnector {
|
|||
'/embark-api/blockchain/blocks/:blockNumber',
|
||||
(req, res) => {
|
||||
self.getBlock(req.params.blockNumber, (err, block) => {
|
||||
if(err){
|
||||
if (err) {
|
||||
self.logger.error(err);
|
||||
}
|
||||
res.send(block);
|
||||
|
@ -347,7 +347,7 @@ class BlockchainConnector {
|
|||
'/embark-api/blockchain/transactions/:hash',
|
||||
(req, res) => {
|
||||
self.getTransaction(req.params.hash, (err, transaction) => {
|
||||
if(err){
|
||||
if (err) {
|
||||
self.logger.error(err);
|
||||
}
|
||||
res.send(transaction);
|
||||
|
@ -395,11 +395,11 @@ class BlockchainConnector {
|
|||
callback(null, account);
|
||||
});
|
||||
}
|
||||
], function(_err, account){
|
||||
], function(_err, account) {
|
||||
accounts.push(account);
|
||||
eachCb();
|
||||
});
|
||||
}, function () {
|
||||
}, function() {
|
||||
callback(accounts);
|
||||
});
|
||||
});
|
||||
|
@ -411,7 +411,7 @@ class BlockchainConnector {
|
|||
function(next) {
|
||||
self.getAccountsWithTransactionCount((accounts) => {
|
||||
let account = accounts.find((a) => a.address === address);
|
||||
if(!account) {
|
||||
if (!account) {
|
||||
return next("No account found with this address");
|
||||
}
|
||||
next(null, account);
|
||||
|
@ -433,7 +433,7 @@ class BlockchainConnector {
|
|||
next(null, account);
|
||||
});
|
||||
}
|
||||
], function (err, result) {
|
||||
], function(err, result) {
|
||||
if (err) {
|
||||
callback();
|
||||
}
|
||||
|
@ -469,7 +469,7 @@ class BlockchainConnector {
|
|||
function(next) {
|
||||
async.times(limit, function(n, eachCb) {
|
||||
self.web3.eth.getBlock(from - n, returnTransactionObjects, function(err, block) {
|
||||
if (err){
|
||||
if (err) {
|
||||
self.logger.error(err);
|
||||
return eachCb();
|
||||
}
|
||||
|
@ -478,7 +478,7 @@ class BlockchainConnector {
|
|||
});
|
||||
}, next);
|
||||
}
|
||||
], function () {
|
||||
], function() {
|
||||
callback(blocks);
|
||||
});
|
||||
}
|
||||
|
@ -557,60 +557,14 @@ class BlockchainConnector {
|
|||
}
|
||||
|
||||
deployContractFromObject(deployContractObject, params, cb) {
|
||||
const self = this;
|
||||
let hash;
|
||||
let calledBacked = false;
|
||||
|
||||
function callback(err, receipt) {
|
||||
if (calledBacked) {
|
||||
return;
|
||||
}
|
||||
if (!err && !receipt.contractAddress) {
|
||||
return; // Not deployed yet. Need to wait
|
||||
}
|
||||
if (interval) {
|
||||
clearInterval(interval);
|
||||
}
|
||||
calledBacked = true;
|
||||
cb(err, 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
|
||||
}
|
||||
self.web3.eth.getTransactionReceipt(hash, (err, receipt) => {
|
||||
if (!err && !receipt) {
|
||||
return; // Transaction is not yet complete
|
||||
}
|
||||
callback(err, receipt);
|
||||
});
|
||||
}, 500);
|
||||
|
||||
deployContractObject.send({
|
||||
embarkJsUtils.secureSend(this.web3, deployContractObject, {
|
||||
from: params.from, gas: params.gas, gasPrice: params.gasPrice
|
||||
}, function (err, transactionHash) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
hash = transactionHash;
|
||||
}).on('receipt', function (receipt) {
|
||||
if (receipt.contractAddress !== undefined) {
|
||||
callback(null, receipt);
|
||||
}
|
||||
}).then(function (_contract) {
|
||||
if (!hash) {
|
||||
return; // Somehow we didn't get the receipt yet... Interval will catch it
|
||||
}
|
||||
self.web3.eth.getTransactionReceipt(hash, callback);
|
||||
}).catch(callback);
|
||||
}, true, cb);
|
||||
}
|
||||
|
||||
determineDefaultAccount(cb) {
|
||||
const self = this;
|
||||
self.getAccounts(function (err, accounts) {
|
||||
self.getAccounts(function(err, accounts) {
|
||||
if (err) {
|
||||
self.logger.error(err);
|
||||
return cb(new Error(err));
|
||||
|
@ -628,6 +582,20 @@ class BlockchainConnector {
|
|||
// can just be a command without a callback
|
||||
this.events.emit("runcode:register", "web3", this.web3, false);
|
||||
}
|
||||
|
||||
subscribeToPendingTransactions() {
|
||||
const self = this;
|
||||
this.onReady(() => {
|
||||
if (self.logsSubscription) {
|
||||
self.logsSubscription.unsubscribe();
|
||||
}
|
||||
self.logsSubscription = self.web3.eth
|
||||
.subscribe('newBlockHeaders', () => {})
|
||||
.on("data", function (blockHeader) {
|
||||
self.events.emit('block:header', blockHeader);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
BlockchainConnector.ACCEPTED_TYPES = ['rpc', 'ws', 'vm'];
|
||||
|
|
|
@ -82,8 +82,7 @@ class ContractsManager {
|
|||
cb(results);
|
||||
});
|
||||
|
||||
let plugin = this.plugins.createPlugin('deployment', {});
|
||||
plugin.registerAPICall(
|
||||
embark.registerAPICall(
|
||||
'get',
|
||||
'/embark-api/contract/:contractName',
|
||||
(req, res) => {
|
||||
|
@ -91,7 +90,7 @@ class ContractsManager {
|
|||
}
|
||||
);
|
||||
|
||||
plugin.registerAPICall(
|
||||
embark.registerAPICall(
|
||||
'post',
|
||||
'/embark-api/contract/:contractName/function',
|
||||
(req, res) => {
|
||||
|
@ -127,7 +126,7 @@ class ContractsManager {
|
|||
}
|
||||
);
|
||||
|
||||
plugin.registerAPICall(
|
||||
embark.registerAPICall(
|
||||
'post',
|
||||
'/embark-api/contract/:contractName/deploy',
|
||||
(req, res) => {
|
||||
|
@ -158,7 +157,7 @@ class ContractsManager {
|
|||
}
|
||||
);
|
||||
|
||||
plugin.registerAPICall(
|
||||
embark.registerAPICall(
|
||||
'get',
|
||||
'/embark-api/contracts',
|
||||
(req, res) => {
|
||||
|
|
|
@ -157,9 +157,6 @@ __embarkENS.setProvider = function (config) {
|
|||
const ERROR_MESSAGE = 'ENS is not available in this chain';
|
||||
self.registration = config.registration;
|
||||
self.env = config.env;
|
||||
EmbarkJS.onReady(() => {
|
||||
self.registration = config.registration;
|
||||
|
||||
EmbarkJS.onReady(() => {
|
||||
web3.eth.net.getId()
|
||||
.then((id) => {
|
||||
|
|
|
@ -13,12 +13,46 @@ class Profiler {
|
|||
this.registerApi();
|
||||
}
|
||||
|
||||
profile(contractName, contract, callback) {
|
||||
profileJSON(contractName, returnCb) {
|
||||
const self = this;
|
||||
|
||||
let profileObj = {};
|
||||
profileObj.name = contractName;
|
||||
profileObj.methods = [];
|
||||
|
||||
self.events.request('contracts:contract', contractName, (contract) => {
|
||||
if (!contract || !contract.deployedAddress) {
|
||||
return returnCb("-- couldn't profile " + contractName + " - it's not deployed or could be an interface");
|
||||
}
|
||||
self.gasEstimator.estimateGas(contractName, function(_err, gastimates, _name) {
|
||||
contract.abiDefinition.forEach((abiMethod) => {
|
||||
let methodName = abiMethod.name;
|
||||
if (['constructor', 'fallback'].indexOf(abiMethod.type) >= 0) {
|
||||
methodName = abiMethod.type;
|
||||
}
|
||||
|
||||
profileObj.methods.push({
|
||||
name: methodName,
|
||||
payable: abiMethod.payable,
|
||||
mutability: abiMethod.stateMutability,
|
||||
inputs: abiMethod.inputs || [],
|
||||
outputs: abiMethod.outputs || [],
|
||||
gasEstimates: gastimates && gastimates[methodName]
|
||||
});
|
||||
});
|
||||
|
||||
returnCb(null, profileObj);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
profile(contractName, returnCb) {
|
||||
const self = this;
|
||||
|
||||
this.profileJSON(contractName, (err, profileObj) => {
|
||||
if (err) {
|
||||
return callback(null, "error found in method: " + name + " error: " + JSON.stringify(err));
|
||||
self.logger.error(JSON.stringify(err));
|
||||
return returnCb(err);
|
||||
}
|
||||
|
||||
let table = new asciiTable(contractName);
|
||||
|
@ -26,7 +60,7 @@ class Profiler {
|
|||
profileObj.methods.forEach((method) => {
|
||||
table.addRow(method.name, method.payable, method.mutability, self.formatParams(method.inputs), self.formatParams(method.outputs), method.gasEstimates);
|
||||
});
|
||||
callback(null, table.toString());
|
||||
return returnCb(null, table.toString());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -30,23 +30,26 @@ class Solidity {
|
|||
}
|
||||
|
||||
_compile(jsonObj, returnAllErrors, callback) {
|
||||
this.solcW.compile(jsonObj, (err, output) => {
|
||||
if (err) {
|
||||
const self = this;
|
||||
self.solcW.compile(jsonObj, function (err, output) {
|
||||
self.events.emit('contracts:compile:solc', jsonObj);
|
||||
|
||||
if(err){
|
||||
return callback(err);
|
||||
}
|
||||
if (output.errors && returnAllErrors) {
|
||||
return callback(output.errors);
|
||||
}
|
||||
|
||||
if (output.errors) {
|
||||
for (let i = 0; i < output.errors.length; i++) {
|
||||
for (let i=0; i<output.errors.length; i++) {
|
||||
if (output.errors[i].type === 'Warning') {
|
||||
this.logger.warn(output.errors[i].formattedMessage);
|
||||
self.logger.warn(output.errors[i].formattedMessage);
|
||||
}
|
||||
if (output.errors[i].type === 'Error' || output.errors[i].severity === 'error') {
|
||||
return callback(new Error("Solidity errors: " + output.errors[i].formattedMessage).message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.events.emit('contracts:compiled:solc', output);
|
||||
callback(null, output);
|
||||
});
|
||||
}
|
||||
|
@ -55,32 +58,6 @@ class Solidity {
|
|||
const self = this;
|
||||
|
||||
async.waterfall([
|
||||
function prepareInput(callback) {
|
||||
async.each(contractFiles,
|
||||
function(file, fileCb) {
|
||||
let filename = file.filename;
|
||||
|
||||
for (let directory of self.contractDirectories) {
|
||||
let match = new RegExp("^" + directory);
|
||||
filename = filename.replace(match, '');
|
||||
}
|
||||
|
||||
originalFilepath[filename] = file.filename;
|
||||
|
||||
file.content(function(fileContent) {
|
||||
if (!fileContent) {
|
||||
self.logger.error(__('Error while loading the content of ') + filename);
|
||||
return fileCb();
|
||||
}
|
||||
input[filename] = {content: fileContent.replace(/\r\n/g, '\n'), path: file.path};
|
||||
fileCb();
|
||||
});
|
||||
},
|
||||
function (err) {
|
||||
callback(err);
|
||||
}
|
||||
);
|
||||
},
|
||||
function loadCompiler(callback) {
|
||||
if (self.solcAlreadyLoaded) {
|
||||
return callback();
|
||||
|
@ -122,28 +99,7 @@ class Solidity {
|
|||
}
|
||||
};
|
||||
|
||||
self.solcW.compile(jsonObj, function (err, output) {
|
||||
self.events.emit('contracts:compile:solc', jsonObj);
|
||||
|
||||
if(err){
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (output.errors) {
|
||||
for (let i=0; i<output.errors.length; i++) {
|
||||
if (output.errors[i].type === 'Warning') {
|
||||
self.logger.warn(output.errors[i].formattedMessage);
|
||||
}
|
||||
if (output.errors[i].type === 'Error' || output.errors[i].severity === 'error') {
|
||||
return callback(new Error("Solidity errors: " + output.errors[i].formattedMessage).message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.events.emit('contracts:compiled:solc', output);
|
||||
|
||||
callback(null, output);
|
||||
});
|
||||
self._compile(jsonObj, returnAllErrors, callback);
|
||||
},
|
||||
function createCompiledObject(output, callback) {
|
||||
let json = output.contracts;
|
||||
|
|
|
@ -24,8 +24,10 @@ class WebServer {
|
|||
this.host = this.webServerConfig.host;
|
||||
this.port = parseInt(this.webServerConfig.port, 10);
|
||||
this.enableCatchAll = this.webServerConfig.enableCatchAll === true;
|
||||
this.enableCatchAll = false; // FIXME when true, some Requests end up failing (eg: process-logs)
|
||||
|
||||
this.events.emit("status", __("Starting Server"));
|
||||
this.server = new Server({logger: this.logger, host: this.host, port: this.port, events: this.events, plugins: this.plugins, enableCatchAll: this.enableCatchAll});
|
||||
|
||||
this.server = new Server({
|
||||
logger: this.logger,
|
||||
|
@ -82,6 +84,7 @@ class WebServer {
|
|||
this.server.port = 0;
|
||||
done();
|
||||
});
|
||||
this.server.start((_err, message) => this.logger.info(message));
|
||||
}
|
||||
|
||||
setServiceCheck() {
|
||||
|
|
|
@ -23,6 +23,8 @@ class Server {
|
|||
this.opened = false;
|
||||
this.openBrowser = options.openBrowser;
|
||||
this.logging = false;
|
||||
this.plugins = options.plugins;
|
||||
this.enableCatchAll = options.enableCatchAll;
|
||||
|
||||
this.events.once('outputDone', () => {
|
||||
this.logger.info(this._getMessage());
|
||||
|
@ -40,6 +42,7 @@ class Server {
|
|||
}
|
||||
|
||||
start(callback) {
|
||||
callback = callback || function() {};
|
||||
const self = this;
|
||||
if (this.server && this.server.listening) {
|
||||
let message = __("a webserver is already running at") + " " +
|
||||
|
@ -159,6 +162,7 @@ class Server {
|
|||
}
|
||||
|
||||
stop(callback) {
|
||||
callback = callback || function () {};
|
||||
if (!this.server || !this.server.listening) {
|
||||
return callback(null, __("no webserver is currently running"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue