mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-12 23:14:10 +00:00
commit
d872ce9c51
@ -1,8 +1,7 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
|
- "7"
|
||||||
- "6"
|
- "6"
|
||||||
- "5"
|
|
||||||
- "4"
|
|
||||||
addons:
|
addons:
|
||||||
code_climate:
|
code_climate:
|
||||||
repo_token: 7454b1a666015e244c384d19f48c34e35d1ae58c3aa428ec542f10bbcb848358
|
repo_token: 7454b1a666015e244c384d19f48c34e35d1ae58c3aa428ec542f10bbcb848358
|
||||||
|
@ -23,7 +23,14 @@ module.exports = (grunt) ->
|
|||||||
src: ['test/**/*.js']
|
src: ['test/**/*.js']
|
||||||
|
|
||||||
jshint:
|
jshint:
|
||||||
all: ['bin/embark', 'lib/**/*.js', 'js/mine.js', 'js/embark.js']
|
all: ['bin/embark', 'lib/**/*.js']
|
||||||
|
options: grunt.file.readJSON('package.json').jshintConfig
|
||||||
|
with_overrides:
|
||||||
|
options:
|
||||||
|
undef: false
|
||||||
|
esversion: 5
|
||||||
|
files:
|
||||||
|
src: ['js/mine.js', 'js/embark.js']
|
||||||
|
|
||||||
grunt.loadTasks "tasks"
|
grunt.loadTasks "tasks"
|
||||||
require('matchdep').filterAll(['grunt-*','!grunt-cli']).forEach(grunt.loadNpmTasks)
|
require('matchdep').filterAll(['grunt-*','!grunt-cli']).forEach(grunt.loadNpmTasks)
|
||||||
|
302
lib/cmd.js
302
lib/cmd.js
@ -1,168 +1,170 @@
|
|||||||
var program = require('commander');
|
let program = require('commander');
|
||||||
var colors = require('colors');
|
let colors = require('colors');
|
||||||
var shelljs = require('shelljs');
|
let shelljs = require('shelljs');
|
||||||
var promptly = require('promptly');
|
let promptly = require('promptly');
|
||||||
var path = require('path');
|
let path = require('path');
|
||||||
var Embark = require('../lib/index');
|
let Embark = require('../lib/index');
|
||||||
|
|
||||||
var Cmd = function() {
|
class Cmd {
|
||||||
program.version(Embark.version);
|
constructor() {
|
||||||
};
|
program.version(Embark.version);
|
||||||
|
|
||||||
|
|
||||||
Cmd.prototype.process = function(args) {
|
|
||||||
this.newApp();
|
|
||||||
this.demo();
|
|
||||||
this.build();
|
|
||||||
this.run();
|
|
||||||
this.blockchain();
|
|
||||||
this.simulator();
|
|
||||||
this.test();
|
|
||||||
this.upload();
|
|
||||||
this.otherCommands();
|
|
||||||
|
|
||||||
//If no arguments are passed display help by default
|
|
||||||
if (!process.argv.slice(2).length) {
|
|
||||||
program.help();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
program.parse(args);
|
|
||||||
};
|
|
||||||
|
|
||||||
Cmd.prototype.newApp = function(name) {
|
process(args) {
|
||||||
|
this.newApp();
|
||||||
|
this.demo();
|
||||||
|
this.build();
|
||||||
|
this.run();
|
||||||
|
this.blockchain();
|
||||||
|
this.simulator();
|
||||||
|
this.test();
|
||||||
|
this.upload();
|
||||||
|
this.otherCommands();
|
||||||
|
|
||||||
var validateName = function (value) {
|
//If no arguments are passed display help by default
|
||||||
try {
|
if (!process.argv.slice(2).length) {
|
||||||
if(value.match(/^[a-zA-Z\s\-]+$/)) return value;
|
program.help();
|
||||||
} catch (e) {
|
|
||||||
throw new Error('Name must be only letters, spaces, or dashes');
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
program
|
program.parse(args);
|
||||||
.command('new [name]')
|
}
|
||||||
.description('new application')
|
|
||||||
.action(function (name) {
|
newApp(name) {
|
||||||
if (name === undefined) {
|
|
||||||
var parentDirectory = path.dirname(__dirname).split("/").pop();
|
let validateName = function (value) {
|
||||||
return promptly.prompt("Name your app (default is " + parentDirectory + "):", {
|
try {
|
||||||
default: parentDirectory,
|
if (value.match(/^[a-zA-Z\s\-]+$/)) return value;
|
||||||
validator: validateName
|
} catch (e) {
|
||||||
}, function (err, inputvalue) {
|
throw new Error('Name must be only letters, spaces, or dashes');
|
||||||
if (err) {
|
|
||||||
console.error('Invalid name:', err.message);
|
|
||||||
// Manually call retry
|
|
||||||
// The passed error has a retry method to easily prompt again.
|
|
||||||
err.retry();
|
|
||||||
} else {
|
|
||||||
//slightly different assignment of name since it comes from child prompt
|
|
||||||
Embark.generateTemplate('boilerplate', './', inputvalue);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
Embark.generateTemplate('boilerplate', './', name);
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
});
|
program
|
||||||
};
|
.command('new [name]')
|
||||||
|
.description('new application')
|
||||||
|
.action(function (name) {
|
||||||
|
if (name === undefined) {
|
||||||
|
let parentDirectory = path.dirname(__dirname).split("/").pop();
|
||||||
|
return promptly.prompt("Name your app (default is " + parentDirectory + "):", {
|
||||||
|
default: parentDirectory,
|
||||||
|
validator: validateName
|
||||||
|
}, function (err, inputvalue) {
|
||||||
|
if (err) {
|
||||||
|
console.error('Invalid name:', err.message);
|
||||||
|
// Manually call retry
|
||||||
|
// The passed error has a retry method to easily prompt again.
|
||||||
|
err.retry();
|
||||||
|
} else {
|
||||||
|
//slightly different assignment of name since it comes from child prompt
|
||||||
|
Embark.generateTemplate('boilerplate', './', inputvalue);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Embark.generateTemplate('boilerplate', './', name);
|
||||||
|
}
|
||||||
|
|
||||||
Cmd.prototype.demo = function() {
|
});
|
||||||
program
|
}
|
||||||
.command('demo')
|
|
||||||
.description('create a working dapp with a SimpleStorage contract')
|
|
||||||
.action(function() {
|
|
||||||
Embark.generateTemplate('demo', './', 'embark_demo');
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Cmd.prototype.build = function() {
|
demo() {
|
||||||
program
|
program
|
||||||
.command('build [environment]')
|
.command('demo')
|
||||||
.description('deploy and build dapp at dist/ (default: development)')
|
.description('create a working dapp with a SimpleStorage contract')
|
||||||
.action(function(env, options) {
|
.action(function () {
|
||||||
Embark.build({env: env || 'development'});
|
Embark.generateTemplate('demo', './', 'embark_demo');
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
Cmd.prototype.run = function() {
|
build() {
|
||||||
program
|
program
|
||||||
.command('run [environment]')
|
.command('build [environment]')
|
||||||
.option('-p, --port [port]', 'port to run the dev webserver (default: 8000)')
|
.description('deploy and build dapp at dist/ (default: development)')
|
||||||
.option('-b, --host [host]', 'host to run the dev webserver (default: localhost)')
|
.action(function (env, options) {
|
||||||
.option('--noserver', 'disable the development webserver')
|
Embark.build({env: env || 'development'});
|
||||||
.option('--nodashboard', 'simple mode, disables the dashboard')
|
});
|
||||||
.option('--no-color', 'no colors in case it\'s needed for compatbility purposes')
|
}
|
||||||
.description('run dapp (default: development)')
|
|
||||||
.action(function(env, options) {
|
|
||||||
Embark.run({
|
|
||||||
env: env || 'development',
|
|
||||||
serverPort: options.port,
|
|
||||||
serverHost: options.host,
|
|
||||||
runWebserver: !options.noserver,
|
|
||||||
useDashboard: !options.nodashboard
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Cmd.prototype.blockchain = function() {
|
run() {
|
||||||
program
|
program
|
||||||
.command('blockchain [environment]')
|
.command('run [environment]')
|
||||||
.option('-c, --client [client]', 'Use a specific ethereum client or simulator (supported: geth, parity, ethersim, testrpc')
|
.option('-p, --port [port]', 'port to run the dev webserver (default: 8000)')
|
||||||
.description('run blockchain server (default: development)')
|
.option('-b, --host [host]', 'host to run the dev webserver (default: localhost)')
|
||||||
.action(function(env ,options) {
|
.option('--noserver', 'disable the development webserver')
|
||||||
Embark.initConfig(env || 'development', {
|
.option('--nodashboard', 'simple mode, disables the dashboard')
|
||||||
embarkConfig: 'embark.json',
|
.option('--no-color', 'no colors in case it\'s needed for compatbility purposes')
|
||||||
interceptLogs: false
|
.description('run dapp (default: development)')
|
||||||
});
|
.action(function (env, options) {
|
||||||
Embark.blockchain(env || 'development', options.client || 'geth');
|
Embark.run({
|
||||||
});
|
env: env || 'development',
|
||||||
};
|
serverPort: options.port,
|
||||||
|
serverHost: options.host,
|
||||||
|
runWebserver: !options.noserver,
|
||||||
|
useDashboard: !options.nodashboard
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Cmd.prototype.simulator = function() {
|
blockchain() {
|
||||||
program
|
program
|
||||||
.command('simulator [environment]')
|
.command('blockchain [environment]')
|
||||||
.description('run a fast ethereum rpc simulator')
|
.option('-c, --client [client]', 'Use a specific ethereum client or simulator (supported: geth, parity, ethersim, testrpc')
|
||||||
.option('--testrpc', 'use testrpc as the rpc simulator [default]')
|
.description('run blockchain server (default: development)')
|
||||||
.option('-p, --port [port]', 'port to run the rpc simulator (default: 8000)')
|
.action(function (env, options) {
|
||||||
.option('-h, --host [host]', 'host to run the rpc simulator (default: localhost)')
|
Embark.initConfig(env || 'development', {
|
||||||
.action(function(env, options) {
|
embarkConfig: 'embark.json',
|
||||||
Embark.initConfig(env || 'development', {
|
interceptLogs: false
|
||||||
embarkConfig: 'embark.json',
|
});
|
||||||
interceptLogs: false
|
Embark.blockchain(env || 'development', options.client || 'geth');
|
||||||
});
|
});
|
||||||
Embark.simulator({port: options.port, host: options.host});
|
}
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Cmd.prototype.test = function() {
|
simulator() {
|
||||||
program
|
program
|
||||||
.command('test')
|
.command('simulator [environment]')
|
||||||
.description('run tests')
|
.description('run a fast ethereum rpc simulator')
|
||||||
.action(function() {
|
.option('--testrpc', 'use testrpc as the rpc simulator [default]')
|
||||||
shelljs.exec('mocha test');
|
.option('-p, --port [port]', 'port to run the rpc simulator (default: 8000)')
|
||||||
});
|
.option('-h, --host [host]', 'host to run the rpc simulator (default: localhost)')
|
||||||
};
|
.action(function (env, options) {
|
||||||
|
Embark.initConfig(env || 'development', {
|
||||||
|
embarkConfig: 'embark.json',
|
||||||
|
interceptLogs: false
|
||||||
|
});
|
||||||
|
Embark.simulator({port: options.port, host: options.host});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Cmd.prototype.upload = function() {
|
test() {
|
||||||
program
|
program
|
||||||
.command('upload [platform] [environment]')
|
.command('test')
|
||||||
.description('upload your dapp to a decentralized storage. possible options: ipfs, swarm (e.g embark upload swarm)')
|
.description('run tests')
|
||||||
.action(function(platform, env, options) {
|
.action(function () {
|
||||||
// TODO: get env in cmd line as well
|
shelljs.exec('mocha test');
|
||||||
Embark.initConfig(env || 'development', {
|
});
|
||||||
embarkConfig: 'embark.json', interceptLogs: false
|
}
|
||||||
});
|
|
||||||
Embark.upload(platform);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Cmd.prototype.otherCommands = function() {
|
upload() {
|
||||||
program
|
program
|
||||||
.action(function(env){
|
.command('upload [platform] [environment]')
|
||||||
console.log('unknown command "%s"'.red, env);
|
.description('upload your dapp to a decentralized storage. possible options: ipfs, swarm (e.g embark upload swarm)')
|
||||||
console.log("type embark --help to see the available commands");
|
.action(function (platform, env, options) {
|
||||||
process.exit(0);
|
// TODO: get env in cmd line as well
|
||||||
});
|
Embark.initConfig(env || 'development', {
|
||||||
};
|
embarkConfig: 'embark.json', interceptLogs: false
|
||||||
|
});
|
||||||
|
Embark.upload(platform);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
otherCommands() {
|
||||||
|
program
|
||||||
|
.action(function (env) {
|
||||||
|
console.log('unknown command "%s"'.red, env);
|
||||||
|
console.log("type embark --help to see the available commands");
|
||||||
|
process.exit(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Cmd;
|
module.exports = Cmd;
|
||||||
|
@ -1,88 +1,11 @@
|
|||||||
var colors = require('colors');
|
let colors = require('colors');
|
||||||
var shelljs = require('shelljs');
|
let shelljs = require('shelljs');
|
||||||
|
|
||||||
var fs = require('../../core/fs.js');
|
let fs = require('../../core/fs.js');
|
||||||
|
|
||||||
var GethCommands = require('./geth_commands.js');
|
let GethCommands = require('./geth_commands.js');
|
||||||
|
|
||||||
/*eslint complexity: ["error", 22]*/
|
let BlockchainClient = function(blockchainConfig, client, env) {
|
||||||
var Blockchain = function(options) {
|
|
||||||
this.blockchainConfig = options.blockchainConfig;
|
|
||||||
this.env = options.env || 'development';
|
|
||||||
this.client = options.client;
|
|
||||||
|
|
||||||
this.config = {
|
|
||||||
geth_bin: this.blockchainConfig.geth_bin || 'geth',
|
|
||||||
networkType: this.blockchainConfig.networkType || 'custom',
|
|
||||||
genesisBlock: this.blockchainConfig.genesisBlock || false,
|
|
||||||
datadir: this.blockchainConfig.datadir || false,
|
|
||||||
mineWhenNeeded: this.blockchainConfig.mineWhenNeeded || false,
|
|
||||||
rpcHost: this.blockchainConfig.rpcHost || 'localhost',
|
|
||||||
rpcPort: this.blockchainConfig.rpcPort || 8545,
|
|
||||||
rpcCorsDomain: this.blockchainConfig.rpcCorsDomain || false,
|
|
||||||
networkId: this.blockchainConfig.networkId || 12301,
|
|
||||||
port: this.blockchainConfig.port || 30303,
|
|
||||||
nodiscover: this.blockchainConfig.nodiscover || false,
|
|
||||||
mine: this.blockchainConfig.mine || false,
|
|
||||||
account: this.blockchainConfig.account || {},
|
|
||||||
whisper: (this.blockchainConfig.whisper === undefined) || this.blockchainConfig.whisper,
|
|
||||||
maxpeers: ((this.blockchainConfig.maxpeers === 0) ? 0 : (this.blockchainConfig.maxpeers || 25)),
|
|
||||||
bootnodes: this.blockchainConfig.bootnodes || "",
|
|
||||||
rpcApi: (this.blockchainConfig.rpcApi || ['eth', 'web3', 'net']),
|
|
||||||
vmdebug: this.blockchainConfig.vmdebug || false
|
|
||||||
};
|
|
||||||
|
|
||||||
this.client = new options.client({config: this.config, env: this.env});
|
|
||||||
};
|
|
||||||
|
|
||||||
Blockchain.prototype.runCommand = function(cmd) {
|
|
||||||
console.log(("running: " + cmd.underline).green);
|
|
||||||
return shelljs.exec(cmd);
|
|
||||||
};
|
|
||||||
|
|
||||||
Blockchain.prototype.run = function() {
|
|
||||||
var self = this;
|
|
||||||
console.log("===============================================================================".magenta);
|
|
||||||
console.log("===============================================================================".magenta);
|
|
||||||
console.log(("Embark Blockchain Using: " + this.client.name.underline).magenta);
|
|
||||||
console.log("===============================================================================".magenta);
|
|
||||||
console.log("===============================================================================".magenta);
|
|
||||||
var address = this.initChainAndGetAddress();
|
|
||||||
this.client.mainCommand(address, function(cmd) {
|
|
||||||
shelljs.exec(cmd, {async : true});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Blockchain.prototype.initChainAndGetAddress = function() {
|
|
||||||
var address = null, result;
|
|
||||||
|
|
||||||
// ensure datadir exists, bypassing the interactive liabilities prompt.
|
|
||||||
this.datadir = '.embark/' + this.env + '/datadir';
|
|
||||||
fs.mkdirpSync(this.datadir);
|
|
||||||
|
|
||||||
// copy mining script
|
|
||||||
fs.copySync(fs.embarkPath("js"), ".embark/" + this.env + "/js", {overwrite: true});
|
|
||||||
|
|
||||||
// check if an account already exists, create one if not, return address
|
|
||||||
result = this.runCommand(this.client.listAccountsCommand());
|
|
||||||
if (result.output === undefined || result.output === '' || result.output.indexOf("Fatal") >= 0) {
|
|
||||||
console.log("no accounts found".green);
|
|
||||||
if (this.config.genesisBlock) {
|
|
||||||
console.log("initializing genesis block".green);
|
|
||||||
result = this.runCommand(this.client.initGenesisCommmand());
|
|
||||||
}
|
|
||||||
|
|
||||||
result = this.runCommand(this.client.newAccountCommand());
|
|
||||||
address = result.output.match(/{(\w+)}/)[1];
|
|
||||||
} else {
|
|
||||||
console.log("already initialized".green);
|
|
||||||
address = result.output.match(/{(\w+)}/)[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
return address;
|
|
||||||
};
|
|
||||||
|
|
||||||
var BlockchainClient = function(blockchainConfig, client, env) {
|
|
||||||
if (client === 'geth') {
|
if (client === 'geth') {
|
||||||
return new Blockchain({blockchainConfig: blockchainConfig, client: GethCommands, env: env});
|
return new Blockchain({blockchainConfig: blockchainConfig, client: GethCommands, env: env});
|
||||||
} else {
|
} else {
|
||||||
@ -90,5 +13,82 @@ var BlockchainClient = function(blockchainConfig, client, env) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*eslint complexity: ["error", 22]*/
|
||||||
|
class Blockchain {
|
||||||
|
constructor(options) {
|
||||||
|
this.blockchainConfig = options.blockchainConfig;
|
||||||
|
this.env = options.env || 'development';
|
||||||
|
this.client = options.client;
|
||||||
|
|
||||||
|
this.config = {
|
||||||
|
geth_bin: this.blockchainConfig.geth_bin || 'geth',
|
||||||
|
networkType: this.blockchainConfig.networkType || 'custom',
|
||||||
|
genesisBlock: this.blockchainConfig.genesisBlock || false,
|
||||||
|
datadir: this.blockchainConfig.datadir || false,
|
||||||
|
mineWhenNeeded: this.blockchainConfig.mineWhenNeeded || false,
|
||||||
|
rpcHost: this.blockchainConfig.rpcHost || 'localhost',
|
||||||
|
rpcPort: this.blockchainConfig.rpcPort || 8545,
|
||||||
|
rpcCorsDomain: this.blockchainConfig.rpcCorsDomain || false,
|
||||||
|
networkId: this.blockchainConfig.networkId || 12301,
|
||||||
|
port: this.blockchainConfig.port || 30303,
|
||||||
|
nodiscover: this.blockchainConfig.nodiscover || false,
|
||||||
|
mine: this.blockchainConfig.mine || false,
|
||||||
|
account: this.blockchainConfig.account || {},
|
||||||
|
whisper: (this.blockchainConfig.whisper === undefined) || this.blockchainConfig.whisper,
|
||||||
|
maxpeers: ((this.blockchainConfig.maxpeers === 0) ? 0 : (this.blockchainConfig.maxpeers || 25)),
|
||||||
|
bootnodes: this.blockchainConfig.bootnodes || "",
|
||||||
|
rpcApi: (this.blockchainConfig.rpcApi || ['eth', 'web3', 'net']),
|
||||||
|
vmdebug: this.blockchainConfig.vmdebug || false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static runCommand(cmd) {
|
||||||
|
console.log(("running: " + cmd.underline).green);
|
||||||
|
return shelljs.exec(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
run () {
|
||||||
|
let self = this;
|
||||||
|
console.log("===============================================================================".magenta);
|
||||||
|
console.log("===============================================================================".magenta);
|
||||||
|
console.log(("Embark Blockchain Using: " + this.client.name.underline).magenta);
|
||||||
|
console.log("===============================================================================".magenta);
|
||||||
|
console.log("===============================================================================".magenta);
|
||||||
|
let address = this.initChainAndGetAddress();
|
||||||
|
this.client.mainCommand(address, function(cmd) {
|
||||||
|
shelljs.exec(cmd, {async : true});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
initChainAndGetAddress() {
|
||||||
|
let address = null, result;
|
||||||
|
|
||||||
|
// ensure datadir exists, bypassing the interactive liabilities prompt.
|
||||||
|
this.datadir = '.embark/' + this.env + '/datadir';
|
||||||
|
fs.mkdirpSync(this.datadir);
|
||||||
|
|
||||||
|
// copy mining script
|
||||||
|
fs.copySync(fs.embarkPath("js"), ".embark/" + this.env + "/js", {overwrite: true});
|
||||||
|
|
||||||
|
// check if an account already exists, create one if not, return address
|
||||||
|
result = this.runCommand(this.client.listAccountsCommand());
|
||||||
|
if (result.output === undefined || result.output === '' || result.output.indexOf("Fatal") >= 0) {
|
||||||
|
console.log("no accounts found".green);
|
||||||
|
if (this.config.genesisBlock) {
|
||||||
|
console.log("initializing genesis block".green);
|
||||||
|
result = this.runCommand(this.client.initGenesisCommmand());
|
||||||
|
}
|
||||||
|
|
||||||
|
result = this.runCommand(this.client.newAccountCommand());
|
||||||
|
address = result.output.match(/{(\w+)}/)[1];
|
||||||
|
} else {
|
||||||
|
console.log("already initialized".green);
|
||||||
|
address = result.output.match(/{(\w+)}/)[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = BlockchainClient;
|
module.exports = BlockchainClient;
|
||||||
|
|
||||||
|
@ -1,164 +1,166 @@
|
|||||||
var async = require('async');
|
let async = require('async');
|
||||||
|
|
||||||
// TODO: make all of this async
|
// TODO: make all of this async
|
||||||
var GethCommands = function(options) {
|
class GethCommands {
|
||||||
this.config = options.config;
|
constructor(options) {
|
||||||
this.env = options.env || 'development';
|
this.config = options.config;
|
||||||
this.name = "Go-Ethereum (https://github.com/ethereum/go-ethereum)";
|
this.env = options.env || 'development';
|
||||||
this.geth_bin = this.config.geth_bin || "geth";
|
this.name = "Go-Ethereum (https://github.com/ethereum/go-ethereum)";
|
||||||
};
|
this.geth_bin = this.config.geth_bin || "geth";
|
||||||
|
|
||||||
GethCommands.prototype.commonOptions = function() {
|
|
||||||
var config = this.config;
|
|
||||||
var cmd = "";
|
|
||||||
|
|
||||||
cmd += this.determineNetworkType(config);
|
|
||||||
|
|
||||||
if (config.datadir) {
|
|
||||||
cmd += "--datadir=\"" + config.datadir + "\" ";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.light) {
|
commonOptions() {
|
||||||
cmd += "--light ";
|
let config = this.config;
|
||||||
|
let cmd = "";
|
||||||
|
|
||||||
|
cmd += this.determineNetworkType(config);
|
||||||
|
|
||||||
|
if (config.datadir) {
|
||||||
|
cmd += "--datadir=\"" + config.datadir + "\" ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.light) {
|
||||||
|
cmd += "--light ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.fast) {
|
||||||
|
cmd += "--fast ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.account && config.account.password) {
|
||||||
|
cmd += "--password " + config.account.password + " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.fast) {
|
determineNetworkType(config) {
|
||||||
cmd += "--fast ";
|
let cmd = "";
|
||||||
|
if (config.networkType === 'testnet') {
|
||||||
|
cmd += "--testnet ";
|
||||||
|
} else if (config.networkType === 'olympic') {
|
||||||
|
cmd += "--olympic ";
|
||||||
|
} else if (config.networkType === 'custom') {
|
||||||
|
cmd += "--networkid " + config.networkId + " ";
|
||||||
|
}
|
||||||
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.account && config.account.password) {
|
initGenesisCommmand() {
|
||||||
cmd += "--password " + config.account.password + " ";
|
let config = this.config;
|
||||||
|
let cmd = this.geth_bin + " " + this.commonOptions();
|
||||||
|
|
||||||
|
if (config.genesisBlock) {
|
||||||
|
cmd += "init \"" + config.genesisBlock + "\" ";
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd;
|
newAccountCommand() {
|
||||||
};
|
return this.geth_bin + " " + this.commonOptions() + "account new ";
|
||||||
|
|
||||||
GethCommands.prototype.determineNetworkType = function(config) {
|
|
||||||
var cmd = "";
|
|
||||||
if (config.networkType === 'testnet') {
|
|
||||||
cmd += "--testnet ";
|
|
||||||
} else if (config.networkType === 'olympic') {
|
|
||||||
cmd += "--olympic ";
|
|
||||||
} else if (config.networkType === 'custom') {
|
|
||||||
cmd += "--networkid " + config.networkId + " ";
|
|
||||||
}
|
|
||||||
return cmd;
|
|
||||||
};
|
|
||||||
|
|
||||||
GethCommands.prototype.initGenesisCommmand = function() {
|
|
||||||
var config = this.config;
|
|
||||||
var cmd = this.geth_bin + " " + this.commonOptions();
|
|
||||||
|
|
||||||
if (config.genesisBlock) {
|
|
||||||
cmd += "init \"" + config.genesisBlock + "\" ";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd;
|
listAccountsCommand() {
|
||||||
};
|
return this.geth_bin + " " + this.commonOptions() + "account list ";
|
||||||
|
}
|
||||||
|
|
||||||
GethCommands.prototype.newAccountCommand = function() {
|
determineRpcOptions(config) {
|
||||||
return this.geth_bin + " " + this.commonOptions() + "account new ";
|
let cmd = "";
|
||||||
};
|
|
||||||
|
|
||||||
GethCommands.prototype.listAccountsCommand = function() {
|
cmd += "--port " + config.port + " ";
|
||||||
return this.geth_bin + " " + this.commonOptions() + "account list ";
|
cmd += "--rpc ";
|
||||||
};
|
cmd += "--rpcport " + config.rpcPort + " ";
|
||||||
|
cmd += "--rpcaddr " + config.rpcHost + " ";
|
||||||
GethCommands.prototype.determineRpcOptions = function(config) {
|
if (config.rpcCorsDomain) {
|
||||||
var cmd = "";
|
if (config.rpcCorsDomain === '*') {
|
||||||
|
console.log('==================================');
|
||||||
cmd += "--port " + config.port + " ";
|
console.log('make sure you know what you are doing');
|
||||||
cmd += "--rpc ";
|
console.log('==================================');
|
||||||
cmd += "--rpcport " + config.rpcPort + " ";
|
}
|
||||||
cmd += "--rpcaddr " + config.rpcHost + " ";
|
cmd += "--rpccorsdomain=\"" + config.rpcCorsDomain + "\" ";
|
||||||
if (config.rpcCorsDomain) {
|
} else {
|
||||||
if (config.rpcCorsDomain === '*') {
|
|
||||||
console.log('==================================');
|
console.log('==================================');
|
||||||
console.log('make sure you know what you are doing');
|
console.log('warning: cors is not set');
|
||||||
console.log('==================================');
|
console.log('==================================');
|
||||||
}
|
}
|
||||||
cmd += "--rpccorsdomain=\"" + config.rpcCorsDomain + "\" ";
|
|
||||||
} else {
|
return cmd;
|
||||||
console.log('==================================');
|
|
||||||
console.log('warning: cors is not set');
|
|
||||||
console.log('==================================');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd;
|
mainCommand(address, done) {
|
||||||
};
|
let self = this;
|
||||||
|
let config = this.config;
|
||||||
|
let rpc_api = (this.config.rpcApi || ['eth', 'web3', 'net']);
|
||||||
|
|
||||||
GethCommands.prototype.mainCommand = function(address, done) {
|
async.series([
|
||||||
var self = this;
|
function commonOptions(callback) {
|
||||||
var config = this.config;
|
let cmd = self.commonOptions();
|
||||||
var rpc_api = (this.config.rpcApi || ['eth', 'web3', 'net']);
|
callback(null, cmd);
|
||||||
|
},
|
||||||
async.series([
|
function rpcOptions(callback) {
|
||||||
function commonOptions(callback) {
|
let cmd = self.determineRpcOptions(self.config);
|
||||||
var cmd = self.commonOptions();
|
callback(null, cmd);
|
||||||
callback(null, cmd);
|
},
|
||||||
},
|
function dontGetPeers(callback) {
|
||||||
function rpcOptions(callback) {
|
if (config.nodiscover) {
|
||||||
var cmd = self.determineRpcOptions(self.config);
|
return callback(null, "--nodiscover");
|
||||||
callback(null, cmd);
|
}
|
||||||
},
|
callback(null, "");
|
||||||
function dontGetPeers(callback) {
|
},
|
||||||
if (config.nodiscover) {
|
function vmDebug(callback) {
|
||||||
return callback(null, "--nodiscover");
|
if (config.vmdebug) {
|
||||||
|
return callback(null, "--vmdebug");
|
||||||
|
}
|
||||||
|
callback(null, "");
|
||||||
|
},
|
||||||
|
function maxPeers(callback) {
|
||||||
|
let cmd = "--maxpeers " + config.maxpeers;
|
||||||
|
callback(null, cmd);
|
||||||
|
},
|
||||||
|
function mining(callback) {
|
||||||
|
if (config.mineWhenNeeded || config.mine) {
|
||||||
|
return callback(null, "--mine ");
|
||||||
|
}
|
||||||
|
callback("");
|
||||||
|
},
|
||||||
|
function bootnodes(callback) {
|
||||||
|
if (config.bootnodes && config.bootnodes !== "" && config.bootnodes !== []) {
|
||||||
|
return callback(null, "--bootnodes " + config.bootnodes);
|
||||||
|
}
|
||||||
|
callback("");
|
||||||
|
},
|
||||||
|
function whisper(callback) {
|
||||||
|
if (config.whisper) {
|
||||||
|
rpc_api.push('shh');
|
||||||
|
return callback(null, "--shh ");
|
||||||
|
}
|
||||||
|
callback("");
|
||||||
|
},
|
||||||
|
function rpcApi(callback) {
|
||||||
|
callback(null, '--rpcapi "' + rpc_api.join(',') + '"');
|
||||||
|
},
|
||||||
|
function accountToUnlock(callback) {
|
||||||
|
let accountAddress = config.account.address || address;
|
||||||
|
if (accountAddress) {
|
||||||
|
return callback(null, "--unlock=" + accountAddress);
|
||||||
|
}
|
||||||
|
callback(null, "");
|
||||||
|
},
|
||||||
|
function mineWhenNeeded(callback) {
|
||||||
|
if (config.mineWhenNeeded) {
|
||||||
|
return callback(null, "js .embark/" + self.env + "/js/mine.js");
|
||||||
|
}
|
||||||
|
callback(null, "");
|
||||||
}
|
}
|
||||||
callback(null, "");
|
], function (err, results) {
|
||||||
},
|
if (err) {
|
||||||
function vmDebug(callback) {
|
throw new Error(err.message);
|
||||||
if (config.vmdebug) {
|
|
||||||
return callback(null, "--vmdebug");
|
|
||||||
}
|
}
|
||||||
callback(null, "");
|
done(self.geth_bin + " " + results.join(" "));
|
||||||
},
|
});
|
||||||
function maxPeers(callback) {
|
}
|
||||||
var cmd = "--maxpeers " + config.maxpeers;
|
}
|
||||||
callback(null, cmd);
|
|
||||||
},
|
|
||||||
function mining(callback) {
|
|
||||||
if (config.mineWhenNeeded || config.mine) {
|
|
||||||
return callback(null, "--mine ");
|
|
||||||
}
|
|
||||||
callback("");
|
|
||||||
},
|
|
||||||
function bootnodes(callback) {
|
|
||||||
if (config.bootnodes && config.bootnodes !== "" && config.bootnodes !== []) {
|
|
||||||
return callback(null, "--bootnodes " + config.bootnodes);
|
|
||||||
}
|
|
||||||
callback("");
|
|
||||||
},
|
|
||||||
function whisper(callback) {
|
|
||||||
if (config.whisper) {
|
|
||||||
rpc_api.push('shh');
|
|
||||||
return callback(null, "--shh ");
|
|
||||||
}
|
|
||||||
callback("");
|
|
||||||
},
|
|
||||||
function rpcApi(callback) {
|
|
||||||
callback(null, '--rpcapi "' + rpc_api.join(',') + '"');
|
|
||||||
},
|
|
||||||
function accountToUnlock(callback) {
|
|
||||||
var accountAddress = config.account.address || address;
|
|
||||||
if (accountAddress) {
|
|
||||||
return callback(null, "--unlock=" + accountAddress);
|
|
||||||
}
|
|
||||||
callback(null, "");
|
|
||||||
},
|
|
||||||
function mineWhenNeeded(callback) {
|
|
||||||
if (config.mineWhenNeeded) {
|
|
||||||
return callback(null, "js .embark/" + self.env + "/js/mine.js");
|
|
||||||
}
|
|
||||||
callback(null, "");
|
|
||||||
}
|
|
||||||
], function(err, results) {
|
|
||||||
if (err) {
|
|
||||||
throw new Error(err.message);
|
|
||||||
}
|
|
||||||
done(self.geth_bin + " " + results.join(" "));
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = GethCommands;
|
module.exports = GethCommands;
|
||||||
|
|
||||||
|
@ -1,18 +1,20 @@
|
|||||||
var shelljs = require('shelljs');
|
let shelljs = require('shelljs');
|
||||||
|
|
||||||
var Simulator = function(options) {
|
class Simulator {
|
||||||
this.blockchainConfig = options.blockchainConfig;
|
constructor(options) {
|
||||||
};
|
this.blockchainConfig = options.blockchainConfig;
|
||||||
|
}
|
||||||
|
|
||||||
Simulator.prototype.run = function(options) {
|
run(options) {
|
||||||
var cmds = [];
|
let cmds = [];
|
||||||
|
|
||||||
cmds.push("-p " + (this.blockchainConfig.rpcPort || options.port || 8545));
|
cmds.push("-p " + (this.blockchainConfig.rpcPort || options.port || 8545));
|
||||||
cmds.push("-h " + (this.blockchainConfig.rpcHost || options.host || 'localhost'));
|
cmds.push("-h " + (this.blockchainConfig.rpcHost || options.host || 'localhost'));
|
||||||
cmds.push("-a " + (options.num || 10));
|
cmds.push("-a " + (options.num || 10));
|
||||||
|
|
||||||
shelljs.exec('testrpc ' + cmds.join(' '), {async : true});
|
shelljs.exec('testrpc ' + cmds.join(' '), {async : true});
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Simulator;
|
module.exports = Simulator;
|
||||||
|
|
||||||
|
@ -1,33 +1,35 @@
|
|||||||
var fs = require('../core/fs.js');
|
let fs = require('../core/fs.js');
|
||||||
var utils = require('../utils/utils.js');
|
let utils = require('../utils/utils.js');
|
||||||
|
|
||||||
var TemplateGenerator = function(templateName) {
|
class TemplateGenerator {
|
||||||
this.templateName = templateName;
|
constuctor(templateName) {
|
||||||
};
|
this.templateName = templateName;
|
||||||
|
|
||||||
TemplateGenerator.prototype.generate = function(destinationFolder, name) {
|
|
||||||
var templatePath = fs.embarkPath(this.templateName);
|
|
||||||
console.log('Initializing Embark Template....'.green);
|
|
||||||
var fspath = utils.joinPath(destinationFolder, name);
|
|
||||||
|
|
||||||
fs.copySync(templatePath, fspath);
|
|
||||||
utils.cd(fspath);
|
|
||||||
utils.sed('package.json', '%APP_NAME%', name);
|
|
||||||
|
|
||||||
console.log('Installing packages.. this can take a few seconds'.green);
|
|
||||||
utils.runCmd('npm install');
|
|
||||||
console.log('Init complete'.green);
|
|
||||||
console.log('\nApp ready at '.green + fspath);
|
|
||||||
|
|
||||||
if (name === 'embark_demo') {
|
|
||||||
console.log('-------------------'.yellow);
|
|
||||||
console.log('Next steps:'.green);
|
|
||||||
console.log(('-> ' + ('cd ' + fspath).bold.cyan).green);
|
|
||||||
console.log('-> '.green + 'embark blockchain'.bold.cyan + ' or '.green + 'embark simulator'.bold.cyan);
|
|
||||||
console.log('open another console in the same directory and run'.green);
|
|
||||||
console.log('-> '.green + 'embark run'.bold.cyan);
|
|
||||||
console.log('For more info go to http://github.com/iurimatias/embark-framework'.green);
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
generate(destinationFolder, name) {
|
||||||
|
let templatePath = fs.embarkPath(this.templateName);
|
||||||
|
console.log('Initializing Embark Template....'.green);
|
||||||
|
let fspath = utils.joinPath(destinationFolder, name);
|
||||||
|
|
||||||
|
fs.copySync(templatePath, fspath);
|
||||||
|
utils.cd(fspath);
|
||||||
|
utils.sed('package.json', '%APP_NAME%', name);
|
||||||
|
|
||||||
|
console.log('Installing packages.. this can take a few seconds'.green);
|
||||||
|
utils.runCmd('npm install');
|
||||||
|
console.log('Init complete'.green);
|
||||||
|
console.log('\nApp ready at '.green + fspath);
|
||||||
|
|
||||||
|
if (name === 'embark_demo') {
|
||||||
|
console.log('-------------------'.yellow);
|
||||||
|
console.log('Next steps:'.green);
|
||||||
|
console.log(('-> ' + ('cd ' + fspath).bold.cyan).green);
|
||||||
|
console.log('-> '.green + 'embark blockchain'.bold.cyan + ' or '.green + 'embark simulator'.bold.cyan);
|
||||||
|
console.log('open another console in the same directory and run'.green);
|
||||||
|
console.log('-> '.green + 'embark run'.bold.cyan);
|
||||||
|
console.log('For more info go to http://github.com/iurimatias/embark-framework'.green);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = TemplateGenerator;
|
module.exports = TemplateGenerator;
|
||||||
|
@ -1,117 +1,118 @@
|
|||||||
|
class ABIGenerator {
|
||||||
var ABIGenerator = function(options) {
|
constructor(options) {
|
||||||
this.blockchainConfig = options.blockchainConfig || {};
|
this.blockchainConfig = options.blockchainConfig || {};
|
||||||
this.storageConfig = options.storageConfig || {};
|
this.storageConfig = options.storageConfig || {};
|
||||||
this.communicationConfig = options.communicationConfig || {};
|
this.communicationConfig = options.communicationConfig || {};
|
||||||
this.contractsManager = options.contractsManager;
|
this.contractsManager = options.contractsManager;
|
||||||
this.rpcHost = options.blockchainConfig && options.blockchainConfig.rpcHost;
|
this.rpcHost = options.blockchainConfig && options.blockchainConfig.rpcHost;
|
||||||
this.rpcPort = options.blockchainConfig && options.blockchainConfig.rpcPort;
|
this.rpcPort = options.blockchainConfig && options.blockchainConfig.rpcPort;
|
||||||
this.plugins = options.plugins;
|
this.plugins = options.plugins;
|
||||||
};
|
|
||||||
|
|
||||||
ABIGenerator.prototype.generateProvider = function() {
|
|
||||||
var self = this;
|
|
||||||
var result = "";
|
|
||||||
var providerPlugins;
|
|
||||||
|
|
||||||
if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) {
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.plugins) {
|
generateProvider() {
|
||||||
providerPlugins = this.plugins.getPluginsFor('clientWeb3Provider');
|
let self = this;
|
||||||
|
let result = "";
|
||||||
|
let providerPlugins;
|
||||||
|
|
||||||
|
if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.plugins) {
|
||||||
|
providerPlugins = this.plugins.getPluginsFor('clientWeb3Provider');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.plugins && providerPlugins.length > 0) {
|
||||||
|
providerPlugins.forEach(function (plugin) {
|
||||||
|
result += plugin.generateProvider(self) + "\n";
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
result += "\nif (typeof web3 !== 'undefined' && typeof Web3 !== 'undefined') {";
|
||||||
|
result += '\n\tweb3 = new Web3(web3.currentProvider);';
|
||||||
|
result += "\n} else if (typeof Web3 !== 'undefined') {";
|
||||||
|
result += '\n\tweb3 = new Web3(new Web3.providers.HttpProvider("http://' + this.rpcHost + ':' + this.rpcPort + '"));';
|
||||||
|
result += '\n}';
|
||||||
|
result += "\nweb3.eth.defaultAccount = web3.eth.accounts[0];";
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.plugins && providerPlugins.length > 0) {
|
generateContracts(useEmbarkJS) {
|
||||||
providerPlugins.forEach(function(plugin) {
|
let self = this;
|
||||||
result += plugin.generateProvider(self) + "\n";
|
let result = "\n";
|
||||||
});
|
let contractsPlugins;
|
||||||
} else {
|
|
||||||
result += "\nif (typeof web3 !== 'undefined' && typeof Web3 !== 'undefined') {";
|
|
||||||
result += '\n\tweb3 = new Web3(web3.currentProvider);';
|
|
||||||
result += "\n} else if (typeof Web3 !== 'undefined') {";
|
|
||||||
result += '\n\tweb3 = new Web3(new Web3.providers.HttpProvider("http://' + this.rpcHost + ':' + this.rpcPort + '"));';
|
|
||||||
result += '\n}';
|
|
||||||
result += "\nweb3.eth.defaultAccount = web3.eth.accounts[0];";
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) {
|
||||||
};
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
ABIGenerator.prototype.generateContracts = function(useEmbarkJS) {
|
if (this.plugins) {
|
||||||
var self = this;
|
contractsPlugins = this.plugins.getPluginsFor('contractGeneration');
|
||||||
var result = "\n";
|
}
|
||||||
var contractsPlugins;
|
|
||||||
|
|
||||||
if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) {
|
if (this.plugins && contractsPlugins.length > 0) {
|
||||||
return "";
|
contractsPlugins.forEach(function (plugin) {
|
||||||
}
|
result += plugin.generateContracts({contracts: self.contractsManager.contracts});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
for (let className in this.contractsManager.contracts) {
|
||||||
|
let contract = this.contractsManager.contracts[className];
|
||||||
|
|
||||||
if (this.plugins) {
|
let abi = JSON.stringify(contract.abiDefinition);
|
||||||
contractsPlugins = this.plugins.getPluginsFor('contractGeneration');
|
let gasEstimates = JSON.stringify(contract.gasEstimates);
|
||||||
}
|
|
||||||
|
|
||||||
if (this.plugins && contractsPlugins.length > 0) {
|
if (useEmbarkJS) {
|
||||||
contractsPlugins.forEach(function(plugin) {
|
result += "\n" + className + " = new EmbarkJS.Contract({abi: " + abi + ", address: '" + contract.deployedAddress + "', code: '" + contract.code + "', gasEstimates: " + gasEstimates + "});";
|
||||||
result += plugin.generateContracts({contracts: self.contractsManager.contracts});
|
} else {
|
||||||
});
|
result += "\n" + className + "Abi = " + abi + ";";
|
||||||
} else {
|
result += "\n" + className + "Contract = web3.eth.contract(" + className + "Abi);";
|
||||||
for(var className in this.contractsManager.contracts) {
|
result += "\n" + className + " = " + className + "Contract.at('" + contract.deployedAddress + "');";
|
||||||
var contract = this.contractsManager.contracts[className];
|
}
|
||||||
|
|
||||||
var abi = JSON.stringify(contract.abiDefinition);
|
|
||||||
var gasEstimates = JSON.stringify(contract.gasEstimates);
|
|
||||||
|
|
||||||
if (useEmbarkJS) {
|
|
||||||
result += "\n" + className + " = new EmbarkJS.Contract({abi: " + abi + ", address: '" + contract.deployedAddress + "', code: '" + contract.code + "', gasEstimates: " + gasEstimates + "});";
|
|
||||||
} else {
|
|
||||||
result += "\n" + className + "Abi = " + abi + ";";
|
|
||||||
result += "\n" + className + "Contract = web3.eth.contract(" + className + "Abi);";
|
|
||||||
result += "\n" + className + " = " + className + "Contract.at('" + contract.deployedAddress + "');";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
generateStorageInitialization(useEmbarkJS) {
|
||||||
};
|
let self = this;
|
||||||
|
let result = "\n";
|
||||||
|
|
||||||
ABIGenerator.prototype.generateStorageInitialization = function(useEmbarkJS) {
|
if (!useEmbarkJS || self.storageConfig === {}) return "";
|
||||||
var self = this;
|
|
||||||
var result = "\n";
|
|
||||||
|
|
||||||
if (!useEmbarkJS || self.storageConfig === {}) return "";
|
if (self.storageConfig.provider === 'ipfs' && self.storageConfig.enabled === true) {
|
||||||
|
result += "\nEmbarkJS.Storage.setProvider('" + self.storageConfig.provider + "', {server: '" + self.storageConfig.host + "', port: '" + self.storageConfig.port + "'});";
|
||||||
|
}
|
||||||
|
|
||||||
if (self.storageConfig.provider === 'ipfs' && self.storageConfig.enabled === true) {
|
return result;
|
||||||
result += "\nEmbarkJS.Storage.setProvider('" + self.storageConfig.provider + "', {server: '" + self.storageConfig.host + "', port: '" + self.storageConfig.port + "'});";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
generateCommunicationInitialization(useEmbarkJS) {
|
||||||
};
|
let self = this;
|
||||||
|
let result = "\n";
|
||||||
|
|
||||||
ABIGenerator.prototype.generateCommunicationInitialization = function(useEmbarkJS) {
|
if (!useEmbarkJS || self.communicationConfig === {}) return "";
|
||||||
var self = this;
|
|
||||||
var result = "\n";
|
|
||||||
|
|
||||||
if (!useEmbarkJS || self.communicationConfig === {}) return "";
|
if (self.communicationConfig.provider === 'whisper' && self.communicationConfig.enabled === true) {
|
||||||
|
result += "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "');";
|
||||||
|
} else if (self.communicationConfig.provider === 'orbit' && self.communicationConfig.enabled === true) {
|
||||||
|
result += "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "', {server: '" + self.communicationConfig.host + "', port: '" + self.communicationConfig.port + "'});";
|
||||||
|
}
|
||||||
|
|
||||||
if (self.communicationConfig.provider === 'whisper' && self.communicationConfig.enabled === true) {
|
return result;
|
||||||
result += "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "');";
|
|
||||||
} else if (self.communicationConfig.provider === 'orbit' && self.communicationConfig.enabled === true) {
|
|
||||||
result += "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "', {server: '" + self.communicationConfig.host + "', port: '" + self.communicationConfig.port + "'});";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
generateABI(options) {
|
||||||
};
|
let result = "";
|
||||||
|
|
||||||
ABIGenerator.prototype.generateABI = function(options) {
|
result += this.generateProvider();
|
||||||
var result = "";
|
result += this.generateContracts(options.useEmbarkJS);
|
||||||
|
result += this.generateStorageInitialization(options.useEmbarkJS);
|
||||||
|
result += this.generateCommunicationInitialization(options.useEmbarkJS);
|
||||||
|
|
||||||
result += this.generateProvider();
|
return result;
|
||||||
result += this.generateContracts(options.useEmbarkJS);
|
}
|
||||||
result += this.generateStorageInitialization(options.useEmbarkJS);
|
}
|
||||||
result += this.generateCommunicationInitialization(options.useEmbarkJS);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = ABIGenerator;
|
module.exports = ABIGenerator;
|
||||||
|
@ -1,107 +1,108 @@
|
|||||||
/*jshint esversion: 6, loopfunc: true */
|
/*jshint esversion: 6, loopfunc: true */
|
||||||
var async = require('../utils/async_extend.js');
|
let async = require('../utils/async_extend.js');
|
||||||
var SolcW = require('./solcW.js');
|
let SolcW = require('./solcW.js');
|
||||||
|
|
||||||
var Compiler = function(options) {
|
class Compiler {
|
||||||
this.plugins = options.plugins;
|
constructor(options) {
|
||||||
this.logger = options.logger;
|
this.plugins = options.plugins;
|
||||||
};
|
this.logger = options.logger;
|
||||||
|
|
||||||
Compiler.prototype.compile_contracts = function(contractFiles, cb) {
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
var available_compilers = {
|
|
||||||
//".se": this.compile_serpent
|
|
||||||
".sol": this.compile_solidity.bind(this)
|
|
||||||
};
|
|
||||||
|
|
||||||
if (this.plugins) {
|
|
||||||
var compilerPlugins = this.plugins.getPluginsFor('compilers');
|
|
||||||
if (compilerPlugins.length > 0) {
|
|
||||||
compilerPlugins.forEach(function(plugin) {
|
|
||||||
plugin.compilers.forEach(function(compilerObject) {
|
|
||||||
available_compilers[compilerObject.extension] = compilerObject.cb;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var compiledObject = {};
|
compile_contracts(contractFiles, cb) {
|
||||||
|
|
||||||
async.eachObject(available_compilers,
|
let available_compilers = {
|
||||||
function(extension, compiler, callback) {
|
//".se": this.compile_serpent
|
||||||
// TODO: warn about files it doesn't know how to compile
|
".sol": this.compile_solidity.bind(this)
|
||||||
var matchingFiles = contractFiles.filter(function(file) {
|
};
|
||||||
return (file.filename.match(/\.[0-9a-z]+$/)[0] === extension);
|
|
||||||
});
|
|
||||||
|
|
||||||
compiler.call(compiler, matchingFiles || [], function(err, compileResult) {
|
if (this.plugins) {
|
||||||
Object.assign(compiledObject, compileResult);
|
let compilerPlugins = this.plugins.getPluginsFor('compilers');
|
||||||
callback(err, compileResult);
|
if (compilerPlugins.length > 0) {
|
||||||
});
|
compilerPlugins.forEach(function (plugin) {
|
||||||
},
|
plugin.compilers.forEach(function (compilerObject) {
|
||||||
function (err) {
|
available_compilers[compilerObject.extension] = compilerObject.cb;
|
||||||
cb(err, compiledObject);
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
Compiler.prototype.compile_solidity = function(contractFiles, cb) {
|
let compiledObject = {};
|
||||||
var self = this;
|
|
||||||
var input = {};
|
|
||||||
var solcW;
|
|
||||||
async.waterfall([
|
|
||||||
function prepareInput(callback) {
|
|
||||||
for (var i = 0; i < contractFiles.length; i++){
|
|
||||||
// TODO: this depends on the config
|
|
||||||
var filename = contractFiles[i].filename.replace('app/contracts/','');
|
|
||||||
input[filename] = contractFiles[i].content.toString();
|
|
||||||
}
|
|
||||||
callback();
|
|
||||||
},
|
|
||||||
function loadCompiler(callback) {
|
|
||||||
// TODO: there ino need to load this twice
|
|
||||||
solcW = new SolcW();
|
|
||||||
if (solcW.isCompilerLoaded()) {
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
|
|
||||||
self.logger.info("loading solc compiler..");
|
async.eachObject(available_compilers,
|
||||||
solcW.load_compiler(function(){
|
function (extension, compiler, callback) {
|
||||||
callback();
|
// TODO: warn about files it doesn't know how to compile
|
||||||
});
|
let matchingFiles = contractFiles.filter(function (file) {
|
||||||
},
|
return (file.filename.match(/\.[0-9a-z]+$/)[0] === extension);
|
||||||
function compileContracts(callback) {
|
});
|
||||||
self.logger.info("compiling contracts...");
|
|
||||||
solcW.compile({sources: input}, 1, function(output) {
|
compiler.call(compiler, matchingFiles || [], function (err, compileResult) {
|
||||||
if (output.errors) {
|
Object.assign(compiledObject, compileResult);
|
||||||
return callback(new Error ("Solidity errors: " + output.errors).message);
|
callback(err, compileResult);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function (err) {
|
||||||
|
cb(err, compiledObject);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
compile_solidity(contractFiles, cb) {
|
||||||
|
let self = this;
|
||||||
|
let input = {};
|
||||||
|
let solcW;
|
||||||
|
async.waterfall([
|
||||||
|
function prepareInput(callback) {
|
||||||
|
for (let i = 0; i < contractFiles.length; i++) {
|
||||||
|
// TODO: this depends on the config
|
||||||
|
let filename = contractFiles[i].filename.replace('app/contracts/', '');
|
||||||
|
input[filename] = contractFiles[i].content.toString();
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
},
|
||||||
|
function loadCompiler(callback) {
|
||||||
|
// TODO: there ino need to load this twice
|
||||||
|
solcW = new SolcW();
|
||||||
|
if (solcW.isCompilerLoaded()) {
|
||||||
|
return callback();
|
||||||
}
|
}
|
||||||
callback(null, output);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
function createCompiledObject(output, callback) {
|
|
||||||
var json = output.contracts;
|
|
||||||
|
|
||||||
compiled_object = {};
|
self.logger.info("loading solc compiler..");
|
||||||
|
solcW.load_compiler(function () {
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function compileContracts(callback) {
|
||||||
|
self.logger.info("compiling contracts...");
|
||||||
|
solcW.compile({sources: input}, 1, function (output) {
|
||||||
|
if (output.errors) {
|
||||||
|
return callback(new Error("Solidity errors: " + output.errors).message);
|
||||||
|
}
|
||||||
|
callback(null, output);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function createCompiledObject(output, callback) {
|
||||||
|
let json = output.contracts;
|
||||||
|
|
||||||
for (var className in json) {
|
let compiled_object = {};
|
||||||
var contract = json[className];
|
|
||||||
|
|
||||||
compiled_object[className] = {};
|
for (let className in json) {
|
||||||
compiled_object[className].code = contract.bytecode;
|
let contract = json[className];
|
||||||
compiled_object[className].runtimeBytecode = contract.runtimeBytecode;
|
|
||||||
compiled_object[className].realRuntimeBytecode = contract.runtimeBytecode.slice(0, -68);
|
compiled_object[className] = {};
|
||||||
compiled_object[className].swarmHash = contract.runtimeBytecode.slice(-68).slice(0,64);
|
compiled_object[className].code = contract.bytecode;
|
||||||
compiled_object[className].gasEstimates = contract.gasEstimates;
|
compiled_object[className].runtimeBytecode = contract.runtimeBytecode;
|
||||||
compiled_object[className].functionHashes = contract.functionHashes;
|
compiled_object[className].realRuntimeBytecode = contract.runtimeBytecode.slice(0, -68);
|
||||||
compiled_object[className].abiDefinition = JSON.parse(contract.interface);
|
compiled_object[className].swarmHash = contract.runtimeBytecode.slice(-68).slice(0, 64);
|
||||||
|
compiled_object[className].gasEstimates = contract.gasEstimates;
|
||||||
|
compiled_object[className].functionHashes = contract.functionHashes;
|
||||||
|
compiled_object[className].abiDefinition = JSON.parse(contract.interface);
|
||||||
|
}
|
||||||
|
callback(null, compiled_object);
|
||||||
}
|
}
|
||||||
callback(null, compiled_object);
|
], function (err, result) {
|
||||||
}
|
cb(err, result);
|
||||||
], function(err, result) {
|
});
|
||||||
cb(err, result);
|
}
|
||||||
});
|
}
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = Compiler;
|
module.exports = Compiler;
|
||||||
|
@ -1,247 +1,251 @@
|
|||||||
var toposort = require('toposort');
|
let toposort = require('toposort');
|
||||||
var async = require('async');
|
let async = require('async');
|
||||||
|
|
||||||
var Compiler = require('./compiler.js');
|
let Compiler = require('./compiler.js');
|
||||||
|
|
||||||
// TODO: create a contract object
|
// TODO: create a contract object
|
||||||
|
|
||||||
var adjustGas = function(contract) {
|
class ContractsManager {
|
||||||
var maxGas, adjustedGas;
|
constructor(options) {
|
||||||
if (contract.gas === 'auto') {
|
this.contractFiles = options.contractFiles;
|
||||||
if (contract.deploy || contract.deploy === undefined) {
|
this.contractsConfig = options.contractsConfig;
|
||||||
if (contract.gasEstimates.creation !== undefined) {
|
this.contracts = {};
|
||||||
// TODO: should sum it instead
|
this.logger = options.logger;
|
||||||
maxGas = Math.max(contract.gasEstimates.creation[0], contract.gasEstimates.creation[1], 500000);
|
this.plugins = options.plugins;
|
||||||
} else {
|
|
||||||
maxGas = 500000;
|
this.contractDependencies = {};
|
||||||
}
|
|
||||||
} else {
|
|
||||||
maxGas = 500000;
|
|
||||||
}
|
|
||||||
// TODO: put a check so it doesn't go over the block limit
|
|
||||||
adjustedGas = Math.round(maxGas * 1.40);
|
|
||||||
adjustedGas += 25000;
|
|
||||||
contract.gas = adjustedGas;
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
var ContractsManager = function(options) {
|
build(done) {
|
||||||
this.contractFiles = options.contractFiles;
|
let self = this;
|
||||||
this.contractsConfig = options.contractsConfig;
|
async.waterfall([
|
||||||
this.contracts = {};
|
function compileContracts(callback) {
|
||||||
this.logger = options.logger;
|
let compiler = new Compiler({plugins: self.plugins, logger: self.logger});
|
||||||
this.plugins = options.plugins;
|
compiler.compile_contracts(self.contractFiles, function (err, compiledObject) {
|
||||||
|
|
||||||
this.contractDependencies = {};
|
|
||||||
};
|
|
||||||
|
|
||||||
ContractsManager.prototype.build = function(done) {
|
|
||||||
var self = this;
|
|
||||||
async.waterfall([
|
|
||||||
function compileContracts(callback) {
|
|
||||||
var compiler = new Compiler({plugins: self.plugins, logger: self.logger});
|
|
||||||
compiler.compile_contracts(self.contractFiles, function(err, compiledObject) {
|
|
||||||
self.compiledContracts = compiledObject;
|
self.compiledContracts = compiledObject;
|
||||||
callback(err);
|
callback(err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function prepareContractsFromConfig(callback) {
|
function prepareContractsFromConfig(callback) {
|
||||||
var className, contract;
|
let className, contract;
|
||||||
for(className in self.contractsConfig.contracts) {
|
for (className in self.contractsConfig.contracts) {
|
||||||
contract = self.contractsConfig.contracts[className];
|
contract = self.contractsConfig.contracts[className];
|
||||||
|
|
||||||
contract.className = className;
|
contract.className = className;
|
||||||
contract.args = contract.args || [];
|
contract.args = contract.args || [];
|
||||||
|
|
||||||
self.contracts[className] = contract;
|
self.contracts[className] = contract;
|
||||||
}
|
|
||||||
callback();
|
|
||||||
},
|
|
||||||
function setDeployIntention(callback) {
|
|
||||||
var className, contract;
|
|
||||||
for(className in self.contracts) {
|
|
||||||
contract = self.contracts[className];
|
|
||||||
contract.deploy = (contract.deploy === undefined) || contract.deploy;
|
|
||||||
}
|
|
||||||
callback();
|
|
||||||
},
|
|
||||||
function prepareContractsFromCompilation(callback) {
|
|
||||||
var className, compiledContract, contractConfig, contract;
|
|
||||||
for(className in self.compiledContracts) {
|
|
||||||
compiledContract = self.compiledContracts[className];
|
|
||||||
contractConfig = self.contractsConfig.contracts[className];
|
|
||||||
|
|
||||||
contract = self.contracts[className] || {className: className, args: []};
|
|
||||||
|
|
||||||
contract.code = compiledContract.code;
|
|
||||||
contract.runtimeBytecode = compiledContract.runtimeBytecode;
|
|
||||||
contract.realRuntimeBytecode = (contract.realRuntimeBytecode || contract.runtimeBytecode);
|
|
||||||
contract.swarmHash = compiledContract.swarmHash;
|
|
||||||
contract.gasEstimates = compiledContract.gasEstimates;
|
|
||||||
contract.functionHashes = compiledContract.functionHashes;
|
|
||||||
contract.abiDefinition = compiledContract.abiDefinition;
|
|
||||||
|
|
||||||
contract.gas = (contractConfig && contractConfig.gas) || self.contractsConfig.gas || 'auto';
|
|
||||||
adjustGas(contract);
|
|
||||||
|
|
||||||
contract.gasPrice = contract.gasPrice || self.contractsConfig.gasPrice;
|
|
||||||
contract.type = 'file';
|
|
||||||
contract.className = className;
|
|
||||||
|
|
||||||
self.contracts[className] = contract;
|
|
||||||
}
|
|
||||||
callback();
|
|
||||||
},
|
|
||||||
/*eslint complexity: ["error", 11]*/
|
|
||||||
function dealWithSpecialConfigs(callback) {
|
|
||||||
var className, contract, parentContractName, parentContract;
|
|
||||||
|
|
||||||
for(className in self.contracts) {
|
|
||||||
contract = self.contracts[className];
|
|
||||||
|
|
||||||
if (contract.instanceOf === undefined) { continue; }
|
|
||||||
|
|
||||||
parentContractName = contract.instanceOf;
|
|
||||||
parentContract = self.contracts[parentContractName];
|
|
||||||
|
|
||||||
if (parentContract === className) {
|
|
||||||
self.logger.error(className + ": instanceOf is set to itself");
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
callback();
|
||||||
if (parentContract === undefined) {
|
},
|
||||||
self.logger.error(className + ": couldn't find instanceOf contract " + parentContractName);
|
function setDeployIntention(callback) {
|
||||||
continue;
|
let className, contract;
|
||||||
|
for (className in self.contracts) {
|
||||||
|
contract = self.contracts[className];
|
||||||
|
contract.deploy = (contract.deploy === undefined) || contract.deploy;
|
||||||
}
|
}
|
||||||
|
callback();
|
||||||
|
},
|
||||||
|
function prepareContractsFromCompilation(callback) {
|
||||||
|
let className, compiledContract, contractConfig, contract;
|
||||||
|
for (className in self.compiledContracts) {
|
||||||
|
compiledContract = self.compiledContracts[className];
|
||||||
|
contractConfig = self.contractsConfig.contracts[className];
|
||||||
|
|
||||||
if (parentContract.args && parentContract.args.length > 0 && ((contract.args && contract.args.length === 0) || contract.args === undefined)) {
|
contract = self.contracts[className] || {className: className, args: []};
|
||||||
contract.args = parentContract.args;
|
|
||||||
|
contract.code = compiledContract.code;
|
||||||
|
contract.runtimeBytecode = compiledContract.runtimeBytecode;
|
||||||
|
contract.realRuntimeBytecode = (contract.realRuntimeBytecode || contract.runtimeBytecode);
|
||||||
|
contract.swarmHash = compiledContract.swarmHash;
|
||||||
|
contract.gasEstimates = compiledContract.gasEstimates;
|
||||||
|
contract.functionHashes = compiledContract.functionHashes;
|
||||||
|
contract.abiDefinition = compiledContract.abiDefinition;
|
||||||
|
|
||||||
|
contract.gas = (contractConfig && contractConfig.gas) || self.contractsConfig.gas || 'auto';
|
||||||
|
self.adjustGas(contract);
|
||||||
|
|
||||||
|
contract.gasPrice = contract.gasPrice || self.contractsConfig.gasPrice;
|
||||||
|
contract.type = 'file';
|
||||||
|
contract.className = className;
|
||||||
|
|
||||||
|
self.contracts[className] = contract;
|
||||||
}
|
}
|
||||||
|
callback();
|
||||||
|
},
|
||||||
|
/*eslint complexity: ["error", 11]*/
|
||||||
|
function dealWithSpecialConfigs(callback) {
|
||||||
|
let className, contract, parentContractName, parentContract;
|
||||||
|
|
||||||
|
for (className in self.contracts) {
|
||||||
|
contract = self.contracts[className];
|
||||||
|
|
||||||
|
if (contract.instanceOf === undefined) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
parentContractName = contract.instanceOf;
|
||||||
|
parentContract = self.contracts[parentContractName];
|
||||||
|
|
||||||
|
if (parentContract === className) {
|
||||||
|
self.logger.error(className + ": instanceOf is set to itself");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parentContract === undefined) {
|
||||||
|
self.logger.error(className + ": couldn't find instanceOf contract " + parentContractName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parentContract.args && parentContract.args.length > 0 && ((contract.args && contract.args.length === 0) || contract.args === undefined)) {
|
||||||
|
contract.args = parentContract.args;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contract.code !== undefined) {
|
||||||
|
self.logger.error(className + " has code associated to it but it's configured as an instanceOf " + parentContractName);
|
||||||
|
}
|
||||||
|
|
||||||
|
contract.code = parentContract.code;
|
||||||
|
contract.runtimeBytecode = parentContract.runtimeBytecode;
|
||||||
|
contract.gasEstimates = parentContract.gasEstimates;
|
||||||
|
contract.functionHashes = parentContract.functionHashes;
|
||||||
|
contract.abiDefinition = parentContract.abiDefinition;
|
||||||
|
|
||||||
|
contract.gas = contract.gas || parentContract.gas;
|
||||||
|
contract.gasPrice = contract.gasPrice || parentContract.gasPrice;
|
||||||
|
contract.type = 'instance';
|
||||||
|
|
||||||
if (contract.code !== undefined) {
|
|
||||||
self.logger.error(className + " has code associated to it but it's configured as an instanceOf " + parentContractName);
|
|
||||||
}
|
}
|
||||||
|
callback();
|
||||||
|
},
|
||||||
|
function removeContractsWithNoCode(callback) {
|
||||||
|
let className, contract;
|
||||||
|
for (className in self.contracts) {
|
||||||
|
contract = self.contracts[className];
|
||||||
|
|
||||||
contract.code = parentContract.code;
|
if (contract.code === undefined) {
|
||||||
contract.runtimeBytecode = parentContract.runtimeBytecode;
|
self.logger.error(className + " has no code associated");
|
||||||
contract.gasEstimates = parentContract.gasEstimates;
|
delete self.contracts[className];
|
||||||
contract.functionHashes = parentContract.functionHashes;
|
|
||||||
contract.abiDefinition = parentContract.abiDefinition;
|
|
||||||
|
|
||||||
contract.gas = contract.gas || parentContract.gas;
|
|
||||||
contract.gasPrice = contract.gasPrice || parentContract.gasPrice;
|
|
||||||
contract.type = 'instance';
|
|
||||||
|
|
||||||
}
|
|
||||||
callback();
|
|
||||||
},
|
|
||||||
function removeContractsWithNoCode(callback) {
|
|
||||||
var className, contract;
|
|
||||||
for(className in self.contracts) {
|
|
||||||
contract = self.contracts[className];
|
|
||||||
|
|
||||||
if (contract.code === undefined) {
|
|
||||||
self.logger.error(className + " has no code associated");
|
|
||||||
delete self.contracts[className];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.logger.trace(self.contracts);
|
|
||||||
callback();
|
|
||||||
},
|
|
||||||
function determineDependencies(callback) {
|
|
||||||
var className, contract;
|
|
||||||
for(className in self.contracts) {
|
|
||||||
contract = self.contracts[className];
|
|
||||||
|
|
||||||
if (contract.args === []) continue;
|
|
||||||
|
|
||||||
var ref = contract.args;
|
|
||||||
for (var j = 0; j < ref.length; j++) {
|
|
||||||
var arg = ref[j];
|
|
||||||
if (arg[0] === "$") {
|
|
||||||
self.contractDependencies[className] = self.contractDependencies[className] || [];
|
|
||||||
self.contractDependencies[className].push(arg.substr(1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.logger.trace(self.contracts);
|
||||||
|
callback();
|
||||||
|
},
|
||||||
|
function determineDependencies(callback) {
|
||||||
|
let className, contract;
|
||||||
|
for (className in self.contracts) {
|
||||||
|
contract = self.contracts[className];
|
||||||
|
|
||||||
|
if (contract.args === []) continue;
|
||||||
|
|
||||||
|
let ref = contract.args;
|
||||||
|
for (let j = 0; j < ref.length; j++) {
|
||||||
|
let arg = ref[j];
|
||||||
|
if (arg[0] === "$") {
|
||||||
|
self.contractDependencies[className] = self.contractDependencies[className] || [];
|
||||||
|
self.contractDependencies[className].push(arg.substr(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
callback();
|
||||||
}
|
}
|
||||||
callback();
|
], function (err, result) {
|
||||||
}
|
if (err) {
|
||||||
], function(err, result) {
|
self.logger.error("Error Compiling/Building contracts: " + err);
|
||||||
if (err) {
|
}
|
||||||
self.logger.error("Error Compiling/Building contracts: " + err);
|
self.logger.trace("finished".underline);
|
||||||
}
|
done(err, self);
|
||||||
self.logger.trace("finished".underline);
|
});
|
||||||
done(err, self);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
ContractsManager.prototype.getContract = function(className) {
|
|
||||||
return this.contracts[className];
|
|
||||||
};
|
|
||||||
|
|
||||||
ContractsManager.prototype.sortContracts = function(contractList) {
|
|
||||||
var converted_dependencies = [], i;
|
|
||||||
|
|
||||||
for(var contract in this.contractDependencies) {
|
|
||||||
var dependencies = this.contractDependencies[contract];
|
|
||||||
for(i=0; i < dependencies.length; i++) {
|
|
||||||
converted_dependencies.push([contract, dependencies[i]]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var orderedDependencies = toposort(converted_dependencies).reverse();
|
getContract(className) {
|
||||||
|
return this.contracts[className];
|
||||||
var newList = contractList.sort(function(a,b) {
|
|
||||||
var order_a = orderedDependencies.indexOf(a.className);
|
|
||||||
var order_b = orderedDependencies.indexOf(b.className);
|
|
||||||
return order_a - order_b;
|
|
||||||
});
|
|
||||||
|
|
||||||
return newList;
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: should be built contracts
|
|
||||||
ContractsManager.prototype.listContracts = function() {
|
|
||||||
var contracts = [];
|
|
||||||
for(var className in this.contracts) {
|
|
||||||
var contract = this.contracts[className];
|
|
||||||
contracts.push(contract);
|
|
||||||
}
|
}
|
||||||
return this.sortContracts(contracts);
|
|
||||||
};
|
|
||||||
|
|
||||||
ContractsManager.prototype.contractsState = function() {
|
sortContracts(contractList) {
|
||||||
var data = [];
|
let converted_dependencies = [], i;
|
||||||
|
|
||||||
for(var className in this.contracts) {
|
for (let contract in this.contractDependencies) {
|
||||||
var contract = this.contracts[className];
|
let dependencies = this.contractDependencies[contract];
|
||||||
|
for (i = 0; i < dependencies.length; i++) {
|
||||||
var contractData;
|
converted_dependencies.push([contract, dependencies[i]]);
|
||||||
|
}
|
||||||
if (contract.deploy === false) {
|
|
||||||
contractData = [
|
|
||||||
className.green,
|
|
||||||
'Interface or set to not deploy'.green,
|
|
||||||
"\t\tn/a".green
|
|
||||||
];
|
|
||||||
} else if (contract.error) {
|
|
||||||
contractData = [
|
|
||||||
className.green,
|
|
||||||
(contract.error).red,
|
|
||||||
'\t\tError'.red
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
contractData = [
|
|
||||||
className.green,
|
|
||||||
(contract.deployedAddress || '...').green,
|
|
||||||
((contract.deployedAddress !== undefined) ? "\t\tDeployed".green : "\t\tPending".magenta)
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data.push(contractData);
|
let orderedDependencies = toposort(converted_dependencies).reverse();
|
||||||
|
|
||||||
|
let newList = contractList.sort(function (a, b) {
|
||||||
|
let order_a = orderedDependencies.indexOf(a.className);
|
||||||
|
let order_b = orderedDependencies.indexOf(b.className);
|
||||||
|
return order_a - order_b;
|
||||||
|
});
|
||||||
|
|
||||||
|
return newList;
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
// TODO: should be built contracts
|
||||||
};
|
listContracts() {
|
||||||
|
let contracts = [];
|
||||||
|
for (let className in this.contracts) {
|
||||||
|
let contract = this.contracts[className];
|
||||||
|
contracts.push(contract);
|
||||||
|
}
|
||||||
|
return this.sortContracts(contracts);
|
||||||
|
}
|
||||||
|
|
||||||
|
contractsState() {
|
||||||
|
let data = [];
|
||||||
|
|
||||||
|
for (let className in this.contracts) {
|
||||||
|
let contract = this.contracts[className];
|
||||||
|
|
||||||
|
let contractData;
|
||||||
|
|
||||||
|
if (contract.deploy === false) {
|
||||||
|
contractData = [
|
||||||
|
className.green,
|
||||||
|
'Interface or set to not deploy'.green,
|
||||||
|
"\t\tn/a".green
|
||||||
|
];
|
||||||
|
} else if (contract.error) {
|
||||||
|
contractData = [
|
||||||
|
className.green,
|
||||||
|
(contract.error).red,
|
||||||
|
'\t\tError'.red
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
contractData = [
|
||||||
|
className.green,
|
||||||
|
(contract.deployedAddress || '...').green,
|
||||||
|
((contract.deployedAddress !== undefined) ? "\t\tDeployed".green : "\t\tPending".magenta)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
data.push(contractData);
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
adjustGas(contract) {
|
||||||
|
let maxGas, adjustedGas;
|
||||||
|
if (contract.gas === 'auto') {
|
||||||
|
if (contract.deploy || contract.deploy === undefined) {
|
||||||
|
if (contract.gasEstimates.creation !== undefined) {
|
||||||
|
// TODO: should sum it instead
|
||||||
|
maxGas = Math.max(contract.gasEstimates.creation[0], contract.gasEstimates.creation[1], 500000);
|
||||||
|
} else {
|
||||||
|
maxGas = 500000;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
maxGas = 500000;
|
||||||
|
}
|
||||||
|
// TODO: put a check so it doesn't go over the block limit
|
||||||
|
adjustedGas = Math.round(maxGas * 1.40);
|
||||||
|
adjustedGas += 25000;
|
||||||
|
contract.gas = adjustedGas;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = ContractsManager;
|
module.exports = ContractsManager;
|
||||||
|
@ -1,166 +1,168 @@
|
|||||||
var async = require('async');
|
let async = require('async');
|
||||||
|
|
||||||
var RunCode = require('../core/runCode.js');
|
let RunCode = require('../core/runCode.js');
|
||||||
|
|
||||||
var DeployTracker = require('./deploy_tracker.js');
|
let DeployTracker = require('./deploy_tracker.js');
|
||||||
var ABIGenerator = require('./abi.js');
|
let ABIGenerator = require('./abi.js');
|
||||||
|
|
||||||
var Deploy = function(options) {
|
class Deploy {
|
||||||
this.web3 = options.web3;
|
constructor(options) {
|
||||||
this.contractsManager = options.contractsManager;
|
this.web3 = options.web3;
|
||||||
this.logger = options.logger;
|
this.contractsManager = options.contractsManager;
|
||||||
this.env = options.env;
|
this.logger = options.logger;
|
||||||
|
this.env = options.env;
|
||||||
|
|
||||||
this.deployTracker = new DeployTracker({
|
this.deployTracker = new DeployTracker({
|
||||||
logger: options.logger, chainConfig: options.chainConfig, web3: options.web3, env: this.env
|
logger: options.logger, chainConfig: options.chainConfig, web3: options.web3, env: this.env
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
Deploy.prototype.determineArguments = function(suppliedArgs) {
|
|
||||||
var realArgs = [], l, arg, contractName, referedContract;
|
|
||||||
|
|
||||||
for (l = 0; l < suppliedArgs.length; l++) {
|
|
||||||
arg = suppliedArgs[l];
|
|
||||||
if (arg[0] === "$") {
|
|
||||||
contractName = arg.substr(1);
|
|
||||||
referedContract = this.contractsManager.getContract(contractName);
|
|
||||||
realArgs.push(referedContract.deployedAddress);
|
|
||||||
} else {
|
|
||||||
realArgs.push(arg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return realArgs;
|
determineArguments(suppliedArgs) {
|
||||||
};
|
let realArgs = [], l, arg, contractName, referedContract;
|
||||||
|
|
||||||
Deploy.prototype.checkAndDeployContract = function(contract, params, callback) {
|
for (l = 0; l < suppliedArgs.length; l++) {
|
||||||
var self = this;
|
arg = suppliedArgs[l];
|
||||||
var suppliedArgs;
|
if (arg[0] === "$") {
|
||||||
var realArgs;
|
contractName = arg.substr(1);
|
||||||
var arg;
|
referedContract = this.contractsManager.getContract(contractName);
|
||||||
var l;
|
realArgs.push(referedContract.deployedAddress);
|
||||||
var contractName;
|
} else {
|
||||||
var referedContract;
|
realArgs.push(arg);
|
||||||
contract.error = false;
|
|
||||||
|
|
||||||
if (contract.deploy === false) {
|
|
||||||
self.logger.contractsState(self.contractsManager.contractsState());
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (contract.address !== undefined) {
|
|
||||||
|
|
||||||
realArgs = self.determineArguments(params || contract.args);
|
|
||||||
|
|
||||||
contract.deployedAddress = contract.address;
|
|
||||||
self.deployTracker.trackContract(contract.className, contract.realRuntimeBytecode, realArgs, contract.address);
|
|
||||||
self.deployTracker.save();
|
|
||||||
self.logger.contractsState(self.contractsManager.contractsState());
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
|
|
||||||
var trackedContract = self.deployTracker.getContract(contract.className, contract.realRuntimeBytecode, contract.args);
|
|
||||||
|
|
||||||
if (trackedContract && this.web3.eth.getCode(trackedContract.address) !== "0x") {
|
|
||||||
self.logger.info(contract.className.bold.cyan + " already deployed at ".green + trackedContract.address.bold.cyan);
|
|
||||||
contract.deployedAddress = trackedContract.address;
|
|
||||||
self.logger.contractsState(self.contractsManager.contractsState());
|
|
||||||
return callback();
|
|
||||||
} else {
|
|
||||||
|
|
||||||
realArgs = self.determineArguments(params || contract.args);
|
|
||||||
|
|
||||||
this.deployContract(contract, realArgs, function(err, address) {
|
|
||||||
if (err) {
|
|
||||||
return callback(new Error(err));
|
|
||||||
}
|
}
|
||||||
self.deployTracker.trackContract(contract.className, contract.realRuntimeBytecode, realArgs, address);
|
}
|
||||||
|
|
||||||
|
return realArgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkAndDeployContract(contract, params, callback) {
|
||||||
|
let self = this;
|
||||||
|
let suppliedArgs;
|
||||||
|
let realArgs;
|
||||||
|
let arg;
|
||||||
|
let l;
|
||||||
|
let contractName;
|
||||||
|
let referedContract;
|
||||||
|
contract.error = false;
|
||||||
|
|
||||||
|
if (contract.deploy === false) {
|
||||||
|
self.logger.contractsState(self.contractsManager.contractsState());
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contract.address !== undefined) {
|
||||||
|
|
||||||
|
realArgs = self.determineArguments(params || contract.args);
|
||||||
|
|
||||||
|
contract.deployedAddress = contract.address;
|
||||||
|
self.deployTracker.trackContract(contract.className, contract.realRuntimeBytecode, realArgs, contract.address);
|
||||||
self.deployTracker.save();
|
self.deployTracker.save();
|
||||||
self.logger.contractsState(self.contractsManager.contractsState());
|
self.logger.contractsState(self.contractsManager.contractsState());
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
|
|
||||||
if (contract.onDeploy !== undefined) {
|
let trackedContract = self.deployTracker.getContract(contract.className, contract.realRuntimeBytecode, contract.args);
|
||||||
self.logger.info('executing onDeploy commands');
|
|
||||||
var abiGenerator = new ABIGenerator({contractsManager: self.contractsManager});
|
|
||||||
var abi = abiGenerator.generateContracts(false);
|
|
||||||
var cmds = contract.onDeploy.join(';\n');
|
|
||||||
|
|
||||||
RunCode.doEval(abi + "\n" + cmds, self.web3);
|
if (trackedContract && this.web3.eth.getCode(trackedContract.address) !== "0x") {
|
||||||
|
self.logger.info(contract.className.bold.cyan + " already deployed at ".green + trackedContract.address.bold.cyan);
|
||||||
|
contract.deployedAddress = trackedContract.address;
|
||||||
|
self.logger.contractsState(self.contractsManager.contractsState());
|
||||||
|
return callback();
|
||||||
|
} else {
|
||||||
|
|
||||||
|
realArgs = self.determineArguments(params || contract.args);
|
||||||
|
|
||||||
|
this.deployContract(contract, realArgs, function (err, address) {
|
||||||
|
if (err) {
|
||||||
|
return callback(new Error(err));
|
||||||
|
}
|
||||||
|
self.deployTracker.trackContract(contract.className, contract.realRuntimeBytecode, realArgs, address);
|
||||||
|
self.deployTracker.save();
|
||||||
|
self.logger.contractsState(self.contractsManager.contractsState());
|
||||||
|
|
||||||
|
if (contract.onDeploy !== undefined) {
|
||||||
|
self.logger.info('executing onDeploy commands');
|
||||||
|
let abiGenerator = new ABIGenerator({contractsManager: self.contractsManager});
|
||||||
|
let abi = abiGenerator.generateContracts(false);
|
||||||
|
let cmds = contract.onDeploy.join(';\n');
|
||||||
|
|
||||||
|
RunCode.doEval(abi + "\n" + cmds, self.web3);
|
||||||
|
}
|
||||||
|
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
deployContract(contract, params, callback) {
|
||||||
|
let self = this;
|
||||||
|
let contractObject = this.web3.eth.contract(contract.abiDefinition);
|
||||||
|
|
||||||
|
let contractParams = (params || contract.args).slice();
|
||||||
|
|
||||||
|
this.web3.eth.getAccounts(function (err, accounts) {
|
||||||
|
if (err) {
|
||||||
|
return callback(new Error(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
callback();
|
// TODO: probably needs to be defaultAccount
|
||||||
|
// TODO: it wouldn't necessary be the first address
|
||||||
|
// use defined blockchain address or first address
|
||||||
|
contractParams.push({
|
||||||
|
//from: this.web3.eth.coinbase,
|
||||||
|
from: accounts[0],
|
||||||
|
data: "0x" + contract.code,
|
||||||
|
gas: contract.gas,
|
||||||
|
gasPrice: contract.gasPrice
|
||||||
|
});
|
||||||
|
|
||||||
|
self.logger.info("deploying " + contract.className.bold.cyan + " with ".green + contract.gas + " gas".green);
|
||||||
|
contractParams.push(function (err, transaction) {
|
||||||
|
self.logger.contractsState(self.contractsManager.contractsState());
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
self.logger.error("error deploying contract: " + contract.className.cyan);
|
||||||
|
let errMsg = err.toString();
|
||||||
|
if (errMsg === 'Error: The contract code couldn\'t be stored, please check your gas amount.') {
|
||||||
|
errMsg = 'The contract code couldn\'t be stored, out of gas or constructor error';
|
||||||
|
}
|
||||||
|
self.logger.error(errMsg);
|
||||||
|
contract.error = errMsg;
|
||||||
|
return callback(new Error(err));
|
||||||
|
} else if (transaction.address !== undefined) {
|
||||||
|
self.logger.info(contract.className.bold.cyan + " deployed at ".green + transaction.address.bold.cyan);
|
||||||
|
contract.deployedAddress = transaction.address;
|
||||||
|
contract.transactionHash = transaction.transactionHash;
|
||||||
|
return callback(null, transaction.address);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
contractObject["new"].apply(contractObject, contractParams);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
deployAll(done) {
|
||||||
|
let self = this;
|
||||||
|
this.logger.info("deploying contracts");
|
||||||
|
|
||||||
Deploy.prototype.deployContract = function(contract, params, callback) {
|
async.eachOfSeries(this.contractsManager.listContracts(),
|
||||||
var self = this;
|
function (contract, key, callback) {
|
||||||
var contractObject = this.web3.eth.contract(contract.abiDefinition);
|
self.logger.trace(arguments);
|
||||||
|
self.checkAndDeployContract(contract, null, callback);
|
||||||
var contractParams = (params || contract.args).slice();
|
},
|
||||||
|
function (err, results) {
|
||||||
this.web3.eth.getAccounts(function(err, accounts) {
|
if (err) {
|
||||||
if (err) {
|
self.logger.error("error deploying contracts");
|
||||||
return callback(new Error(err));
|
self.logger.error(err.message);
|
||||||
}
|
self.logger.debug(err.stack);
|
||||||
|
|
||||||
// TODO: probably needs to be defaultAccount
|
|
||||||
// TODO: it wouldn't necessary be the first address
|
|
||||||
// use defined blockchain address or first address
|
|
||||||
contractParams.push({
|
|
||||||
//from: this.web3.eth.coinbase,
|
|
||||||
from: accounts[0],
|
|
||||||
data: "0x" + contract.code,
|
|
||||||
gas: contract.gas,
|
|
||||||
gasPrice: contract.gasPrice
|
|
||||||
});
|
|
||||||
|
|
||||||
self.logger.info("deploying " + contract.className.bold.cyan + " with ".green + contract.gas + " gas".green);
|
|
||||||
contractParams.push(function(err, transaction) {
|
|
||||||
self.logger.contractsState(self.contractsManager.contractsState());
|
|
||||||
|
|
||||||
if (err) {
|
|
||||||
self.logger.error("error deploying contract: " + contract.className.cyan);
|
|
||||||
var errMsg = err.toString();
|
|
||||||
if (errMsg === 'Error: The contract code couldn\'t be stored, please check your gas amount.') {
|
|
||||||
errMsg = 'The contract code couldn\'t be stored, out of gas or constructor error';
|
|
||||||
}
|
}
|
||||||
self.logger.error(errMsg);
|
self.logger.info("finished deploying contracts");
|
||||||
contract.error = errMsg;
|
self.logger.trace(arguments);
|
||||||
return callback(new Error(err));
|
done();
|
||||||
} else if (transaction.address !== undefined) {
|
|
||||||
self.logger.info(contract.className.bold.cyan + " deployed at ".green + transaction.address.bold.cyan);
|
|
||||||
contract.deployedAddress = transaction.address;
|
|
||||||
contract.transactionHash = transaction.transactionHash;
|
|
||||||
return callback(null, transaction.address);
|
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
contractObject["new"].apply(contractObject, contractParams);
|
}
|
||||||
});
|
}
|
||||||
};
|
|
||||||
|
|
||||||
Deploy.prototype.deployAll = function(done) {
|
|
||||||
var self = this;
|
|
||||||
this.logger.info("deploying contracts");
|
|
||||||
|
|
||||||
async.eachOfSeries(this.contractsManager.listContracts(),
|
|
||||||
function(contract, key, callback) {
|
|
||||||
self.logger.trace(arguments);
|
|
||||||
self.checkAndDeployContract(contract, null, callback);
|
|
||||||
},
|
|
||||||
function(err, results) {
|
|
||||||
if (err) {
|
|
||||||
self.logger.error("error deploying contracts");
|
|
||||||
self.logger.error(err.message);
|
|
||||||
self.logger.debug(err.stack);
|
|
||||||
}
|
|
||||||
self.logger.info("finished deploying contracts");
|
|
||||||
self.logger.trace(arguments);
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = Deploy;
|
module.exports = Deploy;
|
||||||
|
@ -1,88 +1,91 @@
|
|||||||
var async = require('async');
|
let async = require('async');
|
||||||
|
let Deploy = require('./deploy.js');
|
||||||
|
let ContractsManager = require('./contracts.js');
|
||||||
|
let EventEmitter = require('events');
|
||||||
|
|
||||||
var Deploy = require('./deploy.js');
|
class DeployManager {
|
||||||
var ContractsManager = require('./contracts.js');
|
constructor(options) {
|
||||||
|
this.config = options.config;
|
||||||
var DeployManager = function(options) {
|
this.logger = options.logger;
|
||||||
this.config = options.config;
|
this.blockchainConfig = this.config.blockchainConfig;
|
||||||
this.logger = options.logger;
|
this.plugins = options.plugins;
|
||||||
this.blockchainConfig = this.config.blockchainConfig;
|
this.web3 = options.web3;
|
||||||
this.plugins = options.plugins;
|
this.chainConfig = (options.trackContracts !== false) ? this.config.chainTracker : false;
|
||||||
this.events = options.events;
|
Object.create(EventEmitter.prototype);
|
||||||
this.web3 = options.web3;
|
|
||||||
this.chainConfig = (options.trackContracts !== false) ? this.config.chainTracker : false;
|
|
||||||
};
|
|
||||||
|
|
||||||
DeployManager.prototype.deployContracts = function(done) {
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) {
|
|
||||||
self.logger.info("Blockchain component is disabled in the config".underline);
|
|
||||||
self.events.emit('blockchainDisabled', {});
|
|
||||||
return done();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async.waterfall([
|
deployContracts(done) {
|
||||||
function buildContracts(callback) {
|
let self = this;
|
||||||
var contractsManager = new ContractsManager({
|
|
||||||
contractFiles: self.config.contractsFiles,
|
if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) {
|
||||||
contractsConfig: self.config.contractsConfig,
|
self.logger.info("Blockchain component is disabled in the config".underline);
|
||||||
logger: self.logger,
|
this.emit('blockchainDisabled', {});
|
||||||
plugins: self.plugins
|
return done();
|
||||||
});
|
|
||||||
contractsManager.build(callback);
|
|
||||||
},
|
|
||||||
function checkWeb3IsConnected(contractsManager, callback) {
|
|
||||||
if (!self.web3) {
|
|
||||||
return callback(Error("no web3 instance found"));
|
|
||||||
}
|
}
|
||||||
if (self.web3.currentProvider.isConnected !== undefined && !self.web3.isConnected()) {
|
|
||||||
self.logger.error(("Couldn't connect to an Ethereum node are you sure it's on?").red);
|
async.waterfall([
|
||||||
self.logger.info("make sure you have an Ethereum node or simulator running. e.g 'embark blockchain'".magenta);
|
function buildContracts(callback) {
|
||||||
return callback(Error("error connecting to blockchain node"));
|
let contractsManager = new ContractsManager({
|
||||||
}
|
contractFiles: self.config.contractsFiles,
|
||||||
if (self.web3.currentProvider.isConnected === undefined) {
|
contractsConfig: self.config.contractsConfig,
|
||||||
self.web3.version.getNode(function(err, version) {
|
logger: self.logger,
|
||||||
if (err) {
|
plugins: self.plugins
|
||||||
|
});
|
||||||
|
contractsManager.build(callback);
|
||||||
|
},
|
||||||
|
function checkWeb3IsConnected(contractsManager, callback) {
|
||||||
|
if (!self.web3) {
|
||||||
|
return callback(Error("no web3 instance found"));
|
||||||
|
}
|
||||||
|
if (self.web3.currentProvider.isConnected !== undefined && !self.web3.isConnected()) {
|
||||||
|
self.logger.error(("Couldn't connect to an Ethereum node are you sure it's on?").red);
|
||||||
|
self.logger.info("make sure you have an Ethereum node or simulator running. e.g 'embark blockchain'".magenta);
|
||||||
return callback(Error("error connecting to blockchain node"));
|
return callback(Error("error connecting to blockchain node"));
|
||||||
}
|
}
|
||||||
return callback(null, contractsManager, self.web3);
|
if (self.web3.currentProvider.isConnected === undefined) {
|
||||||
});
|
self.web3.version.getNode(function (err, version) {
|
||||||
} else {
|
if (err) {
|
||||||
return callback(null, contractsManager, self.web3);
|
return callback(Error("error connecting to blockchain node"));
|
||||||
}
|
}
|
||||||
},
|
return callback(null, contractsManager, self.web3);
|
||||||
function setDefaultAccount(contractsManager, web3, callback) {
|
});
|
||||||
web3.eth.getAccounts(function(err, accounts) {
|
} else {
|
||||||
if (err) {
|
return callback(null, contractsManager, self.web3);
|
||||||
return callback(new Error(err));
|
}
|
||||||
|
},
|
||||||
|
function setDefaultAccount(contractsManager, web3, callback) {
|
||||||
|
web3.eth.getAccounts(function (err, accounts) {
|
||||||
|
if (err) {
|
||||||
|
return callback(new Error(err));
|
||||||
|
}
|
||||||
|
let accountConfig = self.config.blockchainConfig.account;
|
||||||
|
let selectedAccount = accountConfig && accountConfig.address;
|
||||||
|
web3.eth.defaultAccount = (selectedAccount || accounts[0]);
|
||||||
|
callback(null, contractsManager, web3);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function deployAllContracts(contractsManager, web3, callback) {
|
||||||
|
let deploy = new Deploy({
|
||||||
|
web3: web3,
|
||||||
|
contractsManager: contractsManager,
|
||||||
|
logger: self.logger,
|
||||||
|
chainConfig: self.chainConfig,
|
||||||
|
env: self.config.env
|
||||||
|
});
|
||||||
|
deploy.deployAll(function () {
|
||||||
|
self.emit('contractsDeployed', contractsManager);
|
||||||
|
callback(null, contractsManager);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
], function (err, result) {
|
||||||
|
if (err) {
|
||||||
|
done(err, null);
|
||||||
|
} else {
|
||||||
|
done(null, result);
|
||||||
}
|
}
|
||||||
var accountConfig = self.config.blockchainConfig.account;
|
|
||||||
var selectedAccount = accountConfig && accountConfig.address;
|
|
||||||
web3.eth.defaultAccount = (selectedAccount || accounts[0]);
|
|
||||||
callback(null, contractsManager, web3);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
function deployAllContracts(contractsManager, web3, callback) {
|
|
||||||
var deploy = new Deploy({
|
|
||||||
web3: web3,
|
|
||||||
contractsManager: contractsManager,
|
|
||||||
logger: self.logger,
|
|
||||||
chainConfig: self.chainConfig,
|
|
||||||
env: self.config.env
|
|
||||||
});
|
|
||||||
deploy.deployAll(function() {
|
|
||||||
self.events.emit('contractsDeployed', contractsManager);
|
|
||||||
callback(null, contractsManager);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
], function(err, result) {
|
|
||||||
if (err) {
|
}
|
||||||
done(err, null);
|
|
||||||
} else {
|
|
||||||
done(null, result);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = DeployManager;
|
module.exports = DeployManager;
|
||||||
|
@ -1,56 +1,62 @@
|
|||||||
var fs = require('../core/fs.js');
|
let fs = require('../core/fs.js');
|
||||||
|
|
||||||
var DeployTracker = function(options) {
|
class DeployTracker {
|
||||||
this.logger = options.logger;
|
constructor(options) {
|
||||||
this.env = options.env;
|
this.logger = options.logger;
|
||||||
this.chainConfig = options.chainConfig;
|
this.env = options.env;
|
||||||
this.web3 = options.web3;
|
this.chainConfig = options.chainConfig;
|
||||||
|
this.web3 = options.web3;
|
||||||
|
|
||||||
if (this.chainConfig === false) {
|
if (this.chainConfig === false) {
|
||||||
this.currentChain = {contracts: []};
|
this.currentChain = {contracts: []};
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: need to make this async
|
||||||
|
let block = this.web3.eth.getBlock(0);
|
||||||
|
let chainId = block.hash;
|
||||||
|
|
||||||
|
if (this.chainConfig[chainId] === undefined) {
|
||||||
|
this.chainConfig[chainId] = {contracts: {}};
|
||||||
|
}
|
||||||
|
|
||||||
|
this.currentChain = this.chainConfig[chainId];
|
||||||
|
|
||||||
|
this.currentChain.name = this.env;
|
||||||
|
// TODO: add other params
|
||||||
|
//this.currentChain.networkId = "";
|
||||||
|
//this.currentChain.networkType = "custom"
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: need to make this async
|
loadConfig(config) {
|
||||||
var block = this.web3.eth.getBlock(0);
|
this.chainConfig = config;
|
||||||
var chainId = block.hash;
|
return this;
|
||||||
|
|
||||||
if (this.chainConfig[chainId] === undefined) {
|
|
||||||
this.chainConfig[chainId] = {contracts: {}};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currentChain = this.chainConfig[chainId];
|
trackContract(contractName, code, args, address) {
|
||||||
|
this.currentChain.contracts[this.web3.sha3(code + contractName + args.join(','))] = {
|
||||||
|
name: contractName,
|
||||||
|
address: address
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
this.currentChain.name = this.env;
|
getContract(contractName, code, args) {
|
||||||
// TODO: add other params
|
let contract = this.currentChain.contracts[this.web3.sha3(code + contractName + args.join(','))];
|
||||||
//this.currentChain.networkId = "";
|
if (contract && contract.address === undefined) {
|
||||||
//this.currentChain.networkType = "custom"
|
return false;
|
||||||
};
|
}
|
||||||
|
return contract;
|
||||||
|
}
|
||||||
|
|
||||||
DeployTracker.prototype.loadConfig = function(config) {
|
// TODO: abstract this
|
||||||
this.chainConfig = config;
|
// chainConfig can be an abstract PersistentObject
|
||||||
return this;
|
save() {
|
||||||
};
|
if (this.chainConfig === false) {
|
||||||
|
return;
|
||||||
DeployTracker.prototype.trackContract = function(contractName, code, args, address) {
|
}
|
||||||
this.currentChain.contracts[this.web3.sha3(code + contractName + args.join(','))] = {
|
fs.writeJSONSync("./chains.json", this.chainConfig);
|
||||||
name: contractName,
|
}
|
||||||
address: address
|
}
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
DeployTracker.prototype.getContract = function(contractName, code, args) {
|
|
||||||
var contract = this.currentChain.contracts[this.web3.sha3(code + contractName + args.join(','))];
|
|
||||||
if (contract && contract.address === undefined) { return false; }
|
|
||||||
return contract;
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: abstract this
|
|
||||||
// chainConfig can be an abstract PersistentObject
|
|
||||||
DeployTracker.prototype.save = function() {
|
|
||||||
if (this.chainConfig === false) { return; }
|
|
||||||
fs.writeJSONSync("./chains.json", this.chainConfig);
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = DeployTracker;
|
module.exports = DeployTracker;
|
||||||
|
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
var solc;
|
let solc;
|
||||||
|
|
||||||
process.on('message', function(msg) {
|
process.on('message', function (msg) {
|
||||||
if (msg.action === 'loadCompiler') {
|
if (msg.action === 'loadCompiler') {
|
||||||
solc = require('solc');
|
solc = require('solc');
|
||||||
process.send({result: "loadedCompiler"});
|
process.send({result: "loadedCompiler"});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg.action === 'compile') {
|
if (msg.action === 'compile') {
|
||||||
var output = solc.compile(msg.obj, msg.optimize);
|
let output = solc.compile(msg.obj, msg.optimize);
|
||||||
process.send({result: "compilation", output: output});
|
process.send({result: "compilation", output: output});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function () {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,36 +1,38 @@
|
|||||||
var utils = require('../utils/utils.js');
|
let utils = require('../utils/utils.js');
|
||||||
var solcProcess;
|
let solcProcess;
|
||||||
var compilerLoaded = false;
|
let compilerLoaded = false;
|
||||||
|
|
||||||
var SolcW = function() {
|
class SolcW {
|
||||||
};
|
|
||||||
|
|
||||||
SolcW.prototype.load_compiler = function(done) {
|
load_compiler(done) {
|
||||||
if (compilerLoaded) { done(); }
|
if (compilerLoaded) {
|
||||||
solcProcess = require('child_process').fork(utils.joinPath(__dirname, '/solcP.js'));
|
done();
|
||||||
solcProcess.once('message', function(msg) {
|
|
||||||
if (msg.result !== 'loadedCompiler') {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
compilerLoaded = true;
|
solcProcess = require('child_process').fork(utils.joinPath(__dirname, '/solcP.js'));
|
||||||
done();
|
solcProcess.once('message', function (msg) {
|
||||||
});
|
if (msg.result !== 'loadedCompiler') {
|
||||||
solcProcess.send({action: 'loadCompiler'});
|
return;
|
||||||
};
|
}
|
||||||
|
compilerLoaded = true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
solcProcess.send({action: 'loadCompiler'});
|
||||||
|
}
|
||||||
|
|
||||||
SolcW.prototype.isCompilerLoaded = function() {
|
isCompilerLoaded() {
|
||||||
return (compilerLoaded === true);
|
return (compilerLoaded === true);
|
||||||
};
|
}
|
||||||
|
|
||||||
SolcW.prototype.compile = function(obj, optimize, done) {
|
compile(obj, optimize, done) {
|
||||||
solcProcess.once('message', function(msg) {
|
solcProcess.once('message', function (msg) {
|
||||||
if (msg.result !== 'compilation') {
|
if (msg.result !== 'compilation') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
done(msg.output);
|
done(msg.output);
|
||||||
});
|
});
|
||||||
solcProcess.send({action: 'compile', obj: obj, optimize: optimize});
|
solcProcess.send({action: 'compile', obj: obj, optimize: optimize});
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = SolcW;
|
module.exports = SolcW;
|
||||||
|
|
||||||
|
@ -1,34 +1,36 @@
|
|||||||
var fs = require('./fs.js');
|
let fs = require('./fs.js');
|
||||||
var Plugins = require('./plugins.js');
|
let Plugins = require('./plugins.js');
|
||||||
var utils = require('../utils/utils.js');
|
let utils = require('../utils/utils.js');
|
||||||
|
|
||||||
// TODO: add wrapper for fs so it can also work in the browser
|
// TODO: add wrapper for fs so it can also work in the browser
|
||||||
// can work with both read and save
|
// can work with both read and save
|
||||||
var Config = function(options) {
|
class Config {
|
||||||
this.env = options.env;
|
constructor(options) {
|
||||||
this.blockchainConfig = {};
|
this.env = options.env;
|
||||||
this.contractsConfig = {};
|
this.blockchainConfig = {};
|
||||||
this.pipelineConfig = {};
|
this.contractsConfig = {};
|
||||||
this.webServerConfig = {};
|
this.pipelineConfig = {};
|
||||||
this.chainTracker = {};
|
this.webServerConfig = {};
|
||||||
this.assetFiles = {};
|
this.chainTracker = {};
|
||||||
this.contractsFiles = [];
|
this.assetFiles = {};
|
||||||
this.configDir = options.configDir || 'config/';
|
this.contractsFiles = [];
|
||||||
this.chainsFile = options.chainsFile || './chains.json';
|
this.configDir = options.configDir || 'config/';
|
||||||
this.plugins = options.plugins;
|
this.chainsFile = options.chainsFile || './chains.json';
|
||||||
this.logger = options.logger;
|
this.plugins = options.plugins;
|
||||||
this.events = options.events;
|
this.logger = options.logger;
|
||||||
};
|
this.events = options.events;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Config.prototype.loadConfigFiles = function(options) {
|
Config.prototype.loadConfigFiles = function (options) {
|
||||||
var interceptLogs = options.interceptLogs;
|
let interceptLogs = options.interceptLogs;
|
||||||
if (options.interceptLogs === undefined) {
|
if (options.interceptLogs === undefined) {
|
||||||
interceptLogs = true;
|
interceptLogs = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if the config file exists
|
//Check if the config file exists
|
||||||
var embarkConfigExists = fs.existsSync(options.embarkConfig);
|
let embarkConfigExists = fs.existsSync(options.embarkConfig);
|
||||||
if(!embarkConfigExists){
|
if (!embarkConfigExists) {
|
||||||
this.logger.error('Cannot find file ' + options.embarkConfig + '. Please ensure you are running this command inside the Dapp folder');
|
this.logger.error('Cannot find file ' + options.embarkConfig + '. Please ensure you are running this command inside the Dapp folder');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
@ -36,23 +38,22 @@ Config.prototype.loadConfigFiles = function(options) {
|
|||||||
this.embarkConfig = fs.readJSONSync(options.embarkConfig);
|
this.embarkConfig = fs.readJSONSync(options.embarkConfig);
|
||||||
this.embarkConfig.plugins = this.embarkConfig.plugins || {};
|
this.embarkConfig.plugins = this.embarkConfig.plugins || {};
|
||||||
|
|
||||||
this.plugins = new Plugins({plugins: this.embarkConfig.plugins, logger: this.logger, interceptLogs: interceptLogs, events: this.events, config: this});
|
this.plugins = new Plugins({
|
||||||
|
plugins: this.embarkConfig.plugins,
|
||||||
|
logger: this.logger,
|
||||||
|
interceptLogs: interceptLogs,
|
||||||
|
events: this.events,
|
||||||
|
config: this
|
||||||
|
});
|
||||||
this.plugins.loadPlugins();
|
this.plugins.loadPlugins();
|
||||||
|
|
||||||
this.loadEmbarkConfigFile();
|
this.load();
|
||||||
this.loadBlockchainConfigFile();
|
|
||||||
this.loadStorageConfigFile();
|
|
||||||
this.loadCommunicationConfigFile();
|
|
||||||
|
|
||||||
this.loadPipelineConfigFile();
|
|
||||||
|
|
||||||
this.loadContractsConfigFile();
|
|
||||||
this.loadWebServerConfigFile();
|
this.loadWebServerConfigFile();
|
||||||
this.loadChainTrackerFile();
|
this.loadChainTrackerFile();
|
||||||
this.loadPluginContractFiles();
|
this.loadPluginContractFiles();
|
||||||
};
|
};
|
||||||
|
|
||||||
Config.prototype.reloadConfig = function() {
|
Config.prototype.load = Config.prototype.reloadConfig = function () {
|
||||||
this.loadEmbarkConfigFile();
|
this.loadEmbarkConfigFile();
|
||||||
this.loadBlockchainConfigFile();
|
this.loadBlockchainConfigFile();
|
||||||
this.loadStorageConfigFile();
|
this.loadStorageConfigFile();
|
||||||
@ -62,8 +63,8 @@ Config.prototype.reloadConfig = function() {
|
|||||||
this.loadChainTrackerFile();
|
this.loadChainTrackerFile();
|
||||||
};
|
};
|
||||||
|
|
||||||
Config.prototype.loadBlockchainConfigFile = function() {
|
Config.prototype.loadBlockchainConfigFile = function () {
|
||||||
var defaultBlockchainConfig = fs.readJSONSync(this.configDir + "blockchain.json");
|
let defaultBlockchainConfig = fs.readJSONSync(this.configDir + "blockchain.json");
|
||||||
this.blockchainConfig = defaultBlockchainConfig[this.env] || {};
|
this.blockchainConfig = defaultBlockchainConfig[this.env] || {};
|
||||||
|
|
||||||
if (this.blockchainConfig.enabled === undefined) {
|
if (this.blockchainConfig.enabled === undefined) {
|
||||||
@ -71,31 +72,32 @@ Config.prototype.loadBlockchainConfigFile = function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Config.prototype.loadContractsConfigFile = function() {
|
Config.prototype.loadContractsConfigFile = function () {
|
||||||
|
|
||||||
var configObject = {};
|
let configObject = {};
|
||||||
|
let configPlugins = [];
|
||||||
var configPlugins = this.plugins.getPluginsFor('contractsConfig');
|
this.plugins.emit('get', 'contractsConfig', (kinds) => {
|
||||||
|
configPlugins = kinds;
|
||||||
|
});
|
||||||
if (configPlugins.length > 0) {
|
if (configPlugins.length > 0) {
|
||||||
configPlugins.forEach(function(plugin) {
|
configPlugins.forEach(function (plugin) {
|
||||||
plugin.contractsConfigs.forEach(function(pluginConfig) {
|
plugin.contractsConfigs.forEach(function (pluginConfig) {
|
||||||
configObject = utils.recursiveMerge(configObject, pluginConfig);
|
configObject = utils.recursiveMerge(configObject, pluginConfig);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var contractsConfig = fs.readJSONSync(this.configDir + "contracts.json");
|
let contractsConfig = fs.readJSONSync(this.configDir + "contracts.json");
|
||||||
configObject = utils.recursiveMerge(configObject, contractsConfig);
|
configObject = utils.recursiveMerge(configObject, contractsConfig);
|
||||||
var defaultContractsConfig = configObject['default'];
|
let defaultContractsConfig = configObject['default'];
|
||||||
var envContractsConfig = configObject[this.env];
|
let envContractsConfig = configObject[this.env];
|
||||||
|
|
||||||
var mergedConfig = utils.recursiveMerge(defaultContractsConfig, envContractsConfig);
|
this.contractsConfig = utils.recursiveMerge(defaultContractsConfig, envContractsConfig);
|
||||||
this.contractsConfig = mergedConfig;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Config.prototype.loadStorageConfigFile = function() {
|
Config.prototype.loadStorageConfigFile = function () {
|
||||||
var configObject = {
|
let configObject = {
|
||||||
"default": {
|
"default": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"available_providers": ["ipfs"],
|
"available_providers": ["ipfs"],
|
||||||
@ -104,11 +106,10 @@ Config.prototype.loadStorageConfigFile = function() {
|
|||||||
"host": "localhost",
|
"host": "localhost",
|
||||||
"port": 5001
|
"port": 5001
|
||||||
},
|
},
|
||||||
"development": {
|
"development": {}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//var configPlugins = this.plugins.getPluginsFor('storageConfig');
|
//let configPlugins = this.plugins.getPluginsFor('storageConfig');
|
||||||
//if (configPlugins.length > 0) {
|
//if (configPlugins.length > 0) {
|
||||||
// configPlugins.forEach(function(plugin) {
|
// configPlugins.forEach(function(plugin) {
|
||||||
// plugin.contractsConfigs.forEach(function(pluginConfig) {
|
// plugin.contractsConfigs.forEach(function(pluginConfig) {
|
||||||
@ -117,16 +118,16 @@ Config.prototype.loadStorageConfigFile = function() {
|
|||||||
// });
|
// });
|
||||||
//}
|
//}
|
||||||
|
|
||||||
var storageConfig;
|
let storageConfig;
|
||||||
if (fs.existsSync(this.configDir + "storage.json")) {
|
if (fs.existsSync(this.configDir + "storage.json")) {
|
||||||
storageConfig = fs.readJSONSync(this.configDir + "storage.json");
|
storageConfig = fs.readJSONSync(this.configDir + "storage.json");
|
||||||
configObject = utils.recursiveMerge(configObject, storageConfig);
|
configObject = utils.recursiveMerge(configObject, storageConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultStorageConfig = configObject['default'];
|
let defaultStorageConfig = configObject['default'];
|
||||||
var envStorageConfig = configObject[this.env];
|
let envStorageConfig = configObject[this.env];
|
||||||
|
|
||||||
var mergedConfig = utils.recursiveMerge(defaultStorageConfig, envStorageConfig);
|
let mergedConfig = utils.recursiveMerge(defaultStorageConfig, envStorageConfig);
|
||||||
this.storageConfig = mergedConfig || {};
|
this.storageConfig = mergedConfig || {};
|
||||||
|
|
||||||
if (this.storageConfig.enabled === undefined) {
|
if (this.storageConfig.enabled === undefined) {
|
||||||
@ -137,8 +138,8 @@ Config.prototype.loadStorageConfigFile = function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Config.prototype.loadCommunicationConfigFile = function() {
|
Config.prototype.loadCommunicationConfigFile = function () {
|
||||||
var configObject = {
|
let configObject = {
|
||||||
"default": {
|
"default": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"provider": "whisper",
|
"provider": "whisper",
|
||||||
@ -146,7 +147,7 @@ Config.prototype.loadCommunicationConfigFile = function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//var configPlugins = this.plugins.getPluginsFor('communicationConfig');
|
//let configPlugins = this.plugins.getPluginsFor('communicationConfig');
|
||||||
//if (configPlugins.length > 0) {
|
//if (configPlugins.length > 0) {
|
||||||
// configPlugins.forEach(function(plugin) {
|
// configPlugins.forEach(function(plugin) {
|
||||||
// plugin.contractsConfigs.forEach(function(pluginConfig) {
|
// plugin.contractsConfigs.forEach(function(pluginConfig) {
|
||||||
@ -155,17 +156,17 @@ Config.prototype.loadCommunicationConfigFile = function() {
|
|||||||
// });
|
// });
|
||||||
//}
|
//}
|
||||||
|
|
||||||
var communicationConfig;
|
let communicationConfig;
|
||||||
|
|
||||||
if (fs.existsSync(this.configDir + "communication.json")) {
|
if (fs.existsSync(this.configDir + "communication.json")) {
|
||||||
communicationConfig = fs.readJSONSync(this.configDir + "communication.json");
|
communicationConfig = fs.readJSONSync(this.configDir + "communication.json");
|
||||||
configObject = utils.recursiveMerge(configObject, communicationConfig);
|
configObject = utils.recursiveMerge(configObject, communicationConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultCommunicationConfig = configObject['default'];
|
let defaultCommunicationConfig = configObject['default'];
|
||||||
var envCommunicationConfig = configObject[this.env];
|
let envCommunicationConfig = configObject[this.env];
|
||||||
|
|
||||||
var mergedConfig = utils.recursiveMerge(defaultCommunicationConfig, envCommunicationConfig);
|
let mergedConfig = utils.recursiveMerge(defaultCommunicationConfig, envCommunicationConfig);
|
||||||
this.communicationConfig = mergedConfig || {};
|
this.communicationConfig = mergedConfig || {};
|
||||||
|
|
||||||
// TODO: probably not necessary if the default object is done right
|
// TODO: probably not necessary if the default object is done right
|
||||||
@ -177,14 +178,14 @@ Config.prototype.loadCommunicationConfigFile = function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Config.prototype.loadWebServerConfigFile = function() {
|
Config.prototype.loadWebServerConfigFile = function () {
|
||||||
var webServerConfigJSON;
|
let webServerConfigJSON;
|
||||||
if (fs.existsSync(this.configDir + "webserver.json")) {
|
if (fs.existsSync(this.configDir + "webserver.json")) {
|
||||||
webServerConfigJSON = fs.readJSONSync(this.configDir + "webserver.json");
|
webServerConfigJSON = fs.readJSONSync(this.configDir + "webserver.json");
|
||||||
} else {
|
} else {
|
||||||
webServerConfigJSON = {};
|
webServerConfigJSON = {};
|
||||||
}
|
}
|
||||||
var defaultWebConfig = {
|
let defaultWebConfig = {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"host": "localhost",
|
"host": "localhost",
|
||||||
"port": 8000
|
"port": 8000
|
||||||
@ -192,28 +193,28 @@ Config.prototype.loadWebServerConfigFile = function() {
|
|||||||
this.webServerConfig = utils.recursiveMerge(defaultWebConfig, webServerConfigJSON);
|
this.webServerConfig = utils.recursiveMerge(defaultWebConfig, webServerConfigJSON);
|
||||||
};
|
};
|
||||||
|
|
||||||
Config.prototype.loadEmbarkConfigFile = function() {
|
Config.prototype.loadEmbarkConfigFile = function () {
|
||||||
var contracts = this.embarkConfig.contracts;
|
let contracts = this.embarkConfig.contracts;
|
||||||
this.contractsFiles = this.loadFiles(contracts);
|
this.contractsFiles = this.loadFiles(contracts);
|
||||||
|
|
||||||
this.buildDir = this.embarkConfig.buildDir;
|
this.buildDir = this.embarkConfig.buildDir;
|
||||||
this.configDir = this.embarkConfig.config;
|
this.configDir = this.embarkConfig.config;
|
||||||
};
|
};
|
||||||
|
|
||||||
Config.prototype.loadPipelineConfigFile = function() {
|
Config.prototype.loadPipelineConfigFile = function () {
|
||||||
var assets = this.embarkConfig.app;
|
let assets = this.embarkConfig.app;
|
||||||
for(var targetFile in assets) {
|
for (let targetFile in assets) {
|
||||||
this.assetFiles[targetFile] = this.loadFiles(assets[targetFile]);
|
this.assetFiles[targetFile] = this.loadFiles(assets[targetFile]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Config.prototype.loadChainTrackerFile = function() {
|
Config.prototype.loadChainTrackerFile = function () {
|
||||||
//var self = this;
|
//let self = this;
|
||||||
var chainTracker;
|
let chainTracker;
|
||||||
try {
|
try {
|
||||||
chainTracker = fs.readJSONSync(this.chainsFile);
|
chainTracker = fs.readJSONSync(this.chainsFile);
|
||||||
}
|
}
|
||||||
catch(err) {
|
catch (err) {
|
||||||
//self.logger.info(this.chainsFile + ' file not found, creating it...');
|
//self.logger.info(this.chainsFile + ' file not found, creating it...');
|
||||||
chainTracker = {};
|
chainTracker = {};
|
||||||
fs.writeJSONSync(this.chainsFile, {});
|
fs.writeJSONSync(this.chainsFile, {});
|
||||||
@ -221,65 +222,85 @@ Config.prototype.loadChainTrackerFile = function() {
|
|||||||
this.chainTracker = chainTracker;
|
this.chainTracker = chainTracker;
|
||||||
};
|
};
|
||||||
|
|
||||||
Config.prototype.loadFiles = function(files) {
|
Config.prototype.loadFiles = function (files) {
|
||||||
var self = this;
|
let self = this;
|
||||||
var originalFiles = utils.filesMatchingPattern(files);
|
let originalFiles = utils.filesMatchingPattern(files);
|
||||||
var readFiles = [];
|
let readFiles = [];
|
||||||
|
|
||||||
// get embark.js object first
|
// get embark.js object first
|
||||||
originalFiles.filter(function(file) {
|
originalFiles.filter(function (file) {
|
||||||
return file.indexOf('.') >= 0;
|
return file.indexOf('.') >= 0;
|
||||||
}).filter(function(file) {
|
}).filter(function (file) {
|
||||||
if (file === 'embark.js') {
|
if (file === 'embark.js') {
|
||||||
|
|
||||||
if (self.blockchainConfig.enabled || self.communicationConfig.provider === 'whisper' || self.communicationConfig.available_providers.indexOf('whisper') >= 0) {
|
if (self.blockchainConfig.enabled || self.communicationConfig.provider === 'whisper' || self.communicationConfig.available_providers.indexOf('whisper') >= 0) {
|
||||||
readFiles.push({filename: 'web3.js', content: fs.readFileSync(fs.embarkPath("js/web3.js")).toString(), path: fs.embarkPath("js/web3.js")});
|
readFiles.push({
|
||||||
|
filename: 'web3.js',
|
||||||
|
content: fs.readFileSync(fs.embarkPath("js/web3.js")).toString(),
|
||||||
|
path: fs.embarkPath("js/web3.js")
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.storageConfig.enabled && (self.storageConfig.provider === 'ipfs' || self.storageConfig.available_providers.indexOf('ipfs') >= 0)) {
|
if (self.storageConfig.enabled && (self.storageConfig.provider === 'ipfs' || self.storageConfig.available_providers.indexOf('ipfs') >= 0)) {
|
||||||
readFiles.push({filename: 'ipfs.js', content: fs.readFileSync(fs.embarkPath("js/ipfs.js")).toString(), path: fs.embarkPath("js/ipfs.js")});
|
readFiles.push({
|
||||||
|
filename: 'ipfs.js',
|
||||||
|
content: fs.readFileSync(fs.embarkPath("js/ipfs.js")).toString(),
|
||||||
|
path: fs.embarkPath("js/ipfs.js")
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.communicationConfig.enabled && (self.communicationConfig.provider === 'orbit' || self.communicationConfig.available_providers.indexOf('orbit') >= 0)) {
|
if (self.communicationConfig.enabled && (self.communicationConfig.provider === 'orbit' || self.communicationConfig.available_providers.indexOf('orbit') >= 0)) {
|
||||||
// TODO: remove duplicated files if functionality is the same for storage and orbit
|
// TODO: remove duplicated files if functionality is the same for storage and orbit
|
||||||
readFiles.push({filename: 'ipfs-api.js', content: fs.readFileSync(fs.embarkPath("js/ipfs-api.min.js")).toString(), path: fs.embarkPath("js/ipfs-api.min.js")});
|
readFiles.push({
|
||||||
readFiles.push({filename: 'orbit.js', content: fs.readFileSync(fs.embarkPath("js/orbit.min.js")).toString(), path: fs.embarkPath("js/orbit.min.js")});
|
filename: 'ipfs-api.js',
|
||||||
|
content: fs.readFileSync(fs.embarkPath("js/ipfs-api.min.js")).toString(),
|
||||||
|
path: fs.embarkPath("js/ipfs-api.min.js")
|
||||||
|
});
|
||||||
|
readFiles.push({
|
||||||
|
filename: 'orbit.js',
|
||||||
|
content: fs.readFileSync(fs.embarkPath("js/orbit.min.js")).toString(),
|
||||||
|
path: fs.embarkPath("js/orbit.min.js")
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
readFiles.push({filename: 'embark.js', content: fs.readFileSync(fs.embarkPath("js/build/embark.bundle.js")).toString(), path: fs.embarkPath("js/build/embark.bundle.js")});
|
readFiles.push({
|
||||||
|
filename: 'embark.js',
|
||||||
|
content: fs.readFileSync(fs.embarkPath("js/build/embark.bundle.js")).toString(),
|
||||||
|
path: fs.embarkPath("js/build/embark.bundle.js")
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// get plugins
|
// get plugins
|
||||||
var filesFromPlugins = [];
|
let filesFromPlugins = [];
|
||||||
|
|
||||||
var filePlugins = self.plugins.getPluginsFor('pipelineFiles');
|
let filePlugins = self.plugins.getPluginsFor('pipelineFiles');
|
||||||
|
|
||||||
if (filePlugins.length > 0) {
|
if (filePlugins.length > 0) {
|
||||||
filePlugins.forEach(function(plugin) {
|
filePlugins.forEach(function (plugin) {
|
||||||
try {
|
try {
|
||||||
var fileObjects = plugin.runFilePipeline();
|
let fileObjects = plugin.runFilePipeline();
|
||||||
for (var i=0; i < fileObjects.length; i++) {
|
for (let i = 0; i < fileObjects.length; i++) {
|
||||||
var fileObject = fileObjects[i];
|
let fileObject = fileObjects[i];
|
||||||
filesFromPlugins.push(fileObject);
|
filesFromPlugins.push(fileObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(err) {
|
catch (err) {
|
||||||
self.logger.error(err.message);
|
self.logger.error(err.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
filesFromPlugins.filter(function(file) {
|
filesFromPlugins.filter(function (file) {
|
||||||
if (utils.fileMatchesPattern(files, file.intendedPath)) {
|
if (utils.fileMatchesPattern(files, file.intendedPath)) {
|
||||||
readFiles.push(file);
|
readFiles.push(file);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// get user files
|
// get user files
|
||||||
originalFiles.filter(function(file) {
|
originalFiles.filter(function (file) {
|
||||||
return file.indexOf('.') >= 0;
|
return file.indexOf('.') >= 0;
|
||||||
}).filter(function(file) {
|
}).filter(function (file) {
|
||||||
if (file === 'embark.js') {
|
if (file === 'embark.js') {
|
||||||
return;
|
return;
|
||||||
} else if (file === 'abi.js') {
|
} else if (file === 'abi.js') {
|
||||||
@ -292,15 +313,19 @@ Config.prototype.loadFiles = function(files) {
|
|||||||
return readFiles;
|
return readFiles;
|
||||||
};
|
};
|
||||||
|
|
||||||
Config.prototype.loadPluginContractFiles = function() {
|
Config.prototype.loadPluginContractFiles = function () {
|
||||||
var self = this;
|
let self = this;
|
||||||
|
|
||||||
var contractsPlugins = this.plugins.getPluginsFor('contractFiles');
|
let contractsPlugins = this.plugins.getPluginsFor('contractFiles');
|
||||||
if (contractsPlugins.length > 0) {
|
if (contractsPlugins.length > 0) {
|
||||||
contractsPlugins.forEach(function(plugin) {
|
contractsPlugins.forEach(function (plugin) {
|
||||||
plugin.contractsFiles.forEach(function(file) {
|
plugin.contractsFiles.forEach(function (file) {
|
||||||
var filename = file.replace('./','');
|
let filename = file.replace('./', '');
|
||||||
self.contractsFiles.push({filename: filename, content: plugin.loadPluginFile(file), path: plugin.pathToFile(file)});
|
self.contractsFiles.push({
|
||||||
|
filename: filename,
|
||||||
|
content: plugin.loadPluginFile(file),
|
||||||
|
path: plugin.pathToFile(file)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
class Core {
|
||||||
|
|
||||||
var Core = function() {};
|
}
|
||||||
|
|
||||||
module.exports = Core;
|
module.exports = Core;
|
||||||
|
|
||||||
|
@ -1,244 +1,249 @@
|
|||||||
var http = require('http');
|
let http = require('http');
|
||||||
var Web3 = require('web3');
|
let Web3 = require('web3');
|
||||||
var utils = require('../utils/utils.js');
|
let utils = require('../utils/utils.js');
|
||||||
|
let Events = require('./events.js');
|
||||||
|
let Logger = require('./logger.js');
|
||||||
|
let Config = require('./config.js');
|
||||||
|
let DeployManager = require('../contracts/deploy_manager.js');
|
||||||
|
let ABIGenerator = require('../contracts/abi.js');
|
||||||
|
let ServicesMonitor = require('./services_monitor.js');
|
||||||
|
let Pipeline = require('../pipeline/pipeline.js');
|
||||||
|
let Server = require('../pipeline/server.js');
|
||||||
|
let Watch = require('../pipeline/watch.js');
|
||||||
|
let version = require('../../package.json');
|
||||||
|
|
||||||
var Events = require('./events.js');
|
class Engine {
|
||||||
var Logger = require('./logger.js');
|
constructor(options) {
|
||||||
var Config = require('./config.js');
|
this.env = options.env;
|
||||||
|
this.embarkConfig = options.embarkConfig;
|
||||||
|
this.interceptLogs = options.interceptLogs;
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
var DeployManager = require('../contracts/deploy_manager.js');
|
init(_options) {
|
||||||
var ABIGenerator = require('../contracts/abi.js');
|
let self = this;
|
||||||
var ServicesMonitor = require('./services_monitor.js');
|
let options = _options || {};
|
||||||
var Pipeline = require('../pipeline/pipeline.js');
|
this.events = new Events();
|
||||||
var Server = require('../pipeline/server.js');
|
this.logger = options.logger || new Logger({logLevel: 'debug'});
|
||||||
var Watch = require('../pipeline/watch.js');
|
this.config = new Config({env: this.env, logger: this.logger, events: this.events});
|
||||||
var version = require('../../package.json').version;
|
this.config.loadConfigFiles({embarkConfig: this.embarkConfig, interceptLogs: this.interceptLogs});
|
||||||
|
this.plugins = this.config.plugins;
|
||||||
|
|
||||||
var Engine = function(options) {
|
this.servicesMonitor = new ServicesMonitor({events: this.events, logger: this.logger});
|
||||||
this.env = options.env;
|
this.servicesMonitor.addCheck('embarkVersion', function (cb) {
|
||||||
this.embarkConfig = options.embarkConfig;
|
return cb({name: 'Embark ' + self.version, status: 'green'});
|
||||||
this.interceptLogs = options.interceptLogs;
|
}, 0);
|
||||||
this.version = version;
|
}
|
||||||
};
|
|
||||||
|
|
||||||
Engine.prototype.init = function(_options) {
|
startMonitor() {
|
||||||
var self = this;
|
let self = this;
|
||||||
var options = _options || {};
|
if (this.plugins) {
|
||||||
this.events = new Events();
|
let servicePlugins = this.plugins.getPluginsFor('serviceChecks');
|
||||||
this.logger = options.logger || new Logger({logLevel: 'debug'});
|
servicePlugins.forEach(function (plugin) {
|
||||||
this.config = new Config({env: this.env, logger: this.logger, events: this.events});
|
plugin.serviceChecks.forEach(function (pluginCheck) {
|
||||||
this.config.loadConfigFiles({embarkConfig: this.embarkConfig, interceptLogs: this.interceptLogs});
|
self.servicesMonitor.addCheck(pluginCheck.checkName, pluginCheck.checkFn, pluginCheck.time);
|
||||||
this.plugins = this.config.plugins;
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.servicesMonitor.startMonitor();
|
||||||
|
}
|
||||||
|
|
||||||
this.servicesMonitor = new ServicesMonitor({events: this.events, logger: this.logger});
|
startService(serviceName, _options) {
|
||||||
this.servicesMonitor.addCheck('embarkVersion', function(cb) {
|
let options = _options || {};
|
||||||
return cb({name: 'Embark ' + self.version, status: 'green'});
|
|
||||||
}, 0);
|
|
||||||
};
|
|
||||||
|
|
||||||
Engine.prototype.startMonitor = function() {
|
let services = {
|
||||||
var self = this;
|
"pipeline": this.pipelineService,
|
||||||
if (this.plugins) {
|
"abi": this.abiService,
|
||||||
var servicePlugins = this.plugins.getPluginsFor('serviceChecks');
|
"deployment": this.deploymentService,
|
||||||
servicePlugins.forEach(function(plugin) {
|
"fileWatcher": this.fileWatchService,
|
||||||
plugin.serviceChecks.forEach(function(pluginCheck) {
|
"webServer": this.webServerService,
|
||||||
self.servicesMonitor.addCheck(pluginCheck.checkName, pluginCheck.checkFn, pluginCheck.time);
|
"ipfs": this.ipfsService,
|
||||||
|
"web3": this.web3Service
|
||||||
|
};
|
||||||
|
|
||||||
|
let service = services[serviceName];
|
||||||
|
|
||||||
|
if (!service) {
|
||||||
|
throw new Error("unknown service: " + serviceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// need to be careful with circular references due to passing the web3 object
|
||||||
|
//this.logger.trace("calling: " + serviceName + "(" + JSON.stringify(options) + ")");
|
||||||
|
return service.apply(this, [options]);
|
||||||
|
}
|
||||||
|
|
||||||
|
pipelineService(options) {
|
||||||
|
let self = this;
|
||||||
|
this.logger.setStatus("Building Assets");
|
||||||
|
let pipeline = new Pipeline({
|
||||||
|
buildDir: this.config.buildDir,
|
||||||
|
contractsFiles: this.config.contractsFiles,
|
||||||
|
assetFiles: this.config.assetFiles,
|
||||||
|
logger: this.logger,
|
||||||
|
plugins: this.plugins
|
||||||
|
});
|
||||||
|
this.events.on('abi', function (abi) {
|
||||||
|
self.currentAbi = abi;
|
||||||
|
pipeline.build(abi);
|
||||||
|
self.events.emit('outputDone');
|
||||||
|
});
|
||||||
|
// TODO: still need to redeploy contracts because the original contracts
|
||||||
|
// config is being corrupted
|
||||||
|
//this.events.on('file-event', function(fileType, path) {
|
||||||
|
// if (fileType === 'asset') {
|
||||||
|
// self.config.reloadConfig();
|
||||||
|
// pipeline.build(self.abi, path);
|
||||||
|
// self.events.emit('outputDone');
|
||||||
|
// }
|
||||||
|
//});
|
||||||
|
}
|
||||||
|
|
||||||
|
abiService(options) {
|
||||||
|
let self = this;
|
||||||
|
let generateABICode = function (contractsManager) {
|
||||||
|
let abiGenerator = new ABIGenerator({
|
||||||
|
blockchainConfig: self.config.blockchainConfig,
|
||||||
|
contractsManager: contractsManager,
|
||||||
|
plugins: self.plugins,
|
||||||
|
storageConfig: self.config.storageConfig,
|
||||||
|
communicationConfig: self.config.communicationConfig
|
||||||
|
});
|
||||||
|
let embarkJSABI = abiGenerator.generateABI({useEmbarkJS: true});
|
||||||
|
let vanillaABI = abiGenerator.generateABI({useEmbarkJS: false});
|
||||||
|
let vanillaContractsABI = abiGenerator.generateContracts(false);
|
||||||
|
|
||||||
|
self.events.emit('abi-contracts-vanila', vanillaContractsABI);
|
||||||
|
self.events.emit('abi-vanila', vanillaABI);
|
||||||
|
self.events.emit('abi', embarkJSABI);
|
||||||
|
};
|
||||||
|
this.events.on('contractsDeployed', generateABICode);
|
||||||
|
this.events.on('blockchainDisabled', generateABICode);
|
||||||
|
}
|
||||||
|
|
||||||
|
deploymentService(options) {
|
||||||
|
let self = this;
|
||||||
|
this.deployManager = new DeployManager({
|
||||||
|
web3: options.web3 || self.web3,
|
||||||
|
trackContracts: options.trackContracts,
|
||||||
|
config: this.config,
|
||||||
|
logger: this.logger,
|
||||||
|
plugins: this.plugins,
|
||||||
|
events: this.events
|
||||||
|
});
|
||||||
|
|
||||||
|
this.events.on('file-event', function (fileType, path) {
|
||||||
|
// TODO: for now need to deploy on asset chanes as well
|
||||||
|
// because the contractsManager config is corrupted after a deploy
|
||||||
|
//if (fileType === 'contract' || fileType === 'config') {
|
||||||
|
self.config.reloadConfig();
|
||||||
|
self.deployManager.deployContracts(function () {
|
||||||
|
});
|
||||||
|
//}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fileWatchService(options) {
|
||||||
|
this.logger.setStatus("Watching for changes");
|
||||||
|
let watch = new Watch({logger: this.logger, events: this.events});
|
||||||
|
watch.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
webServerService(options) {
|
||||||
|
let self = this;
|
||||||
|
let webServerConfig = this.config.webServerConfig;
|
||||||
|
if (!webServerConfig.enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let host = options.host || webServerConfig.host;
|
||||||
|
let port = options.port || webServerConfig.port;
|
||||||
|
|
||||||
|
this.logger.setStatus("Starting Server");
|
||||||
|
let server = new Server({
|
||||||
|
logger: this.logger,
|
||||||
|
host: host,
|
||||||
|
port: port
|
||||||
|
});
|
||||||
|
|
||||||
|
self.servicesMonitor.addCheck('Webserver', function (cb) {
|
||||||
|
let devServer = 'Webserver (http://' + host + ':' + port + ')';
|
||||||
|
return cb({name: devServer, status: 'green'});
|
||||||
|
});
|
||||||
|
|
||||||
|
server.start(function () {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ipfsService(options) {
|
||||||
|
let self = this;
|
||||||
|
self.servicesMonitor.addCheck('IPFS', function (cb) {
|
||||||
|
utils.checkIsAvailable('http://localhost:5001', function (available) {
|
||||||
|
if (available) {
|
||||||
|
//Ideally this method should be in an IPFS API JSONRPC wrapper
|
||||||
|
//The URL should also be flexible to accept non-default IPFS url
|
||||||
|
self.logger.trace("Checking IPFS version...");
|
||||||
|
http.get('http://localhost:5001/api/v0/version', function (res) {
|
||||||
|
let body = '';
|
||||||
|
res.on('data', function (d) {
|
||||||
|
body += d;
|
||||||
|
});
|
||||||
|
res.on('end', function () {
|
||||||
|
try {
|
||||||
|
let parsed = JSON.parse(body);
|
||||||
|
if (parsed.Version) {
|
||||||
|
return cb({name: ("IPFS " + parsed.Version), status: 'green'});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return cb({name: "IPFS ", status: 'green'});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
return cb({name: "IPFS ", status: 'red'});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
res.on('error', function (err) {
|
||||||
|
self.logger.trace("Check IPFS version error: " + err);
|
||||||
|
return cb({name: "IPFS ", status: 'red'});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return cb({name: "IPFS ", status: 'red'});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.servicesMonitor.startMonitor();
|
|
||||||
};
|
|
||||||
|
|
||||||
Engine.prototype.startService = function(serviceName, _options) {
|
web3Service(options) {
|
||||||
var options = _options || {};
|
let self = this;
|
||||||
|
this.web3 = options.web3;
|
||||||
var services = {
|
if (this.web3 === undefined) {
|
||||||
"pipeline": this.pipelineService,
|
this.web3 = new Web3();
|
||||||
"abi": this.abiService,
|
let web3Endpoint = 'http://' + this.config.blockchainConfig.rpcHost + ':' + this.config.blockchainConfig.rpcPort;
|
||||||
"deployment": this.deploymentService,
|
this.web3.setProvider(new this.web3.providers.HttpProvider(web3Endpoint));
|
||||||
"fileWatcher": this.fileWatchService,
|
|
||||||
"webServer": this.webServerService,
|
|
||||||
"ipfs": this.ipfsService,
|
|
||||||
"web3": this.web3Service
|
|
||||||
};
|
|
||||||
|
|
||||||
var service = services[serviceName];
|
|
||||||
|
|
||||||
if (!service) {
|
|
||||||
throw new Error("unknown service: " + serviceName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// need to be careful with circular references due to passing the web3 object
|
|
||||||
//this.logger.trace("calling: " + serviceName + "(" + JSON.stringify(options) + ")");
|
|
||||||
return service.apply(this, [options]);
|
|
||||||
};
|
|
||||||
|
|
||||||
Engine.prototype.pipelineService = function(options) {
|
|
||||||
var self = this;
|
|
||||||
this.logger.setStatus("Building Assets");
|
|
||||||
var pipeline = new Pipeline({
|
|
||||||
buildDir: this.config.buildDir,
|
|
||||||
contractsFiles: this.config.contractsFiles,
|
|
||||||
assetFiles: this.config.assetFiles,
|
|
||||||
logger: this.logger,
|
|
||||||
plugins: this.plugins
|
|
||||||
});
|
|
||||||
this.events.on('abi', function(abi) {
|
|
||||||
self.currentAbi = abi;
|
|
||||||
pipeline.build(abi);
|
|
||||||
self.events.emit('outputDone');
|
|
||||||
});
|
|
||||||
// TODO: still need to redeploy contracts because the original contracts
|
|
||||||
// config is being corrupted
|
|
||||||
//this.events.on('file-event', function(fileType, path) {
|
|
||||||
// if (fileType === 'asset') {
|
|
||||||
// self.config.reloadConfig();
|
|
||||||
// pipeline.build(self.abi, path);
|
|
||||||
// self.events.emit('outputDone');
|
|
||||||
// }
|
|
||||||
//});
|
|
||||||
};
|
|
||||||
|
|
||||||
Engine.prototype.abiService = function(options) {
|
|
||||||
var self = this;
|
|
||||||
var generateABICode = function(contractsManager) {
|
|
||||||
var abiGenerator = new ABIGenerator({
|
|
||||||
blockchainConfig: self.config.blockchainConfig,
|
|
||||||
contractsManager: contractsManager,
|
|
||||||
plugins: self.plugins,
|
|
||||||
storageConfig: self.config.storageConfig,
|
|
||||||
communicationConfig: self.config.communicationConfig
|
|
||||||
});
|
|
||||||
var embarkJSABI = abiGenerator.generateABI({useEmbarkJS: true});
|
|
||||||
var vanillaABI = abiGenerator.generateABI({useEmbarkJS: false});
|
|
||||||
var vanillaContractsABI = abiGenerator.generateContracts(false);
|
|
||||||
|
|
||||||
self.events.emit('abi-contracts-vanila', vanillaContractsABI);
|
|
||||||
self.events.emit('abi-vanila', vanillaABI);
|
|
||||||
self.events.emit('abi', embarkJSABI);
|
|
||||||
};
|
|
||||||
this.events.on('contractsDeployed', generateABICode);
|
|
||||||
this.events.on('blockchainDisabled', generateABICode);
|
|
||||||
};
|
|
||||||
|
|
||||||
Engine.prototype.deploymentService = function(options) {
|
|
||||||
var self = this;
|
|
||||||
this.deployManager = new DeployManager({
|
|
||||||
web3: options.web3 || self.web3,
|
|
||||||
trackContracts: options.trackContracts,
|
|
||||||
config: this.config,
|
|
||||||
logger: this.logger,
|
|
||||||
plugins: this.plugins,
|
|
||||||
events: this.events
|
|
||||||
});
|
|
||||||
|
|
||||||
this.events.on('file-event', function(fileType, path) {
|
|
||||||
// TODO: for now need to deploy on asset chanes as well
|
|
||||||
// because the contractsManager config is corrupted after a deploy
|
|
||||||
//if (fileType === 'contract' || fileType === 'config') {
|
|
||||||
self.config.reloadConfig();
|
|
||||||
self.deployManager.deployContracts(function() {});
|
|
||||||
//}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Engine.prototype.fileWatchService = function(options) {
|
|
||||||
this.logger.setStatus("Watching for changes");
|
|
||||||
var watch = new Watch({logger: this.logger, events: this.events});
|
|
||||||
watch.start();
|
|
||||||
};
|
|
||||||
|
|
||||||
Engine.prototype.webServerService = function(options) {
|
|
||||||
var self = this;
|
|
||||||
var webServerConfig = this.config.webServerConfig;
|
|
||||||
if (!webServerConfig.enabled) { return; }
|
|
||||||
|
|
||||||
var host = options.host || webServerConfig.host;
|
|
||||||
var port = options.port || webServerConfig.port;
|
|
||||||
|
|
||||||
this.logger.setStatus("Starting Server");
|
|
||||||
var server = new Server({
|
|
||||||
logger: this.logger,
|
|
||||||
host: host,
|
|
||||||
port: port
|
|
||||||
});
|
|
||||||
|
|
||||||
self.servicesMonitor.addCheck('Webserver', function(cb) {
|
|
||||||
var devServer = 'Webserver (http://' + host + ':' + port + ')';
|
|
||||||
return cb({name: devServer, status: 'green'});
|
|
||||||
});
|
|
||||||
|
|
||||||
server.start(function(){
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Engine.prototype.ipfsService = function(options) {
|
|
||||||
var self = this;
|
|
||||||
self.servicesMonitor.addCheck('IPFS', function(cb) {
|
|
||||||
utils.checkIsAvailable('http://localhost:5001', function(available) {
|
|
||||||
if (available) {
|
|
||||||
//Ideally this method should be in an IPFS API JSONRPC wrapper
|
|
||||||
//The URL should also be flexible to accept non-default IPFS url
|
|
||||||
self.logger.trace("Checking IPFS version...");
|
|
||||||
http.get('http://localhost:5001/api/v0/version', function(res) {
|
|
||||||
var body = '';
|
|
||||||
res.on('data', function(d) {
|
|
||||||
body += d;
|
|
||||||
});
|
|
||||||
res.on('end', function() {
|
|
||||||
try{
|
|
||||||
var parsed = JSON.parse(body);
|
|
||||||
if(parsed.Version){
|
|
||||||
return cb({name: ("IPFS " + parsed.Version), status: 'green'});
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return cb({name: "IPFS ", status: 'green'});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (e){
|
|
||||||
return cb({name: "IPFS ", status: 'red'});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
res.on('error', function(err) {
|
|
||||||
self.logger.trace("Check IPFS version error: " + err);
|
|
||||||
return cb({name: "IPFS ", status: 'red'});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return cb({name: "IPFS ", status: 'red'});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Engine.prototype.web3Service = function(options) {
|
|
||||||
var self = this;
|
|
||||||
this.web3 = options.web3;
|
|
||||||
if (this.web3 === undefined) {
|
|
||||||
this.web3 = new Web3();
|
|
||||||
var web3Endpoint = 'http://' + this.config.blockchainConfig.rpcHost + ':' + this.config.blockchainConfig.rpcPort;
|
|
||||||
this.web3.setProvider(new this.web3.providers.HttpProvider(web3Endpoint));
|
|
||||||
}
|
|
||||||
|
|
||||||
self.servicesMonitor.addCheck('Ethereum', function(cb) {
|
|
||||||
if (self.web3.isConnected()) {
|
|
||||||
return cb({name: (self.web3.version.node.split("/")[0] + " " + self.web3.version.node.split("/")[1].split("-")[0] + " (Ethereum)"), status: 'green'});
|
|
||||||
} else {
|
|
||||||
return cb({name: "No Blockchain node found", status: 'red'});
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
self.servicesMonitor.addCheck('Whisper', function(cb) {
|
self.servicesMonitor.addCheck('Ethereum', function (cb) {
|
||||||
self.web3.version.getWhisper(function(err, res) {
|
if (self.web3.isConnected()) {
|
||||||
if (err) {
|
return cb({
|
||||||
return cb({name: 'Whisper', status: 'red'});
|
name: (self.web3.version.node.split("/")[0] + " " + self.web3.version.node.split("/")[1].split("-")[0] + " (Ethereum)"),
|
||||||
|
status: 'green'
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
return cb({name: 'Whisper', status: 'green'});
|
return cb({name: "No Blockchain node found", status: 'red'});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
self.servicesMonitor.addCheck('Whisper', function (cb) {
|
||||||
|
self.web3.version.getWhisper(function (err, res) {
|
||||||
|
if (err) {
|
||||||
|
return cb({name: 'Whisper', status: 'red'});
|
||||||
|
} else {
|
||||||
|
return cb({name: 'Whisper', status: 'green'});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Engine;
|
module.exports = Engine;
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
var EventEmitter = require('events');
|
//TODO: This is deprecated because Embark extends EventEmitter now
|
||||||
|
let events = require('events');
|
||||||
|
|
||||||
|
class EventEmitter {
|
||||||
|
constructor(options) {
|
||||||
|
this.options = options;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EventEmitter.prototype = Object.create(events.EventEmitter.prototype);
|
||||||
|
|
||||||
module.exports = EventEmitter;
|
module.exports = EventEmitter;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
var fs = require('fs-extra');
|
let fs = require('fs-extra');
|
||||||
var utils = require('../utils/utils.js');
|
let utils = require('../utils/utils.js');
|
||||||
|
|
||||||
function mkdirpSync() {
|
function mkdirpSync() {
|
||||||
return fs.mkdirpSync.apply(fs.mkdirpSync, arguments);
|
return fs.mkdirpSync.apply(fs.mkdirpSync, arguments);
|
||||||
@ -25,7 +25,7 @@ function writeJSONSync() {
|
|||||||
return fs.writeJSONSync.apply(fs.writeJSONSync, arguments);
|
return fs.writeJSONSync.apply(fs.writeJSONSync, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
function existsSync(){
|
function existsSync() {
|
||||||
return fs.existsSync.apply(fs.existsSync, arguments);
|
return fs.existsSync.apply(fs.existsSync, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,39 +1,52 @@
|
|||||||
var colors = require('colors');
|
let colors = require('colors');
|
||||||
|
|
||||||
var Logger = function(options) {
|
class Logger {
|
||||||
this.logLevels = ['error', 'warn', 'info', 'debug', 'trace'];
|
constructor(options) {
|
||||||
this.logLevel = options.logLevel || 'info';
|
this.logLevels = ['error', 'warn', 'info', 'debug', 'trace'];
|
||||||
this.logFunction = options.logFunction || console.log;
|
this.logLevel = options.logLevel || 'info';
|
||||||
this.contractsState = options.contractsState || function() {};
|
this.logFunction = options.logFunction || console.log;
|
||||||
this.setStatus = options.setStatus || console.log;
|
this.contractsState = options.contractsState || function () {
|
||||||
};
|
};
|
||||||
|
this.setStatus = options.setStatus || console.log;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Logger.prototype.error = function(txt) {
|
Logger.prototype.error = function (txt) {
|
||||||
if (!(this.shouldLog('error'))) { return; }
|
if (!(this.shouldLog('error'))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.logFunction(txt.red);
|
this.logFunction(txt.red);
|
||||||
};
|
};
|
||||||
|
|
||||||
Logger.prototype.warn = function(txt) {
|
Logger.prototype.warn = function (txt) {
|
||||||
if (!(this.shouldLog('warn'))) { return; }
|
if (!(this.shouldLog('warn'))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.logFunction(txt.yellow);
|
this.logFunction(txt.yellow);
|
||||||
};
|
};
|
||||||
|
|
||||||
Logger.prototype.info = function(txt) {
|
Logger.prototype.info = function (txt) {
|
||||||
if (!(this.shouldLog('info'))) { return; }
|
if (!(this.shouldLog('info'))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.logFunction(txt.green);
|
this.logFunction(txt.green);
|
||||||
};
|
};
|
||||||
|
|
||||||
Logger.prototype.debug = function(txt) {
|
Logger.prototype.debug = function (txt) {
|
||||||
if (!(this.shouldLog('debug'))) { return; }
|
if (!(this.shouldLog('debug'))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.logFunction(txt);
|
this.logFunction(txt);
|
||||||
};
|
};
|
||||||
|
|
||||||
Logger.prototype.trace = function(txt) {
|
Logger.prototype.trace = function (txt) {
|
||||||
if (!(this.shouldLog('trace'))) { return; }
|
if (!(this.shouldLog('trace'))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.logFunction(txt);
|
this.logFunction(txt);
|
||||||
};
|
};
|
||||||
|
|
||||||
Logger.prototype.shouldLog = function(level) {
|
Logger.prototype.shouldLog = function (level) {
|
||||||
return (this.logLevels.indexOf(level) <= this.logLevels.indexOf(this.logLevel));
|
return (this.logLevels.indexOf(level) <= this.logLevels.indexOf(this.logLevel));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,46 +1,59 @@
|
|||||||
/*jshint esversion: 6, loopfunc: true */
|
/*jshint esversion: 6, loopfunc: true */
|
||||||
var fs = require('./fs.js');
|
let fs = require('./fs.js');
|
||||||
var utils = require('../utils/utils.js');
|
let utils = require('../utils/utils.js');
|
||||||
|
let camelcase = require("underscore.string").camelcase;
|
||||||
|
|
||||||
// TODO: pass other params like blockchainConfig, contract files, etc..
|
class Plugin {
|
||||||
var Plugin = function(options) {
|
constructor(options) {
|
||||||
this.name = options.name;
|
this.config = {};
|
||||||
this.pluginModule = options.pluginModule;
|
for (let opt in options) {
|
||||||
this.pluginPath = options.pluginPath;
|
if (options.hasOwnProperty(opt)) {
|
||||||
this.pluginConfig = options.pluginConfig;
|
this.config[opt] = options[opt];
|
||||||
this.shouldInterceptLogs = options.interceptLogs;
|
}
|
||||||
this.clientWeb3Providers = [];
|
}
|
||||||
this.contractsGenerators = [];
|
let requiredOptions = ['name', 'pluginModule', 'pluginPath', 'config', 'interceptLogs', 'logger'];
|
||||||
this.pipeline = [];
|
|
||||||
this.pipelineFiles = [];
|
|
||||||
this.console = [];
|
|
||||||
this.contractsConfigs = [];
|
|
||||||
this.contractsFiles = [];
|
|
||||||
this.compilers = [];
|
|
||||||
this.serviceChecks = [];
|
|
||||||
this.pluginTypes = [];
|
|
||||||
this.logger = options.logger;
|
|
||||||
this.events = options.events;
|
|
||||||
this.config = options.config;
|
|
||||||
};
|
|
||||||
|
|
||||||
Plugin.prototype.loadPlugin = function() {
|
for (let i = 0; requiredOptions.length > i; i++) {
|
||||||
|
if (!(utils.contains(Object.keys(this.config), requiredOptions[i]))) {
|
||||||
|
throw new Error('Missing required plugin configuration key: ' + requiredOptions[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.clientWeb3Providers = [];
|
||||||
|
this.contractsGenerators = [];
|
||||||
|
this.pipeline = [];
|
||||||
|
this.pipelineFiles = [];
|
||||||
|
this.console = [];
|
||||||
|
this.contractsConfigs = [];
|
||||||
|
this.contractsFiles = [];
|
||||||
|
this.compilers = [];
|
||||||
|
this.serviceChecks = [];
|
||||||
|
this.pluginTypes = [];
|
||||||
|
|
||||||
|
if (!(this instanceof Plugin)) {
|
||||||
|
return new Plugin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Plugin.prototype.runPlugin = Plugin.prototype.run = function () {
|
||||||
if (this.shouldInterceptLogs) {
|
if (this.shouldInterceptLogs) {
|
||||||
this.interceptLogs(this.pluginModule);
|
this.interceptLogs(this.pluginModule);
|
||||||
}
|
}
|
||||||
(this.pluginModule.call(this, this));
|
let fullyQualifiedPath = this.pathToFile(this.config.pluginModule);
|
||||||
|
this.call(this.loadPluginFile(fullyQualifiedPath), this);
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.loadPluginFile = function(filename) {
|
Plugin.prototype.loadPluginFile = function (filename) {
|
||||||
return fs.readFileSync(this.pathToFile(filename)).toString();
|
return fs.readFileSync(this.pathToFile(filename)).toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.pathToFile = function(filename) {
|
Plugin.prototype.pathToFile = function (filename) {
|
||||||
return utils.joinPath(this.pluginPath, filename);
|
return utils.joinPath(this.pluginPath, filename);
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.interceptLogs = function(context) {
|
Plugin.prototype.interceptLogs = function (context) {
|
||||||
var self = this;
|
let self = this;
|
||||||
// TODO: this is a bit nasty, figure out a better way
|
// TODO: this is a bit nasty, figure out a better way
|
||||||
context.console = context.console || console;
|
context.console = context.console || console;
|
||||||
|
|
||||||
@ -49,112 +62,125 @@ Plugin.prototype.interceptLogs = function(context) {
|
|||||||
// //self.logger.error.apply(self.logger, arguments);
|
// //self.logger.error.apply(self.logger, arguments);
|
||||||
// self.logger.error(self.name + " > " + txt);
|
// self.logger.error(self.name + " > " + txt);
|
||||||
//};
|
//};
|
||||||
context.console.log = function(txt) {
|
context.console.log = function (txt) {
|
||||||
self.logger.info(self.name + " > " + txt);
|
self.logger.info(self.name + " > " + txt);
|
||||||
};
|
};
|
||||||
context.console.warn = function(txt) {
|
context.console.warn = function (txt) {
|
||||||
self.logger.warn(self.name + " > " + txt);
|
self.logger.warn(self.name + " > " + txt);
|
||||||
};
|
};
|
||||||
context.console.info = function(txt) {
|
context.console.info = function (txt) {
|
||||||
self.logger.info(self.name + " > " + txt);
|
self.logger.info(self.name + " > " + txt);
|
||||||
};
|
};
|
||||||
context.console.debug = function(txt) {
|
context.console.debug = function (txt) {
|
||||||
// TODO: ue JSON.stringify
|
// TODO: ue JSON.stringify
|
||||||
self.logger.debug(self.name + " > " + txt);
|
self.logger.debug(self.name + " > " + txt);
|
||||||
};
|
};
|
||||||
context.console.trace = function(txt) {
|
context.console.trace = function (txt) {
|
||||||
self.logger.trace(self.name + " > " + txt);
|
self.logger.trace(self.name + " > " + txt);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Plugin.prototype.register = function (classname, cb) {
|
||||||
|
let camelCasedClassname = camelcase(classname);
|
||||||
|
this[camelCasedClassname].push(cb);
|
||||||
|
this.pluginTypes.push({class: classname, call: cb});
|
||||||
|
};
|
||||||
|
|
||||||
|
["ClientWeb3Provider", "ContractsGeneration", "Pipeline", "Deployer",
|
||||||
|
"ConsoleCommand", "ServiceCheck", "ContractConfiguration", "Compiler"].forEach(function (name) {
|
||||||
|
Plugin.prototype["register" + name] = function (cb) {
|
||||||
|
Plugin.prototype.register.call(name, cb);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
// TODO: add deploy provider
|
// TODO: add deploy provider
|
||||||
Plugin.prototype.registerClientWeb3Provider = function(cb) {
|
Plugin.prototype.registerClientWeb3Provider = function (cb) {
|
||||||
this.clientWeb3Providers.push(cb);
|
this.clientWeb3Providers.push(cb);
|
||||||
this.pluginTypes.push('clientWeb3Provider');
|
this.pluginTypes.push('clientWeb3Provider');
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.registerContractsGeneration = function(cb) {
|
Plugin.prototype.registerContractsGeneration = function (cb) {
|
||||||
this.contractsGenerators.push(cb);
|
this.contractsGenerators.push(cb);
|
||||||
this.pluginTypes.push('contractGeneration');
|
this.pluginTypes.push('contractGeneration');
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.registerPipeline = function(matcthingFiles, cb) {
|
Plugin.prototype.registerPipeline = function (matcthingFiles, cb) {
|
||||||
// TODO: generate error for more than one pipeline per plugin
|
// TODO: generate error for more than one pipeline per plugin
|
||||||
this.pipeline.push({matcthingFiles: matcthingFiles, cb: cb});
|
this.pipeline.push({matcthingFiles: matcthingFiles, cb: cb});
|
||||||
this.pluginTypes.push('pipeline');
|
this.pluginTypes.push('pipeline');
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.addFileToPipeline = function(file, intendedPath, options) {
|
Plugin.prototype.addFileToPipeline = function (file, intendedPath, options) {
|
||||||
this.pipelineFiles.push({file: file, intendedPath: intendedPath, options: options});
|
this.pipelineFiles.push({file: file, intendedPath: intendedPath, options: options});
|
||||||
this.pluginTypes.push('pipelineFiles');
|
this.pluginTypes.push('pipelineFiles');
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.addContractFile = function(file) {
|
Plugin.prototype.addContractFile = function (file) {
|
||||||
this.contractsFiles.push(file);
|
this.contractsFiles.push(file);
|
||||||
this.pluginTypes.push('contractFiles');
|
this.pluginTypes.push('contractFiles');
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.registerConsoleCommand = function(cb) {
|
Plugin.prototype.registerConsoleCommand = function (cb) {
|
||||||
this.console.push(cb);
|
this.console.push(cb);
|
||||||
this.pluginTypes.push('console');
|
this.pluginTypes.push('console');
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.registerServiceCheck = function(checkName, checkFn, time) {
|
Plugin.prototype.registerServiceCheck = function (checkName, checkFn, time) {
|
||||||
this.serviceChecks.push({checkName: checkName, checkFn: checkFn, time: time});
|
this.serviceChecks.push({checkName: checkName, checkFn: checkFn, time: time});
|
||||||
this.pluginTypes.push('serviceChecks');
|
this.pluginTypes.push('serviceChecks');
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.has = function(pluginType) {
|
Plugin.prototype.has = function (pluginType) {
|
||||||
return this.pluginTypes.indexOf(pluginType) >= 0;
|
return this.pluginTypes.indexOf(pluginType) >= 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.generateProvider = function(args) {
|
Plugin.prototype.generateProvider = function (args) {
|
||||||
return this.clientWeb3Providers.map(function(cb) {
|
return this.clientWeb3Providers.map(function (cb) {
|
||||||
return cb.call(this, args);
|
return cb.call(this, args);
|
||||||
}).join("\n");
|
}).join("\n");
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.generateContracts = function(args) {
|
Plugin.prototype.generateContracts = function (args) {
|
||||||
return this.contractsGenerators.map(function(cb) {
|
return this.contractsGenerators.map(function (cb) {
|
||||||
return cb.call(this, args);
|
return cb.call(this, args);
|
||||||
}).join("\n");
|
}).join("\n");
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.registerContractConfiguration = function(config) {
|
Plugin.prototype.registerContractConfiguration = function (config) {
|
||||||
this.contractsConfigs.push(config);
|
this.contractsConfigs.push(config);
|
||||||
this.pluginTypes.push('contractsConfig');
|
this.pluginTypes.push('contractsConfig');
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.registerCompiler = function(extension, cb) {
|
Plugin.prototype.registerCompiler = function (extension, cb) {
|
||||||
this.compilers.push({extension: extension, cb: cb});
|
this.compilers.push({extension: extension, cb: cb});
|
||||||
this.pluginTypes.push('compilers');
|
this.pluginTypes.push('compilers');
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.runCommands = function(cmd, options) {
|
Plugin.prototype.runCommands = function (cmd, options) {
|
||||||
return this.console.map(function(cb) {
|
return this.console.map(function (cb) {
|
||||||
return cb.call(this, cmd, options);
|
return cb.call(this, cmd, options);
|
||||||
}).join("\n");
|
}).join("\n");
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.runFilePipeline = function() {
|
Plugin.prototype.runFilePipeline = function () {
|
||||||
var self = this;
|
let self = this;
|
||||||
|
|
||||||
return this.pipelineFiles.map(function(file) {
|
return this.pipelineFiles.map(function (file) {
|
||||||
var obj = {};
|
let obj = {};
|
||||||
obj.filename = file.file.replace('./','');
|
obj.filename = file.file.replace('./', '');
|
||||||
obj.content = self.loadPluginFile(file.file).toString();
|
obj.content = self.loadPluginFile(file.file).toString();
|
||||||
obj.intendedPath = file.intendedPath;
|
obj.intendedPath = file.intendedPath;
|
||||||
obj.options = file.options;
|
obj.options = file.options;
|
||||||
obj.path = self.pathToFile(obj.filename);
|
obj.path = self.pathToFile(obj.filename);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.runPipeline = function(args) {
|
Plugin.prototype.runPipeline = function (args) {
|
||||||
// TODO: should iterate the pipelines
|
// TODO: should iterate the pipelines
|
||||||
var pipeline = this.pipeline[0];
|
let pipeline = this.pipeline[0];
|
||||||
var shouldRunPipeline = utils.fileMatchesPattern(pipeline.matcthingFiles, args.targetFile);
|
let shouldRunPipeline = utils.fileMatchesPattern(pipeline.matcthingFiles, args.targetFile);
|
||||||
if (shouldRunPipeline) {
|
if (shouldRunPipeline) {
|
||||||
return pipeline.cb.call(this, args);
|
return pipeline.cb.call(this, args);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,45 +1,53 @@
|
|||||||
var Plugin = require('./plugin.js');
|
const _ = require('underscore');
|
||||||
var utils = require('../utils/utils.js');
|
const EventEmitter = require('events').EventEmitter;
|
||||||
|
|
||||||
var Plugins = function(options) {
|
const getPluginsFor = function (pluginType, plugins) {
|
||||||
this.pluginList = options.plugins || [];
|
return _.filter(plugins, pluginType);
|
||||||
this.interceptLogs = options.interceptLogs;
|
|
||||||
this.plugins = [];
|
|
||||||
// TODO: need backup 'NullLogger'
|
|
||||||
this.logger = options.logger;
|
|
||||||
this.events = options.events;
|
|
||||||
this.config = options.config;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugins.prototype.loadPlugins = function() {
|
class Plugins extends EventEmitter {
|
||||||
var pluginConfig;
|
constructor(options) {
|
||||||
for (var pluginName in this.pluginList) {
|
super();
|
||||||
pluginConfig = this.pluginList[pluginName];
|
//TODO: put an observer on this.plugins and call loadPlugin when a new item is added
|
||||||
this.loadPlugin(pluginName, pluginConfig);
|
this.config = {};
|
||||||
|
|
||||||
|
const loadPlugins = this.load;
|
||||||
|
for (let opt in options) {
|
||||||
|
if (options.hasOwnProperty(opt)) {
|
||||||
|
this.config[opt] = options[opt];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let requiredOptions = ['interceptLogs', 'plugins', 'logger'];
|
||||||
|
for (let i = 0; requiredOptions.length > i; i++) {
|
||||||
|
if (!(_.contains(Object.keys(this.config), requiredOptions[i]))) {
|
||||||
|
console.log('Warning: missing required plugin configuration key: ' + requiredOptions[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.on('load', () => {
|
||||||
|
this.load();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.on('get', (pluginType, cb) => {
|
||||||
|
let pluginTypes = getPluginsFor(pluginType, this.config.plugins);
|
||||||
|
return cb(pluginTypes);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
Plugins.prototype.listPlugins = function() {
|
load() {
|
||||||
var list = [];
|
let pluginConfig;
|
||||||
for (var className in this.pluginList) {
|
for (let i = 0; this.config.plugins.length > i; i++) {
|
||||||
list.push(className);
|
pluginConfig = this.config.plugins[i].config;
|
||||||
|
let Plugin = require('./plugin');
|
||||||
|
let plugin = new Plugin(pluginConfig);
|
||||||
|
plugin.run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return list;
|
|
||||||
};
|
|
||||||
|
|
||||||
Plugins.prototype.loadPlugin = function(pluginName, pluginConfig) {
|
listPlugins() {
|
||||||
var pluginPath = utils.joinPath(process.env.PWD, 'node_modules', pluginName);
|
return this.config.plugins.join(', ');
|
||||||
var plugin = require(pluginPath);
|
}
|
||||||
|
|
||||||
var pluginWrapper = new Plugin({name: pluginName, pluginModule: plugin, pluginConfig: pluginConfig, logger: this.logger, pluginPath: pluginPath, interceptLogs: this.interceptLogs, events: this.events, config: this.config});
|
}
|
||||||
pluginWrapper.loadPlugin();
|
|
||||||
this.plugins.push(pluginWrapper);
|
|
||||||
};
|
|
||||||
|
|
||||||
Plugins.prototype.getPluginsFor = function(pluginType) {
|
module.exports = Plugins;
|
||||||
return this.plugins.filter(function(plugin) {
|
|
||||||
return plugin.has(pluginType);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = Plugins;
|
|
@ -1,5 +1,5 @@
|
|||||||
var Web3 = require('web3');
|
let Web3 = require('web3');
|
||||||
var web3;
|
let web3;
|
||||||
|
|
||||||
// ======================
|
// ======================
|
||||||
// the eval is used for evaluating some of the contact calls for different purposes
|
// the eval is used for evaluating some of the contact calls for different purposes
|
||||||
@ -8,7 +8,7 @@ var web3;
|
|||||||
// ======================
|
// ======================
|
||||||
function doEval(code, _web3) {
|
function doEval(code, _web3) {
|
||||||
if (_web3) {
|
if (_web3) {
|
||||||
web3 = _web3;
|
let web3 = _web3;
|
||||||
}
|
}
|
||||||
return eval(code); // jshint ignore:line
|
return eval(code); // jshint ignore:line
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,28 @@
|
|||||||
var async = require('../utils/async_extend.js');
|
let async = require('../utils/async_extend.js');
|
||||||
|
|
||||||
// TODO: need to separate colors from states
|
// TODO: need to separate colors from states
|
||||||
// i.e use status: /on|off|warn/ not /red|green/
|
// i.e use status: /on|off|warn/ not /red|green/
|
||||||
// it's up to the logger or console to determine the color
|
// it's up to the logger or console to determine the color
|
||||||
var ServicesMonitor = function(options) {
|
class ServicesMonitor {
|
||||||
this.events = options.events;
|
constructor(options) {
|
||||||
this.logger = options.logger;
|
this.events = options.events;
|
||||||
this.checkList = {};
|
this.logger = options.logger;
|
||||||
this.checkTimers = {};
|
this.checkList = {};
|
||||||
this.checkState = {};
|
this.checkTimers = {};
|
||||||
this.working = false;
|
this.checkState = {};
|
||||||
};
|
this.working = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ServicesMonitor.prototype.initCheck = function(checkName) {
|
ServicesMonitor.prototype.initCheck = function (checkName) {
|
||||||
var self = this;
|
let self = this;
|
||||||
var check = this.checkList[checkName];
|
let check = this.checkList[checkName];
|
||||||
|
|
||||||
if (!check) { return false; }
|
if (!check) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
self.events.on('check:' + checkName, function(obj) {
|
self.events.on('check:' + checkName, function (obj) {
|
||||||
// TODO: see todo above
|
// TODO: see todo above
|
||||||
if (check && check.status === 'red' && obj.status === 'green') {
|
if (check && check.status === 'red' && obj.status === 'green') {
|
||||||
self.events.emit('check:backOnline:' + checkName);
|
self.events.emit('check:backOnline:' + checkName);
|
||||||
@ -32,20 +36,20 @@ ServicesMonitor.prototype.initCheck = function(checkName) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (check.interval !== 0) {
|
if (check.interval !== 0) {
|
||||||
self.checkTimers[checkName] = setInterval(function() {
|
self.checkTimers[checkName] = setInterval(function () {
|
||||||
check.fn.call(check.fn, function(obj) {
|
check.fn.call(check.fn, function (obj) {
|
||||||
self.events.emit('check:' + checkName, obj);
|
self.events.emit('check:' + checkName, obj);
|
||||||
});
|
});
|
||||||
}, check.interval);
|
}, check.interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
check.fn.call(check.fn, function(obj) {
|
check.fn.call(check.fn, function (obj) {
|
||||||
self.events.emit('check:' + checkName, obj);
|
self.events.emit('check:' + checkName, obj);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
ServicesMonitor.prototype.addCheck = function(checkName, checkFn, time) {
|
ServicesMonitor.prototype.addCheck = function (checkName, checkFn, time) {
|
||||||
var self = this;
|
let self = this;
|
||||||
this.logger.trace('add check: ' + checkName);
|
this.logger.trace('add check: ' + checkName);
|
||||||
this.checkList[checkName] = {fn: checkFn, interval: time || 5000};
|
this.checkList[checkName] = {fn: checkFn, interval: time || 5000};
|
||||||
|
|
||||||
@ -54,22 +58,22 @@ ServicesMonitor.prototype.addCheck = function(checkName, checkFn, time) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ServicesMonitor.prototype.stopCheck = function(name) {
|
ServicesMonitor.prototype.stopCheck = function (name) {
|
||||||
clearInterval(this.checkTimers[name]);
|
clearInterval(this.checkTimers[name]);
|
||||||
delete this.checkTimers[name];
|
delete this.checkTimers[name];
|
||||||
delete this.checkList[name];
|
delete this.checkList[name];
|
||||||
delete this.checkState[name];
|
delete this.checkState[name];
|
||||||
};
|
};
|
||||||
|
|
||||||
ServicesMonitor.prototype.startMonitor = function() {
|
ServicesMonitor.prototype.startMonitor = function () {
|
||||||
var self = this;
|
let self = this;
|
||||||
this.working = true;
|
this.working = true;
|
||||||
this.logger.trace('startMonitor');
|
this.logger.trace('startMonitor');
|
||||||
|
|
||||||
async.eachObject(this.checkList, function(checkName, check, callback) {
|
async.eachObject(this.checkList, function (checkName, check, callback) {
|
||||||
self.initCheck(checkName);
|
self.initCheck(checkName);
|
||||||
callback();
|
callback();
|
||||||
}, function(err) {
|
}, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
self.logger.error("error running service check");
|
self.logger.error("error running service check");
|
||||||
self.logger.error(err.message);
|
self.logger.error(err.message);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
var getSimulator = function() {
|
let getSimulator = function () {
|
||||||
try {
|
try {
|
||||||
return require('ethereumjs-testrpc');
|
return require('ethereumjs-testrpc');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -17,91 +17,25 @@ var getSimulator = function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var Test;
|
|
||||||
Test = (function (options) {
|
|
||||||
var async = require('async');
|
|
||||||
var opts = options === undefined ? {} : options;
|
|
||||||
opts.logLevel = opts.hasOwnProperty('logLevel') ? opts.logLevel : 'debug';
|
|
||||||
opts.simulatorOptions = opts.hasOwnProperty('simulatorOptions') ? opts.simulatorOptions : {};
|
|
||||||
var sim = getSimulator();
|
|
||||||
|
|
||||||
function newWebThree() {
|
class Test {
|
||||||
|
constructor(options) {
|
||||||
|
this.opts = options === undefined ? {} : options;
|
||||||
|
this.opts.logLevel = this.opts.hasOwnProperty('logLevel') ? this.opts.logLevel : 'debug';
|
||||||
|
this.opts.simulatorOptions = this.opts.hasOwnProperty('simulatorOptions') ? this.opts.simulatorOptions : {};
|
||||||
|
this.sim = getSimulator();
|
||||||
|
}
|
||||||
|
|
||||||
|
newWebThree() {
|
||||||
try {
|
try {
|
||||||
var Web3 = require('web3');
|
let Web3 = require('web3');
|
||||||
var web3 = new Web3();
|
let web3 = new Web3();
|
||||||
web3.setProvider(sim.provider(opts.simulatorOptions));
|
web3.setProvider(this.sim.provider(this.opts.simulatorOptions));
|
||||||
return web3;
|
return web3;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(e);
|
throw new Error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
function deployAll(contractsConfig, cb) {
|
|
||||||
var RunCode = require('./runCode.js');
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
function newEngine () {
|
|
||||||
var Engine = require('./engine.js');
|
|
||||||
return new Engine({
|
|
||||||
env: opts.env || 'test',
|
|
||||||
// TODO: confi will need to detect if this is a obj
|
|
||||||
embarkConfig: opts.embarkConfig || 'embark.json',
|
|
||||||
interceptLogs: false
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
self.web3 = newWebThree();
|
|
||||||
self.engine = newEngine();
|
|
||||||
self.engine.init();
|
|
||||||
|
|
||||||
async.waterfall([
|
|
||||||
function getConfig(callback) {
|
|
||||||
self.engine.config.contractsConfig = {contracts: contractsConfig};
|
|
||||||
callback();
|
|
||||||
},
|
|
||||||
function startServices(callback) {
|
|
||||||
//{abiType: 'contracts', embarkJS: false}
|
|
||||||
self.engine.startService("abi");
|
|
||||||
self.engine.startService("deployment", {
|
|
||||||
web3: self.web3,
|
|
||||||
trackContracts: false
|
|
||||||
});
|
|
||||||
callback();
|
|
||||||
},
|
|
||||||
function deploy(callback) {
|
|
||||||
self.engine.events.on('abi-contracts-vanila', function (vanillaABI) {
|
|
||||||
callback(null, vanillaABI);
|
|
||||||
});
|
|
||||||
self.engine.deployManager.deployContracts(function (err, result) {
|
|
||||||
if (err) {
|
|
||||||
console.log(err);
|
|
||||||
callback(err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
], function (err, result) {
|
|
||||||
if (err) {
|
|
||||||
console.log("got error");
|
|
||||||
process.exit();
|
|
||||||
}
|
|
||||||
// this should be part of the waterfall and not just something done at the
|
|
||||||
// end
|
|
||||||
self.web3.eth.getAccounts(function (err, accounts) {
|
|
||||||
if (err) {
|
|
||||||
throw new Error(err);
|
|
||||||
}
|
|
||||||
self.web3.eth.defaultAccount = accounts[0];
|
|
||||||
RunCode.doEval(result, self.web3); // jshint ignore:line
|
|
||||||
cb();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return {
|
|
||||||
deployAll: deployAll,
|
|
||||||
sim: sim
|
|
||||||
};
|
|
||||||
}());
|
|
||||||
|
|
||||||
module.exports = Test;
|
module.exports = Test;
|
||||||
|
@ -1,52 +1,65 @@
|
|||||||
var colors = require('colors');
|
let colors = require('colors');
|
||||||
|
|
||||||
// TODO: just logFunction changes, probably doesn't need a whole new module just
|
// TODO: just logFunction changes, probably doesn't need a whole new module just
|
||||||
// for this
|
// for this
|
||||||
var TestLogger = function(options) {
|
class TestLogger {
|
||||||
this.logLevels = ['error', 'warn', 'info', 'debug', 'trace'];
|
constructor(options) {
|
||||||
this.logs = [];
|
this.logLevels = ['error', 'warn', 'info', 'debug', 'trace'];
|
||||||
this.logLevel = options.logLevel || 'info';
|
this.logs = [];
|
||||||
};
|
this.logLevel = options.logLevel || 'info';
|
||||||
|
}
|
||||||
|
|
||||||
TestLogger.prototype.logFunction = function() {
|
logFunction() {
|
||||||
this.logs.push(arguments);
|
this.logs.push(arguments);
|
||||||
};
|
}
|
||||||
|
|
||||||
TestLogger.prototype.contractsState = function() {
|
contractsState() {
|
||||||
this.logs.push(arguments);
|
this.logs.push(arguments);
|
||||||
};
|
}
|
||||||
|
|
||||||
TestLogger.prototype.availableServices = function() {
|
availableServices() {
|
||||||
this.logs.push(arguments);
|
this.logs.push(arguments);
|
||||||
};
|
}
|
||||||
|
|
||||||
TestLogger.prototype.error = function(txt) {
|
error(txt) {
|
||||||
if (!(this.shouldLog('error'))) { return; }
|
if (!(this.shouldLog('error'))) {
|
||||||
this.logFunction(txt.red);
|
return;
|
||||||
};
|
}
|
||||||
|
this.logFunction(txt.red);
|
||||||
|
}
|
||||||
|
|
||||||
TestLogger.prototype.warn = function(txt) {
|
warn(txt) {
|
||||||
if (!(this.shouldLog('warn'))) { return; }
|
if (!(this.shouldLog('warn'))) {
|
||||||
this.logFunction(txt.yellow);
|
return;
|
||||||
};
|
}
|
||||||
|
this.logFunction(txt.yellow);
|
||||||
|
}
|
||||||
|
|
||||||
TestLogger.prototype.info = function(txt) {
|
info(txt) {
|
||||||
if (!(this.shouldLog('info'))) { return; }
|
if (!(this.shouldLog('info'))) {
|
||||||
this.logFunction(txt.green);
|
return;
|
||||||
};
|
}
|
||||||
|
this.logFunction(txt.green);
|
||||||
|
}
|
||||||
|
|
||||||
TestLogger.prototype.debug = function(txt) {
|
debug(txt) {
|
||||||
if (!(this.shouldLog('debug'))) { return; }
|
if (!(this.shouldLog('debug'))) {
|
||||||
this.logFunction(txt);
|
return;
|
||||||
};
|
}
|
||||||
|
this.logFunction(txt);
|
||||||
|
}
|
||||||
|
|
||||||
TestLogger.prototype.trace = function(txt) {
|
trace(txt) {
|
||||||
if (!(this.shouldLog('trace'))) { return; }
|
if (!(this.shouldLog('trace'))) {
|
||||||
this.logFunction(txt);
|
return;
|
||||||
};
|
}
|
||||||
|
this.logFunction(txt);
|
||||||
|
}
|
||||||
|
|
||||||
TestLogger.prototype.shouldLog = function(level) {
|
shouldLog(level) {
|
||||||
return (this.logLevels.indexOf(level) <= this.logLevels.indexOf(this.logLevel));
|
return (this.logLevels.indexOf(level) <= this.logLevels.indexOf(this.logLevel));
|
||||||
};
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = TestLogger;
|
module.exports = TestLogger;
|
||||||
|
@ -1,28 +1,29 @@
|
|||||||
|
class CommandHistory {
|
||||||
var CommandHistory = function() {
|
constructor() {
|
||||||
this.history = [];
|
this.history = [];
|
||||||
this.pointer = -1;
|
this.pointer = -1;
|
||||||
};
|
|
||||||
|
|
||||||
CommandHistory.prototype.addCommand = function(cmd) {
|
|
||||||
this.history.push(cmd);
|
|
||||||
this.pointer = this.history.length;
|
|
||||||
};
|
|
||||||
|
|
||||||
CommandHistory.prototype.getPreviousCommand = function(cmd) {
|
|
||||||
if (this.pointer >= 0) {
|
|
||||||
this.pointer--;
|
|
||||||
}
|
}
|
||||||
return this.history[this.pointer];
|
|
||||||
};
|
|
||||||
|
|
||||||
CommandHistory.prototype.getNextCommand = function(cmd) {
|
addCommand(cmd) {
|
||||||
if (this.pointer >= this.history.length) {
|
this.history.push(cmd);
|
||||||
this.pointer = this.history.length - 1;
|
this.pointer = this.history.length;
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
this.pointer++;
|
|
||||||
return this.history[this.pointer];
|
getPreviousCommand(cmd) {
|
||||||
};
|
if (this.pointer >= 0) {
|
||||||
|
this.pointer--;
|
||||||
|
}
|
||||||
|
return this.history[this.pointer];
|
||||||
|
}
|
||||||
|
|
||||||
|
getNextCommand(cmd) {
|
||||||
|
if (this.pointer >= this.history.length) {
|
||||||
|
this.pointer = this.history.length - 1;
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
this.pointer++;
|
||||||
|
return this.history[this.pointer];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = CommandHistory;
|
module.exports = CommandHistory;
|
||||||
|
@ -1,60 +1,65 @@
|
|||||||
var utils = require('../utils/utils.js');
|
let utils = require('../utils/utils.js');
|
||||||
var RunCode = require('../core/runCode.js');
|
let RunCode = require('../core/runCode.js');
|
||||||
|
|
||||||
var Console = function(options) {
|
class Console {
|
||||||
this.plugins = options.plugins;
|
constructor(options) {
|
||||||
this.version = options.version;
|
this.plugins = options.plugins;
|
||||||
};
|
this.version = options.version;
|
||||||
|
|
||||||
Console.prototype.runCode = function(code) {
|
|
||||||
RunCode.doEval(code); // jshint ignore:line
|
|
||||||
};
|
|
||||||
|
|
||||||
Console.prototype.processEmbarkCmd = function(cmd) {
|
|
||||||
if (cmd === 'help') {
|
|
||||||
var helpText = [
|
|
||||||
'Welcome to Embark ' + this.version,
|
|
||||||
'',
|
|
||||||
'possible commands are:',
|
|
||||||
// TODO: only if the blockchain is actually active!
|
|
||||||
// will need to pass te current embark state here
|
|
||||||
'web3 - instantiated web3.js object configured to the current environment',
|
|
||||||
'quit - to immediatly exit',
|
|
||||||
'',
|
|
||||||
'The web3 object and the interfaces for the deployed contracts and their methods are also available'
|
|
||||||
];
|
|
||||||
return helpText.join('\n');
|
|
||||||
} else if (cmd === 'quit') {
|
|
||||||
utils.exit();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
Console.prototype.executeCmd = function(cmd, callback) {
|
|
||||||
var plugin, pluginOutput;
|
|
||||||
var plugins = this.plugins.getPluginsFor('console');
|
|
||||||
for (var i = 0; i < plugins.length; i++) {
|
|
||||||
plugin = plugins[i];
|
|
||||||
pluginOutput = plugin.runCommands(cmd, {});
|
|
||||||
if (pluginOutput !== false && pluginOutput !== 'false') return callback(pluginOutput);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var output = this.processEmbarkCmd(cmd);
|
runCode(code) {
|
||||||
if (output) {
|
RunCode.doEval(code); // jshint ignore:line
|
||||||
return callback(output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
processEmbarkCmd (cmd) {
|
||||||
var result = RunCode.doEval(cmd);
|
if (cmd === 'help') {
|
||||||
return callback(result);
|
let helpText = [
|
||||||
|
'Welcome to Embark ' + this.version,
|
||||||
|
'',
|
||||||
|
'possible commands are:',
|
||||||
|
// TODO: only if the blockchain is actually active!
|
||||||
|
// will need to pass te current embark state here
|
||||||
|
'web3 - instantiated web3.js object configured to the current environment',
|
||||||
|
'quit - to immediatly exit',
|
||||||
|
'',
|
||||||
|
'The web3 object and the interfaces for the deployed contracts and their methods are also available'
|
||||||
|
];
|
||||||
|
return helpText.join('\n');
|
||||||
|
} else if (cmd === 'quit') {
|
||||||
|
utils.exit();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
catch(e) {
|
|
||||||
if (e.message.indexOf('not defined') > 0) {
|
executeCmd(cmd, callback) {
|
||||||
return callback(("error: " + e.message).red + ("\nType " + "help".bold + " to see the list of available commands").cyan);
|
let plugin, pluginOutput;
|
||||||
} else {
|
let plugins = [];
|
||||||
return callback(e.message);
|
this.plugins.emit('get', 'console', (list) => {
|
||||||
|
plugins = list;
|
||||||
|
});
|
||||||
|
for (let i = 0; i < plugins.length; i++) {
|
||||||
|
plugin = plugins[i];
|
||||||
|
pluginOutput = plugin.runCommands(cmd, {});
|
||||||
|
if (pluginOutput !== false && pluginOutput !== 'false') return callback(pluginOutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
let output = this.processEmbarkCmd(cmd);
|
||||||
|
if (output) {
|
||||||
|
return callback(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
let result = RunCode.doEval(cmd);
|
||||||
|
return callback(result);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
if (e.message.indexOf('not defined') > 0) {
|
||||||
|
return callback(("error: " + e.message).red + ("\nType " + "help".bold + " to see the list of available commands").cyan);
|
||||||
|
} else {
|
||||||
|
return callback(e.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = Console;
|
module.exports = Console;
|
||||||
|
@ -1,42 +1,45 @@
|
|||||||
var async = require('async');
|
let async = require('async');
|
||||||
|
|
||||||
var Monitor = require('./monitor.js');
|
let Monitor = require('./monitor.js');
|
||||||
var Console = require('./console.js');
|
let Console = require('./console.js');
|
||||||
|
|
||||||
var Dashboard = function(options) {
|
class Dashboard {
|
||||||
this.logger = options.logger;
|
constructor(options) {
|
||||||
this.plugins = options.plugins;
|
this.logger = options.logger;
|
||||||
this.version = options.version;
|
this.plugins = options.plugins;
|
||||||
this.env = options.env;
|
this.version = options.version;
|
||||||
};
|
this.env = options.env;
|
||||||
|
}
|
||||||
|
|
||||||
Dashboard.prototype.start = function(done) {
|
start(done) {
|
||||||
var console, monitor;
|
let console, monitor;
|
||||||
var self = this;
|
let self = this;
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function startConsole(callback) {
|
function startConsole(callback) {
|
||||||
console = new Console({plugins: self.plugins, version: self.version});
|
console = new Console({plugins: self.plugins, version: self.version});
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
function startMonitor(callback) {
|
function startMonitor(callback) {
|
||||||
monitor = new Monitor({env: self.env, console: console});
|
monitor = new Monitor({env: self.env, console: console});
|
||||||
self.logger.logFunction = monitor.logEntry;
|
self.logger.logFunction = monitor.logEntry;
|
||||||
self.logger.contractsState = monitor.setContracts;
|
self.logger.contractsState = monitor.setContracts;
|
||||||
self.logger.setStatus = monitor.setStatus.bind(monitor);
|
self.logger.setStatus = monitor.setStatus.bind(monitor);
|
||||||
|
|
||||||
self.logger.info('========================'.bold.green);
|
self.logger.info('========================'.bold.green);
|
||||||
self.logger.info(('Welcome to Embark ' + self.version).yellow.bold);
|
self.logger.info(('Welcome to Embark ' + self.version).yellow.bold);
|
||||||
self.logger.info('========================'.bold.green);
|
self.logger.info('========================'.bold.green);
|
||||||
|
|
||||||
// TODO: do this after monitor is rendered
|
// TODO: do this after monitor is rendered
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
], function() {
|
], function () {
|
||||||
self.console = console;
|
self.console = console;
|
||||||
self.monitor = monitor;
|
self.monitor = monitor;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Dashboard;
|
module.exports = Dashboard;
|
||||||
|
@ -1,355 +1,357 @@
|
|||||||
/*jshint esversion: 6 */
|
/*jshint esversion: 6 */
|
||||||
|
|
||||||
var blessed = require("blessed");
|
let blessed = require("blessed");
|
||||||
var CommandHistory = require('./command_history.js');
|
let CommandHistory = require('./command_history.js');
|
||||||
var version = require('../../package.json').version;
|
let version = require('../../package.json').version;
|
||||||
|
|
||||||
function Dashboard(options) {
|
class Dashboard {
|
||||||
var title = (options && options.title) || "Embark " + version;
|
constructor(options) {
|
||||||
this.env = options.env;
|
let title = (options && options.title) || "Embark " + version;
|
||||||
this.console = options.console;
|
this.env = options.env;
|
||||||
this.history = new CommandHistory();
|
this.console = options.console;
|
||||||
|
this.history = new CommandHistory();
|
||||||
|
|
||||||
this.color = (options && options.color) || "green";
|
this.color = (options && options.color) || "green";
|
||||||
this.minimal = (options && options.minimal) || false;
|
this.minimal = (options && options.minimal) || false;
|
||||||
|
|
||||||
this.screen = blessed.screen({
|
this.screen = blessed.screen({
|
||||||
smartCSR: true,
|
smartCSR: true,
|
||||||
title: title,
|
title: title,
|
||||||
dockBorders: false,
|
dockBorders: false,
|
||||||
fullUnicode: true,
|
fullUnicode: true,
|
||||||
autoPadding: true
|
autoPadding: true
|
||||||
});
|
});
|
||||||
|
|
||||||
this.layoutLog();
|
this.layoutLog();
|
||||||
this.layoutStatus();
|
this.layoutStatus();
|
||||||
this.layoutModules();
|
this.layoutModules();
|
||||||
this.layoutCmd();
|
this.layoutCmd();
|
||||||
|
|
||||||
this.screen.key(["C-c"], function() {
|
this.screen.key(["C-c"], function () {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.logEntry = this.logEntry.bind(this);
|
this.logEntry = this.logEntry.bind(this);
|
||||||
this.setContracts = this.setContracts.bind(this);
|
this.setContracts = this.setContracts.bind(this);
|
||||||
this.availableServices = this.availableServices.bind(this);
|
this.availableServices = this.availableServices.bind(this);
|
||||||
|
|
||||||
this.status.setContent(this.env.green);
|
this.status.setContent(this.env.green);
|
||||||
|
|
||||||
this.screen.render();
|
this.screen.render();
|
||||||
this.input.focus();
|
this.input.focus();
|
||||||
}
|
|
||||||
|
|
||||||
Dashboard.prototype.availableServices = function(_services) {
|
|
||||||
var services = [];
|
|
||||||
var checkName;
|
|
||||||
for (checkName in _services) {
|
|
||||||
services.push(_services[checkName]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.progress.setContent(services.join('\n'));
|
availableServices(_services) {
|
||||||
this.screen.render();
|
let services = [];
|
||||||
};
|
let checkName;
|
||||||
|
for (checkName in _services) {
|
||||||
Dashboard.prototype.setStatus = function(status) {
|
services.push(_services[checkName]);
|
||||||
this.operations.setContent(status);
|
|
||||||
this.screen.render();
|
|
||||||
};
|
|
||||||
|
|
||||||
Dashboard.prototype.setContracts = function(contracts) {
|
|
||||||
var data = [];
|
|
||||||
|
|
||||||
data.push(["Contract Name", "Address", "Status"]);
|
|
||||||
|
|
||||||
contracts.forEach(function(row) {
|
|
||||||
data.push(row);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.moduleTable.setData(data);
|
|
||||||
this.screen.render();
|
|
||||||
};
|
|
||||||
|
|
||||||
Dashboard.prototype.logEntry = function(text) {
|
|
||||||
this.logText.log(text);
|
|
||||||
this.screen.render();
|
|
||||||
};
|
|
||||||
|
|
||||||
Dashboard.prototype.layoutLog = function() {
|
|
||||||
this.log = blessed.box({
|
|
||||||
label: "Logs",
|
|
||||||
padding: 1,
|
|
||||||
width: "100%",
|
|
||||||
height: "55%",
|
|
||||||
left: "0%",
|
|
||||||
top: "42%",
|
|
||||||
border: {
|
|
||||||
type: "line"
|
|
||||||
},
|
|
||||||
style: {
|
|
||||||
fg: -1,
|
|
||||||
border: {
|
|
||||||
fg: this.color
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
this.logText = blessed.log({
|
this.progress.setContent(services.join('\n'));
|
||||||
parent: this.log,
|
this.screen.render();
|
||||||
tags: true,
|
}
|
||||||
width: "100%-5",
|
|
||||||
//height: '90%',
|
|
||||||
scrollable: true,
|
|
||||||
input: false,
|
|
||||||
alwaysScroll: true,
|
|
||||||
scrollbar: {
|
|
||||||
ch: " ",
|
|
||||||
inverse: true
|
|
||||||
},
|
|
||||||
keys: false,
|
|
||||||
vi: false,
|
|
||||||
mouse: true
|
|
||||||
});
|
|
||||||
|
|
||||||
this.screen.append(this.log);
|
setStatus(status) {
|
||||||
};
|
this.operations.setContent(status);
|
||||||
|
this.screen.render();
|
||||||
|
}
|
||||||
|
|
||||||
Dashboard.prototype.layoutModules = function() {
|
setContracts(contracts) {
|
||||||
this.modules = blessed.box({
|
let data = [];
|
||||||
label: "Contracts",
|
|
||||||
tags: true,
|
data.push(["Contract Name", "Address", "Status"]);
|
||||||
padding: 1,
|
|
||||||
width: "75%",
|
contracts.forEach(function (row) {
|
||||||
height: "42%",
|
data.push(row);
|
||||||
left: "0%",
|
});
|
||||||
top: "0",
|
|
||||||
border: {
|
this.moduleTable.setData(data);
|
||||||
type: "line"
|
this.screen.render();
|
||||||
},
|
}
|
||||||
style: {
|
|
||||||
fg: -1,
|
logEntry(text) {
|
||||||
|
this.logText.log(text);
|
||||||
|
this.screen.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
layoutLog() {
|
||||||
|
this.log = blessed.box({
|
||||||
|
label: "Logs",
|
||||||
|
padding: 1,
|
||||||
|
width: "100%",
|
||||||
|
height: "55%",
|
||||||
|
left: "0%",
|
||||||
|
top: "42%",
|
||||||
border: {
|
border: {
|
||||||
fg: this.color
|
type: "line"
|
||||||
|
},
|
||||||
|
style: {
|
||||||
|
fg: -1,
|
||||||
|
border: {
|
||||||
|
fg: this.color
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
this.moduleTable = blessed.table({
|
this.logText = blessed.log({
|
||||||
parent: this.modules,
|
parent: this.log,
|
||||||
height: "100%",
|
tags: true,
|
||||||
width: "100%-5",
|
width: "100%-5",
|
||||||
align: "left",
|
//height: '90%',
|
||||||
pad: 1,
|
scrollable: true,
|
||||||
margin: "auto",
|
input: false,
|
||||||
shrink: true,
|
alwaysScroll: true,
|
||||||
scrollable: true,
|
scrollbar: {
|
||||||
alwaysScroll: true,
|
ch: " ",
|
||||||
scrollbar: {
|
inverse: true
|
||||||
ch: " ",
|
},
|
||||||
inverse: true
|
keys: false,
|
||||||
},
|
vi: false,
|
||||||
keys: false,
|
mouse: true
|
||||||
vi: false,
|
});
|
||||||
mouse: true,
|
|
||||||
data: [["ContractName", "Address", "Status"]]
|
|
||||||
});
|
|
||||||
|
|
||||||
this.screen.append(this.modules);
|
this.screen.append(this.log);
|
||||||
};
|
}
|
||||||
|
|
||||||
Dashboard.prototype.layoutAssets = function() {
|
layoutModules() {
|
||||||
this.assets = blessed.box({
|
this.modules = blessed.box({
|
||||||
label: "Asset Pipeline",
|
label: "Contracts",
|
||||||
tags: true,
|
tags: true,
|
||||||
padding: 1,
|
padding: 1,
|
||||||
width: "50%",
|
width: "75%",
|
||||||
height: "55%",
|
height: "42%",
|
||||||
left: "50%",
|
left: "0%",
|
||||||
top: "42%",
|
top: "0",
|
||||||
border: {
|
|
||||||
type: "line"
|
|
||||||
},
|
|
||||||
style: {
|
|
||||||
fg: -1,
|
|
||||||
border: {
|
border: {
|
||||||
fg: this.color
|
type: "line"
|
||||||
|
},
|
||||||
|
style: {
|
||||||
|
fg: -1,
|
||||||
|
border: {
|
||||||
|
fg: this.color
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
this.assetTable = blessed.table({
|
this.moduleTable = blessed.table({
|
||||||
parent: this.assets,
|
parent: this.modules,
|
||||||
height: "100%",
|
height: "100%",
|
||||||
width: "100%-5",
|
width: "100%-5",
|
||||||
align: "left",
|
align: "left",
|
||||||
pad: 1,
|
pad: 1,
|
||||||
scrollable: true,
|
margin: "auto",
|
||||||
alwaysScroll: true,
|
shrink: true,
|
||||||
scrollbar: {
|
scrollable: true,
|
||||||
ch: " ",
|
alwaysScroll: true,
|
||||||
inverse: true
|
scrollbar: {
|
||||||
},
|
ch: " ",
|
||||||
keys: false,
|
inverse: true
|
||||||
vi: false,
|
},
|
||||||
mouse: true,
|
keys: false,
|
||||||
data: [["Name", "Size"]]
|
vi: false,
|
||||||
});
|
mouse: true,
|
||||||
|
data: [["ContractName", "Address", "Status"]]
|
||||||
|
});
|
||||||
|
|
||||||
this.screen.append(this.assets);
|
this.screen.append(this.modules);
|
||||||
};
|
}
|
||||||
|
|
||||||
Dashboard.prototype.layoutStatus = function() {
|
layoutAssets() {
|
||||||
|
this.assets = blessed.box({
|
||||||
this.wrapper = blessed.layout({
|
label: "Asset Pipeline",
|
||||||
width: "25%",
|
tags: true,
|
||||||
height: "42%",
|
padding: 1,
|
||||||
top: "0%",
|
width: "50%",
|
||||||
left: "75%",
|
height: "55%",
|
||||||
layout: "grid"
|
left: "50%",
|
||||||
});
|
top: "42%",
|
||||||
|
|
||||||
this.status = blessed.box({
|
|
||||||
parent: this.wrapper,
|
|
||||||
label: "Environment",
|
|
||||||
tags: true,
|
|
||||||
padding: {
|
|
||||||
left: 1
|
|
||||||
},
|
|
||||||
width: "100%",
|
|
||||||
height: "20%",
|
|
||||||
valign: "middle",
|
|
||||||
border: {
|
|
||||||
type: "line"
|
|
||||||
},
|
|
||||||
style: {
|
|
||||||
fg: -1,
|
|
||||||
border: {
|
border: {
|
||||||
fg: this.color
|
type: "line"
|
||||||
|
},
|
||||||
|
style: {
|
||||||
|
fg: -1,
|
||||||
|
border: {
|
||||||
|
fg: this.color
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
this.operations = blessed.box({
|
this.assetTable = blessed.table({
|
||||||
parent: this.wrapper,
|
parent: this.assets,
|
||||||
label: "Status",
|
height: "100%",
|
||||||
tags: true,
|
width: "100%-5",
|
||||||
padding: {
|
align: "left",
|
||||||
left: 1
|
pad: 1,
|
||||||
},
|
scrollable: true,
|
||||||
width: "100%",
|
alwaysScroll: true,
|
||||||
height: "20%",
|
scrollbar: {
|
||||||
valign: "middle",
|
ch: " ",
|
||||||
border: {
|
inverse: true
|
||||||
type: "line"
|
},
|
||||||
},
|
keys: false,
|
||||||
style: {
|
vi: false,
|
||||||
fg: -1,
|
mouse: true,
|
||||||
|
data: [["Name", "Size"]]
|
||||||
|
});
|
||||||
|
|
||||||
|
this.screen.append(this.assets);
|
||||||
|
}
|
||||||
|
|
||||||
|
layoutStatus() {
|
||||||
|
|
||||||
|
this.wrapper = blessed.layout({
|
||||||
|
width: "25%",
|
||||||
|
height: "42%",
|
||||||
|
top: "0%",
|
||||||
|
left: "75%",
|
||||||
|
layout: "grid"
|
||||||
|
});
|
||||||
|
|
||||||
|
this.status = blessed.box({
|
||||||
|
parent: this.wrapper,
|
||||||
|
label: "Environment",
|
||||||
|
tags: true,
|
||||||
|
padding: {
|
||||||
|
left: 1
|
||||||
|
},
|
||||||
|
width: "100%",
|
||||||
|
height: "20%",
|
||||||
|
valign: "middle",
|
||||||
border: {
|
border: {
|
||||||
fg: this.color
|
type: "line"
|
||||||
|
},
|
||||||
|
style: {
|
||||||
|
fg: -1,
|
||||||
|
border: {
|
||||||
|
fg: this.color
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
this.progress = blessed.box({
|
this.operations = blessed.box({
|
||||||
parent: this.wrapper,
|
parent: this.wrapper,
|
||||||
label: "Available Services",
|
label: "Status",
|
||||||
tags: true,
|
tags: true,
|
||||||
padding: this.minimal ? {
|
padding: {
|
||||||
left: 1
|
left: 1
|
||||||
} : 1,
|
},
|
||||||
width: "100%",
|
width: "100%",
|
||||||
height: "60%",
|
height: "20%",
|
||||||
valign: "top",
|
valign: "middle",
|
||||||
border: {
|
|
||||||
type: "line"
|
|
||||||
},
|
|
||||||
style: {
|
|
||||||
fg: -1,
|
|
||||||
border: {
|
border: {
|
||||||
fg: this.color
|
type: "line"
|
||||||
|
},
|
||||||
|
style: {
|
||||||
|
fg: -1,
|
||||||
|
border: {
|
||||||
|
fg: this.color
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
this.screen.append(this.wrapper);
|
this.progress = blessed.box({
|
||||||
};
|
parent: this.wrapper,
|
||||||
|
label: "Available Services",
|
||||||
|
tags: true,
|
||||||
Dashboard.prototype.layoutCmd = function() {
|
padding: this.minimal ? {
|
||||||
this.consoleBox = blessed.box({
|
left: 1
|
||||||
label: 'Console',
|
} : 1,
|
||||||
tags: true,
|
width: "100%",
|
||||||
padding: 0,
|
height: "60%",
|
||||||
width: '100%',
|
valign: "top",
|
||||||
height: '6%',
|
|
||||||
left: '0%',
|
|
||||||
top: '95%',
|
|
||||||
border: {
|
|
||||||
type: 'line'
|
|
||||||
},
|
|
||||||
style: {
|
|
||||||
fg: 'black',
|
|
||||||
border: {
|
border: {
|
||||||
fg: this.color
|
type: "line"
|
||||||
|
},
|
||||||
|
style: {
|
||||||
|
fg: -1,
|
||||||
|
border: {
|
||||||
|
fg: this.color
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
this.input = blessed.textbox({
|
this.screen.append(this.wrapper);
|
||||||
parent: this.consoleBox,
|
}
|
||||||
name: 'input',
|
|
||||||
input: true,
|
layoutCmd() {
|
||||||
keys: false,
|
this.consoleBox = blessed.box({
|
||||||
top: 0,
|
label: 'Console',
|
||||||
left: 1,
|
tags: true,
|
||||||
height: '50%',
|
padding: 0,
|
||||||
width: '100%-2',
|
width: '100%',
|
||||||
inputOnFocus: true,
|
height: '6%',
|
||||||
style: {
|
left: '0%',
|
||||||
fg: 'green',
|
top: '95%',
|
||||||
bg: 'black',
|
border: {
|
||||||
focus: {
|
type: 'line'
|
||||||
|
},
|
||||||
|
style: {
|
||||||
|
fg: 'black',
|
||||||
|
border: {
|
||||||
|
fg: this.color
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.input = blessed.textbox({
|
||||||
|
parent: this.consoleBox,
|
||||||
|
name: 'input',
|
||||||
|
input: true,
|
||||||
|
keys: false,
|
||||||
|
top: 0,
|
||||||
|
left: 1,
|
||||||
|
height: '50%',
|
||||||
|
width: '100%-2',
|
||||||
|
inputOnFocus: true,
|
||||||
|
style: {
|
||||||
|
fg: 'green',
|
||||||
bg: 'black',
|
bg: 'black',
|
||||||
fg: 'green'
|
focus: {
|
||||||
|
bg: 'black',
|
||||||
|
fg: 'green'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
var self = this;
|
let self = this;
|
||||||
|
|
||||||
this.input.key(["C-c"], function() {
|
this.input.key(["C-c"], function () {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.input.key(["C-w"], function() {
|
this.input.key(["C-w"], function () {
|
||||||
self.input.clearValue();
|
self.input.clearValue();
|
||||||
self.input.focus();
|
self.input.focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.input.key(["up"], function() {
|
this.input.key(["up"], function () {
|
||||||
var cmd = self.history.getPreviousCommand();
|
let cmd = self.history.getPreviousCommand();
|
||||||
self.input.setValue(cmd);
|
self.input.setValue(cmd);
|
||||||
self.input.focus();
|
self.input.focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.input.key(["down"], function() {
|
this.input.key(["down"], function () {
|
||||||
var cmd = self.history.getNextCommand();
|
let cmd = self.history.getNextCommand();
|
||||||
self.input.setValue(cmd);
|
self.input.setValue(cmd);
|
||||||
self.input.focus();
|
self.input.focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.input.on('submit', function(data) {
|
this.input.on('submit', function (data) {
|
||||||
if (data !== '') {
|
if (data !== '') {
|
||||||
self.history.addCommand(data);
|
self.history.addCommand(data);
|
||||||
self.logText.log('console> '.bold.green + data);
|
self.logText.log('console> '.bold.green + data);
|
||||||
self.console.executeCmd(data, function(result) {
|
self.console.executeCmd(data, function (result) {
|
||||||
self.logText.log(result);
|
self.logText.log(result);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
self.input.clearValue();
|
self.input.clearValue();
|
||||||
self.input.focus();
|
self.input.focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.screen.append(this.consoleBox);
|
this.screen.append(this.consoleBox);
|
||||||
};
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Dashboard;
|
module.exports = Dashboard;
|
||||||
|
348
lib/index.js
348
lib/index.js
@ -1,203 +1,207 @@
|
|||||||
/*jshint esversion: 6 */
|
/*jshint esversion: 6 */
|
||||||
var async = require('async');
|
let async = require('async');
|
||||||
// require("./utils/debug_util.js")(__filename, async);
|
// require("./utils/debug_util.js")(__filename, async);
|
||||||
|
|
||||||
var colors = require('colors');
|
let colors = require('colors');
|
||||||
|
|
||||||
var Engine = require('./core/engine.js');
|
let IPFS = require('./upload/ipfs.js');
|
||||||
|
let Swarm = require('./upload/swarm.js');
|
||||||
|
|
||||||
var IPFS = require('./upload/ipfs.js');
|
let EventEmitter = require('events').EventEmitter;
|
||||||
var Swarm = require('./upload/swarm.js');
|
let Config = require('./core/config');
|
||||||
|
/**
|
||||||
|
* Initialize a new `Embark` instance.
|
||||||
|
*
|
||||||
|
* @return {Embark}
|
||||||
|
* @api public
|
||||||
|
*/
|
||||||
|
|
||||||
var version = require('../package.json').version;
|
class Embark {
|
||||||
|
constructor(options) {
|
||||||
|
this.version = require('../package.json').version;
|
||||||
|
|
||||||
var Embark = (function () {
|
this.env = options.environment || options.env || "development";
|
||||||
function initConfig (env, options) {
|
|
||||||
var Events = require('./core/events.js');
|
|
||||||
var Logger = require('./core/logger.js');
|
|
||||||
var Config = require('./core/config.js');
|
|
||||||
|
|
||||||
this.events = new Events();
|
this.config = new Config({env: this.env, logger: this.logger, events: this.events});
|
||||||
this.logger = new Logger({logLevel: 'debug'});
|
|
||||||
|
|
||||||
this.config = new Config({env: env, logger: this.logger, events: this.events});
|
|
||||||
this.config.loadConfigFiles(options);
|
this.config.loadConfigFiles(options);
|
||||||
this.plugins = this.config.plugins;
|
this.plugins = this.config.plugins;
|
||||||
}
|
|
||||||
|
|
||||||
function blockchain (env, client) {
|
this.blockchain = function (env, client) {
|
||||||
return require('./cmds/blockchain/blockchain.js')(this.config.blockchainConfig, client, env).run();
|
return require('./cmds/blockchain/blockchain.js')(Embark.prototype.config.blockchainConfig, client, env).run();
|
||||||
}
|
};
|
||||||
|
|
||||||
function simulator (options) {
|
this.simulator = function (options) {
|
||||||
var Simulator = require('./cmds/simulator.js');
|
let Simulator = require('./cmds/simulator.js');
|
||||||
var simulator = new Simulator({blockchainConfig: this.config.blockchainConfig});
|
let simulator = new Simulator({blockchainConfig: Embark.prototype.config.blockchainConfig});
|
||||||
simulator.run(options);
|
simulator.run(options);
|
||||||
}
|
};
|
||||||
|
|
||||||
function generateTemplate (templateName, destinationFolder, name) {
|
this.generateTemplate = function (templateName, destinationFolder, name) {
|
||||||
var TemplateGenerator = require('./cmds/template_generator.js');
|
let TemplateGenerator = require('./cmds/template_generator.js');
|
||||||
var templateGenerator = new TemplateGenerator(templateName);
|
let templateGenerator = new TemplateGenerator(templateName);
|
||||||
templateGenerator.generate(destinationFolder, name);
|
templateGenerator.generate(destinationFolder, name);
|
||||||
}
|
};
|
||||||
|
|
||||||
function run (options) {
|
this.run = function (options) {
|
||||||
var Dashboard = require('./dashboard/dashboard.js');
|
let Dashboard = require('./dashboard/dashboard.js');
|
||||||
|
let Engine = require('./core/engine');
|
||||||
|
let engine = new Engine({
|
||||||
|
env: options.env,
|
||||||
|
embarkConfig: options.embarkConfig || 'embark.json'
|
||||||
|
});
|
||||||
|
|
||||||
var env = options.env;
|
engine.init();
|
||||||
|
|
||||||
var engine = new Engine({
|
if (!options.useDashboard) {
|
||||||
env: options.env,
|
console.log('========================'.bold.green);
|
||||||
embarkConfig: options.embarkConfig || 'embark.json'
|
console.log(('Welcome to Embark ' + Embark.version).yellow.bold);
|
||||||
});
|
console.log('========================'.bold.green);
|
||||||
engine.init();
|
}
|
||||||
|
|
||||||
if (!options.useDashboard) {
|
async.parallel([
|
||||||
console.log('========================'.bold.green);
|
function startDashboard(callback) {
|
||||||
console.log(('Welcome to Embark ' + Embark.version).yellow.bold);
|
if (!options.useDashboard) {
|
||||||
console.log('========================'.bold.green);
|
return callback();
|
||||||
}
|
|
||||||
|
|
||||||
async.parallel([
|
|
||||||
function startDashboard(callback) {
|
|
||||||
if (!options.useDashboard) {
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
|
|
||||||
var dashboard = new Dashboard({
|
|
||||||
logger: engine.logger,
|
|
||||||
plugins: engine.plugins,
|
|
||||||
version: engine.version,
|
|
||||||
env: engine.env
|
|
||||||
});
|
|
||||||
dashboard.start(function() {
|
|
||||||
engine.events.on('abi-vanila', function(abi) {
|
|
||||||
dashboard.console.runCode(abi);
|
|
||||||
});
|
|
||||||
|
|
||||||
engine.logger.info('dashboard start');
|
|
||||||
engine.events.on('servicesState', function(servicesState) {
|
|
||||||
dashboard.monitor.availableServices(servicesState);
|
|
||||||
});
|
|
||||||
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
function (callback) {
|
|
||||||
var pluginList = engine.plugins.listPlugins();
|
|
||||||
if (pluginList.length > 0) {
|
|
||||||
engine.logger.info("loaded plugins: " + pluginList.join(", "));
|
|
||||||
}
|
|
||||||
|
|
||||||
engine.startMonitor();
|
|
||||||
engine.startService("web3");
|
|
||||||
engine.startService("pipeline");
|
|
||||||
engine.startService("abi");
|
|
||||||
engine.startService("deployment");
|
|
||||||
engine.startService("ipfs");
|
|
||||||
|
|
||||||
engine.events.on('check:backOnline:Ethereum', function() {
|
|
||||||
engine.logger.info('Ethereum node detected..');
|
|
||||||
engine.config.reloadConfig();
|
|
||||||
engine.deployManager.deployContracts(function() {
|
|
||||||
engine.logger.info('Deployment Done');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
engine.deployManager.deployContracts(function(err) {
|
|
||||||
engine.startService("fileWatcher");
|
|
||||||
if (options.runWebserver) {
|
|
||||||
engine.startService("webServer", {
|
|
||||||
host: options.serverHost,
|
|
||||||
port: options.serverPort
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
callback(err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
], function(err, result) {
|
|
||||||
if (err) {
|
|
||||||
engine.logger.error(err.message);
|
|
||||||
engine.logger.info(err.stack);
|
|
||||||
} else {
|
|
||||||
engine.logger.setStatus("Ready".green);
|
|
||||||
engine.logger.info("Looking for documentation? you can find it at ".cyan + "http://embark.readthedocs.io/".green.underline);
|
|
||||||
engine.logger.info("Ready".underline);
|
|
||||||
engine.events.emit('firstDeploymentDone');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function build (options) {
|
let dashboard = new Dashboard({
|
||||||
|
logger: engine.logger,
|
||||||
|
plugins: engine.plugins,
|
||||||
|
version: engine.version,
|
||||||
|
env: engine.env
|
||||||
|
});
|
||||||
|
dashboard.start(function () {
|
||||||
|
Embark.on('abi-vanila', function (abi) {
|
||||||
|
dashboard.console.runCode(abi);
|
||||||
|
});
|
||||||
|
|
||||||
var engine = new Engine({
|
engine.logger.info('dashboard start');
|
||||||
env: options.env,
|
Embark.on('servicesState', function (servicesState) {
|
||||||
embarkConfig: 'embark.json',
|
dashboard.monitor.availableServices(servicesState);
|
||||||
interceptLogs: false
|
});
|
||||||
});
|
|
||||||
engine.init();
|
|
||||||
|
|
||||||
async.waterfall([
|
callback();
|
||||||
function startServices(callback) {
|
});
|
||||||
var pluginList = engine.plugins.listPlugins();
|
},
|
||||||
if (pluginList.length > 0) {
|
function (callback) {
|
||||||
engine.logger.info("loaded plugins: " + pluginList.join(", "));
|
let pluginList = engine.plugins.listPlugins();
|
||||||
|
if (pluginList.length > 0) {
|
||||||
|
engine.logger.info("loaded plugins: " + pluginList.join(", "));
|
||||||
|
}
|
||||||
|
|
||||||
|
engine.startMonitor();
|
||||||
|
engine.startService("web3");
|
||||||
|
engine.startService("pipeline");
|
||||||
|
engine.startService("abi");
|
||||||
|
engine.startService("deployment");
|
||||||
|
engine.startService("ipfs");
|
||||||
|
|
||||||
|
Embark.on('check:backOnline:Ethereum', function () {
|
||||||
|
engine.logger.info('Ethereum node detected..');
|
||||||
|
engine.config.reloadConfig();
|
||||||
|
engine.deployManager.deployContracts(function () {
|
||||||
|
engine.logger.info('Deployment Done');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
engine.deployManager.deployContracts(function (err) {
|
||||||
|
engine.startService("fileWatcher");
|
||||||
|
if (options.runWebserver) {
|
||||||
|
engine.startService("webServer", {
|
||||||
|
host: options.serverHost,
|
||||||
|
port: options.serverPort
|
||||||
|
});
|
||||||
|
}
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
], function (err, result) {
|
||||||
engine.startService("web3");
|
if (err) {
|
||||||
engine.startService("pipeline");
|
engine.logger.error(err.message);
|
||||||
engine.startService("abi");
|
engine.logger.info(err.stack);
|
||||||
engine.startService("deployment");
|
} else {
|
||||||
callback();
|
engine.logger.setStatus("Ready".green);
|
||||||
},
|
engine.logger.info("Looking for documentation? you can find it at ".cyan + "http://embark.readthedocs.io/".green.underline);
|
||||||
function deploy(callback) {
|
engine.logger.info("Ready".underline);
|
||||||
engine.deployManager.deployContracts(function(err) {
|
engine.events.emit('firstDeploymentDone');
|
||||||
callback(err);
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
this.build = function (options) {
|
||||||
|
let Engine = require('./core/engine');
|
||||||
|
|
||||||
|
let engine = new Engine({
|
||||||
|
env: options.env,
|
||||||
|
embarkConfig: 'embark.json',
|
||||||
|
interceptLogs: false
|
||||||
|
});
|
||||||
|
engine.init();
|
||||||
|
|
||||||
|
async.waterfall([
|
||||||
|
function startServices(callback) {
|
||||||
|
let pluginList = engine.plugins.listPlugins();
|
||||||
|
if (pluginList.length > 0) {
|
||||||
|
engine.logger.info("loaded plugins: " + pluginList.join(", "));
|
||||||
|
}
|
||||||
|
|
||||||
|
engine.startService("web3");
|
||||||
|
engine.startService("pipeline");
|
||||||
|
engine.startService("abi");
|
||||||
|
engine.startService("deployment");
|
||||||
|
callback();
|
||||||
|
},
|
||||||
|
function deploy(callback) {
|
||||||
|
engine.deployManager.deployContracts(function (err) {
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
], function (err, result) {
|
||||||
|
if (err) {
|
||||||
|
engine.logger.error(err.message);
|
||||||
|
engine.logger.debug(err.stack);
|
||||||
|
} else {
|
||||||
|
engine.logger.info("finished building".underline);
|
||||||
|
}
|
||||||
|
// needed due to child processes
|
||||||
|
process.exit();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
this.initTests = function () {
|
||||||
|
let Test = require('./core/test.js');
|
||||||
|
return new Test(options);
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: should deploy if it hasn't already
|
||||||
|
this.upload = function (platform) {
|
||||||
|
if (platform === 'ipfs') {
|
||||||
|
let ipfs = new IPFS({
|
||||||
|
buildDir: 'dist/',
|
||||||
|
plugins: Embark.prototype.plugins,
|
||||||
|
storageConfig: Embark.prototype.config.storageConfig
|
||||||
});
|
});
|
||||||
}
|
ipfs.deploy();
|
||||||
], function(err, result) {
|
} else if (platform === 'swarm') {
|
||||||
if (err) {
|
let swarm = new Swarm({
|
||||||
engine.logger.error(err.message);
|
buildDir: 'dist/',
|
||||||
engine.logger.debug(err.stack);
|
plugins: Embark.prototype.plugins,
|
||||||
|
storageConfig: Embark.prototype.config.storageConfig
|
||||||
|
});
|
||||||
|
swarm.deploy();
|
||||||
} else {
|
} else {
|
||||||
engine.logger.info("finished building".underline);
|
console.log(("unknown platform: " + platform).red);
|
||||||
|
console.log('try "embark upload ipfs" or "embark upload swarm"'.green);
|
||||||
}
|
}
|
||||||
// needed due to child processes
|
};
|
||||||
process.exit();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function initTests () {
|
if (!(this instanceof Embark)) {
|
||||||
var Test = require('./core/test.js');
|
return new Embark();
|
||||||
return new Test(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: should deploy if it hasn't already
|
|
||||||
function upload (platform) {
|
|
||||||
if (platform === 'ipfs') {
|
|
||||||
var ipfs = new IPFS({buildDir: 'dist/', plugins: this.plugins, storageConfig: this.config.storageConfig});
|
|
||||||
ipfs.deploy();
|
|
||||||
} else if (platform === 'swarm') {
|
|
||||||
var swarm = new Swarm({buildDir: 'dist/', plugins: this.plugins, storageConfig: this.config.storageConfig});
|
|
||||||
swarm.deploy();
|
|
||||||
} else {
|
|
||||||
console.log(("unknown platform: " + platform).red);
|
|
||||||
console.log('try "embark upload ipfs" or "embark upload swarm"'.green);
|
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
Embark.prototype = Object.create(EventEmitter.prototype);
|
||||||
version: version,
|
|
||||||
initConfig: initConfig,
|
|
||||||
blockchain: blockchain,
|
|
||||||
simulator: simulator,
|
|
||||||
generateTemplate: generateTemplate,
|
|
||||||
run: run,
|
|
||||||
build: build,
|
|
||||||
initTests: initTests,
|
|
||||||
upload: upload
|
|
||||||
};
|
|
||||||
|
|
||||||
})();
|
|
||||||
|
|
||||||
module.exports = Embark;
|
module.exports = Embark;
|
||||||
|
@ -1,80 +1,83 @@
|
|||||||
/*jshint esversion: 6, loopfunc: true */
|
/*jshint esversion: 6, loopfunc: true */
|
||||||
var fs = require('../core/fs.js');
|
let fs = require('../core/fs.js');
|
||||||
|
|
||||||
var Pipeline = function(options) {
|
class Pipeline {
|
||||||
this.buildDir = options.buildDir;
|
|
||||||
this.contractsFiles = options.contractsFiles;
|
|
||||||
this.assetFiles = options.assetFiles;
|
|
||||||
this.logger = options.logger;
|
|
||||||
this.plugins = options.plugins;
|
|
||||||
};
|
|
||||||
|
|
||||||
Pipeline.prototype.build = function(abi, path) {
|
constructor(options) {
|
||||||
var self = this;
|
this.buildDir = options.buildDir;
|
||||||
for(var targetFile in this.assetFiles) {
|
this.contractsFiles = options.contractsFiles;
|
||||||
|
this.assetFiles = options.assetFiles;
|
||||||
|
this.logger = options.logger;
|
||||||
|
this.plugins = options.plugins;
|
||||||
|
}
|
||||||
|
|
||||||
var contentFiles = this.assetFiles[targetFile].map(file => {
|
build(abi, path) {
|
||||||
self.logger.trace("reading " + file.filename);
|
let self = this;
|
||||||
|
for (let targetFile in this.assetFiles) {
|
||||||
|
|
||||||
var pipelinePlugins = this.plugins.getPluginsFor('pipeline');
|
let contentFiles = this.assetFiles[targetFile].map(file => {
|
||||||
|
self.logger.trace("reading " + file.filename);
|
||||||
|
|
||||||
if (file.filename === 'embark.js') {
|
let pipelinePlugins = this.plugins.getPluginsFor('pipeline');
|
||||||
return {content: file.content + "\n" + abi, filename: file.filename, path: file.path, modified: true};
|
|
||||||
} else if (file.filename === 'abi.js') {
|
|
||||||
return {content: abi, filename: file.filename, path: file.path, modified: true};
|
|
||||||
} else if (['web3.js', 'ipfs.js', 'ipfs-api.js', 'orbit.js'].indexOf(file.filename) >= 0) {
|
|
||||||
file.modified = true;
|
|
||||||
return file;
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if (pipelinePlugins.length > 0) {
|
if (file.filename === 'embark.js') {
|
||||||
pipelinePlugins.forEach(function(plugin) {
|
return {content: file.content + "\n" + abi, filename: file.filename, path: file.path, modified: true};
|
||||||
try {
|
} else if (file.filename === 'abi.js') {
|
||||||
if (file.options && file.options.skipPipeline) {
|
return {content: abi, filename: file.filename, path: file.path, modified: true};
|
||||||
return;
|
} else if (['web3.js', 'ipfs.js', 'ipfs-api.js', 'orbit.js'].indexOf(file.filename) >= 0) {
|
||||||
|
file.modified = true;
|
||||||
|
return file;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (pipelinePlugins.length > 0) {
|
||||||
|
pipelinePlugins.forEach(function (plugin) {
|
||||||
|
try {
|
||||||
|
if (file.options && file.options.skipPipeline) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
file.content = plugin.runPipeline({targetFile: file.filename, source: file.content});
|
||||||
|
file.modified = true;
|
||||||
}
|
}
|
||||||
file.content = plugin.runPipeline({targetFile: file.filename, source: file.content});
|
catch (err) {
|
||||||
file.modified = true;
|
self.logger.error(err.message);
|
||||||
}
|
}
|
||||||
catch(err) {
|
});
|
||||||
self.logger.error(err.message);
|
}
|
||||||
}
|
|
||||||
});
|
return file;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let dir = targetFile.split('/').slice(0, -1).join('/');
|
||||||
|
self.logger.trace("creating dir " + this.buildDir + dir);
|
||||||
|
fs.mkdirpSync(this.buildDir + dir);
|
||||||
|
|
||||||
|
// if it's a directory
|
||||||
|
if (targetFile.slice(-1) === '/' || targetFile.indexOf('.') === -1) {
|
||||||
|
let targetDir = targetFile;
|
||||||
|
|
||||||
|
if (targetDir.slice(-1) !== '/') {
|
||||||
|
targetDir = targetDir + '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
return file;
|
contentFiles.map(function (file) {
|
||||||
|
let filename = file.filename.replace('app/', '');
|
||||||
|
filename = filename.replace(targetDir, '');
|
||||||
|
self.logger.info("writing file " + (self.buildDir + targetDir + filename).bold.dim);
|
||||||
|
|
||||||
|
fs.copySync(self.buildDir + targetDir + filename, file.path, {overwrite: true});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
let content = contentFiles.map(function (file) {
|
||||||
|
return file.content;
|
||||||
|
}).join("\n");
|
||||||
|
|
||||||
|
self.logger.info("writing file " + (this.buildDir + targetFile).bold.dim);
|
||||||
|
fs.writeFileSync(this.buildDir + targetFile, content);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
var dir = targetFile.split('/').slice(0, -1).join('/');
|
|
||||||
self.logger.trace("creating dir " + this.buildDir + dir);
|
|
||||||
fs.mkdirpSync(this.buildDir + dir);
|
|
||||||
|
|
||||||
// if it's a directory
|
|
||||||
if (targetFile.slice(-1) === '/' || targetFile.indexOf('.') === -1) {
|
|
||||||
var targetDir = targetFile;
|
|
||||||
|
|
||||||
if (targetDir.slice(-1) !== '/') {
|
|
||||||
targetDir = targetDir + '/';
|
|
||||||
}
|
|
||||||
|
|
||||||
contentFiles.map(function(file) {
|
|
||||||
var filename = file.filename.replace('app/', '');
|
|
||||||
filename = filename.replace(targetDir, '');
|
|
||||||
self.logger.info("writing file " + (self.buildDir + targetDir + filename).bold.dim);
|
|
||||||
|
|
||||||
fs.copySync(self.buildDir + targetDir + filename, file.path, {overwrite: true});
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var content = contentFiles.map(function(file) {
|
|
||||||
return file.content;
|
|
||||||
}).join("\n");
|
|
||||||
|
|
||||||
self.logger.info("writing file " + (this.buildDir + targetFile).bold.dim);
|
|
||||||
fs.writeFileSync(this.buildDir + targetFile, content);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = Pipeline;
|
module.exports = Pipeline;
|
||||||
|
|
||||||
|
@ -1,24 +1,27 @@
|
|||||||
var finalhandler = require('finalhandler');
|
let finalhandler = require('finalhandler');
|
||||||
var http = require('http');
|
let http = require('http');
|
||||||
var serveStatic = require('serve-static');
|
let serveStatic = require('serve-static');
|
||||||
|
|
||||||
var Server = function(options) {
|
class Server {
|
||||||
this.dist = options.dist || 'dist/';
|
constructor(options) {
|
||||||
this.port = options.port || 8000;
|
this.dist = options.dist || 'dist/';
|
||||||
this.hostname = options.host || 'localhost';
|
this.port = options.port || 8000;
|
||||||
this.logger = options.logger;
|
this.hostname = options.host || 'localhost';
|
||||||
};
|
this.logger = options.logger;
|
||||||
|
}
|
||||||
|
|
||||||
Server.prototype.start = function(callback) {
|
start(callback) {
|
||||||
var serve = serveStatic(this.dist, {'index': ['index.html', 'index.htm']});
|
let serve = serveStatic(this.dist, {'index': ['index.html', 'index.htm']});
|
||||||
|
|
||||||
var server = http.createServer(function onRequest (req, res) {
|
let server = http.createServer(function onRequest(req, res) {
|
||||||
serve(req, res, finalhandler(req, res));
|
serve(req, res, finalhandler(req, res));
|
||||||
});
|
});
|
||||||
|
|
||||||
this.logger.info("webserver available at " + ("http://" + this.hostname + ":" + this.port).bold.underline.green);
|
this.logger.info("webserver available at " + ("http://" + this.hostname + ":" + this.port).bold.underline.green);
|
||||||
server.listen(this.port, this.hostname) ;
|
server.listen(this.port, this.hostname);
|
||||||
callback();
|
callback();
|
||||||
};
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Server;
|
module.exports = Server;
|
||||||
|
@ -1,101 +1,104 @@
|
|||||||
/*jshint esversion: 6 */
|
/*jshint esversion: 6 */
|
||||||
var chokidar = require('chokidar');
|
let chokidar = require('chokidar');
|
||||||
|
|
||||||
var fs = require('../core/fs.js');
|
let fs = require('../core/fs.js');
|
||||||
|
|
||||||
// TODO: this should be receiving the config object not re-reading the
|
// TODO: this should be receiving the config object not re-reading the
|
||||||
// embark.json file
|
// embark.json file
|
||||||
var Watch = function(options) {
|
class Watch {
|
||||||
this.logger = options.logger;
|
constructor(options) {
|
||||||
this.events = options.events;
|
this.logger = options.logger;
|
||||||
};
|
this.events = options.events;
|
||||||
|
|
||||||
Watch.prototype.start = function() {
|
|
||||||
var self = this;
|
|
||||||
// TODO: should come from the config object instead of reading the file
|
|
||||||
// directly
|
|
||||||
var embarkConfig = fs.readJSONSync('embark.json');
|
|
||||||
|
|
||||||
this.watchAssets(embarkConfig, function() {
|
|
||||||
self.logger.trace('ready to watch asset changes');
|
|
||||||
});
|
|
||||||
|
|
||||||
this.watchContracts(embarkConfig, function() {
|
|
||||||
self.logger.trace('ready to watch contract changes');
|
|
||||||
});
|
|
||||||
|
|
||||||
this.watchConfigs(function() {
|
|
||||||
self.logger.trace('ready to watch config changes');
|
|
||||||
});
|
|
||||||
|
|
||||||
this.logger.info("ready to watch file changes");
|
|
||||||
};
|
|
||||||
|
|
||||||
Watch.prototype.watchAssets = function(embarkConfig, callback) {
|
|
||||||
var self = this;
|
|
||||||
var appConfig = embarkConfig.app;
|
|
||||||
var filesToWatch = [];
|
|
||||||
|
|
||||||
for(var targetFile in appConfig) {
|
|
||||||
filesToWatch.push(appConfig[targetFile]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.watchFiles(
|
start() {
|
||||||
filesToWatch,
|
let self = this;
|
||||||
function(eventName, path) {
|
// TODO: should come from the config object instead of reading the file
|
||||||
self.logger.info(`${eventName}: ${path}`);
|
// directly
|
||||||
self.events.emit('file-' + eventName, 'asset', path);
|
let embarkConfig = fs.readJSONSync("embark.json");
|
||||||
self.events.emit('file-event', 'asset', path);
|
|
||||||
},
|
this.watchAssets(embarkConfig, function () {
|
||||||
function() {
|
self.logger.trace('ready to watch asset changes');
|
||||||
callback();
|
});
|
||||||
|
|
||||||
|
this.watchContracts(embarkConfig, function () {
|
||||||
|
self.logger.trace('ready to watch contract changes');
|
||||||
|
});
|
||||||
|
|
||||||
|
this.watchConfigs(function () {
|
||||||
|
self.logger.trace('ready to watch config changes');
|
||||||
|
});
|
||||||
|
|
||||||
|
this.logger.info("ready to watch file changes");
|
||||||
|
}
|
||||||
|
|
||||||
|
watchAssets(embarkConfig, callback) {
|
||||||
|
let self = this;
|
||||||
|
let appConfig = embarkConfig.app;
|
||||||
|
let filesToWatch = [];
|
||||||
|
|
||||||
|
for (let targetFile in appConfig) {
|
||||||
|
filesToWatch.push(appConfig[targetFile]);
|
||||||
}
|
}
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
Watch.prototype.watchContracts = function(embarkConfig, callback) {
|
this.watchFiles(
|
||||||
var self = this;
|
filesToWatch,
|
||||||
this.watchFiles(
|
function (eventName, path) {
|
||||||
[embarkConfig.contracts],
|
self.logger.info(`${eventName}: ${path}`);
|
||||||
function(eventName, path) {
|
self.events.emit('file-' + eventName, 'asset', path);
|
||||||
self.logger.info(`${eventName}: ${path}`);
|
self.events.emit('file-event', 'asset', path);
|
||||||
self.events.emit('file-' + eventName, 'contract', path);
|
},
|
||||||
self.events.emit('file-event', 'contract', path);
|
function () {
|
||||||
},
|
callback();
|
||||||
function() {
|
}
|
||||||
callback();
|
);
|
||||||
}
|
}
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
Watch.prototype.watchConfigs = function(callback) {
|
watchContracts(embarkConfig, callback) {
|
||||||
var self = this;
|
let self = this;
|
||||||
this.watchFiles(
|
this.watchFiles(
|
||||||
"config/**/contracts.json",
|
[embarkConfig.contracts],
|
||||||
function(eventName, path) {
|
function (eventName, path) {
|
||||||
self.logger.info(`${eventName}: ${path}`);
|
self.logger.info(`${eventName}: ${path}`);
|
||||||
self.events.emit('file-' + eventName, 'config', path);
|
self.events.emit('file-' + eventName, 'contract', path);
|
||||||
self.events.emit('file-event', 'config', path);
|
self.events.emit('file-event', 'contract', path);
|
||||||
},
|
},
|
||||||
function() {
|
function () {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
Watch.prototype.watchFiles = function(files, changeCallback, doneCallback) {
|
watchConfigs(callback) {
|
||||||
this.logger.trace('watchFiles');
|
let self = this;
|
||||||
this.logger.trace(files);
|
this.watchFiles(
|
||||||
|
"config/**/contracts.json",
|
||||||
|
function (eventName, path) {
|
||||||
|
self.logger.info(`${eventName}: ${path}`);
|
||||||
|
self.events.emit('file-' + eventName, 'config', path);
|
||||||
|
self.events.emit('file-event', 'config', path);
|
||||||
|
},
|
||||||
|
function () {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
var configWatcher = chokidar.watch(files, {
|
watchFiles(files, changeCallback, doneCallback) {
|
||||||
ignored: /[\/\\]\./, persistent: true, ignoreInitial: true, followSymlinks: true
|
this.logger.trace('watchFiles');
|
||||||
});
|
this.logger.trace(files);
|
||||||
|
|
||||||
configWatcher
|
let configWatcher = chokidar.watch(files, {
|
||||||
.on('add', path => changeCallback('add', path))
|
ignored: /[\/\\]\./, persistent: true, ignoreInitial: true, followSymlinks: true
|
||||||
.on('change', path => changeCallback('change', path))
|
});
|
||||||
.on('unlink', path => changeCallback('remove', path))
|
|
||||||
.on('ready', doneCallback);
|
configWatcher
|
||||||
};
|
.on('add', path => changeCallback('add', path))
|
||||||
|
.on('change', path => changeCallback('change', path))
|
||||||
|
.on('unlink', path => changeCallback('remove', path))
|
||||||
|
.on('ready', doneCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Watch;
|
module.exports = Watch;
|
||||||
|
@ -1,56 +1,60 @@
|
|||||||
var colors = require('colors');
|
let colors = require('colors');
|
||||||
var async = require('async');
|
let async = require('async');
|
||||||
var shelljs = require('shelljs');
|
let shelljs = require('shelljs');
|
||||||
|
|
||||||
var IPFS = function(options) {
|
class IPFS {
|
||||||
this.options = options;
|
|
||||||
this.buildDir = options.buildDir || 'dist/';
|
|
||||||
this.plugins = options.plugins;
|
|
||||||
this.storageConfig = options.storageConfig;
|
|
||||||
this.configIpfsBin = this.storageConfig.ipfs_bin || "ipfs";
|
|
||||||
};
|
|
||||||
|
|
||||||
IPFS.prototype.deploy = function() {
|
constructor(options) {
|
||||||
var self = this;
|
this.options = options;
|
||||||
async.waterfall([
|
this.buildDir = options.buildDir || 'dist/';
|
||||||
function findBinary(callback) {
|
this.plugins = options.plugins;
|
||||||
var ipfs_bin = shelljs.exec('which ' + self.configIpfsBin).output.split("\n")[0];
|
this.storageConfig = options.storageConfig;
|
||||||
|
this.configIpfsBin = this.storageConfig.ipfs_bin || "ipfs";
|
||||||
|
}
|
||||||
|
|
||||||
if (ipfs_bin === 'ipfs not found' || ipfs_bin === ''){
|
deploy() {
|
||||||
console.log(('=== WARNING: ' + self.configIpfsBin + ' not found or not in the path. Guessing ~/go/bin/ipfs for path').yellow);
|
let self = this;
|
||||||
ipfs_bin = "~/go/bin/ipfs";
|
async.waterfall([
|
||||||
|
function findBinary(callback) {
|
||||||
|
let ipfs_bin = shelljs.exec('which ' + self.configIpfsBin).output.split("\n")[0];
|
||||||
|
|
||||||
|
if (ipfs_bin === 'ipfs not found' || ipfs_bin === '') {
|
||||||
|
console.log(('=== WARNING: ' + self.configIpfsBin + ' not found or not in the path. Guessing ~/go/bin/ipfs for path').yellow);
|
||||||
|
ipfs_bin = "~/go/bin/ipfs";
|
||||||
|
}
|
||||||
|
|
||||||
|
return callback(null, ipfs_bin);
|
||||||
|
},
|
||||||
|
function runCommand(ipfs_bin, callback) {
|
||||||
|
let cmd = ipfs_bin + " add -r " + self.buildDir;
|
||||||
|
console.log(("=== adding " + self.buildDir + " to ipfs").green);
|
||||||
|
console.log(cmd.green);
|
||||||
|
let result = shelljs.exec(cmd);
|
||||||
|
|
||||||
|
return callback(null, result);
|
||||||
|
},
|
||||||
|
function getHashFromOutput(result, callback) {
|
||||||
|
let rows = result.output.split("\n");
|
||||||
|
let dir_row = rows[rows.length - 2];
|
||||||
|
let dir_hash = dir_row.split(" ")[1];
|
||||||
|
|
||||||
|
return callback(null, dir_hash);
|
||||||
|
},
|
||||||
|
function printUrls(dir_hash, callback) {
|
||||||
|
console.log(("=== DApp available at http://localhost:8080/ipfs/" + dir_hash + "/").green);
|
||||||
|
console.log(("=== DApp available at http://gateway.ipfs.io/ipfs/" + dir_hash + "/").green);
|
||||||
|
|
||||||
|
return callback();
|
||||||
}
|
}
|
||||||
|
], function (err, result) {
|
||||||
return callback(null, ipfs_bin);
|
|
||||||
},
|
|
||||||
function runCommand(ipfs_bin, callback) {
|
|
||||||
var cmd = ipfs_bin + " add -r " + self.buildDir;
|
|
||||||
console.log(("=== adding " + self.buildDir + " to ipfs").green);
|
|
||||||
console.log(cmd.green);
|
|
||||||
var result = shelljs.exec(cmd);
|
|
||||||
|
|
||||||
return callback(null, result);
|
|
||||||
},
|
|
||||||
function getHashFromOutput(result, callback) {
|
|
||||||
var rows = result.output.split("\n");
|
|
||||||
var dir_row = rows[rows.length - 2];
|
|
||||||
var dir_hash = dir_row.split(" ")[1];
|
|
||||||
|
|
||||||
return callback(null, dir_hash);
|
|
||||||
},
|
|
||||||
function printUrls(dir_hash, callback) {
|
|
||||||
console.log(("=== DApp available at http://localhost:8080/ipfs/" + dir_hash + "/").green);
|
|
||||||
console.log(("=== DApp available at http://gateway.ipfs.io/ipfs/" + dir_hash + "/").green);
|
|
||||||
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
], function(err, result) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log("error uploading to ipfs".red);
|
console.log("error uploading to ipfs".red);
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = IPFS;
|
module.exports = IPFS;
|
||||||
|
|
||||||
|
@ -1,55 +1,57 @@
|
|||||||
var colors = require('colors');
|
let colors = require('colors');
|
||||||
var async = require('async');
|
let async = require('async');
|
||||||
var shelljs = require('shelljs');
|
let shelljs = require('shelljs');
|
||||||
|
|
||||||
var Swarm = function(options) {
|
class Swarm {
|
||||||
this.options = options;
|
constructor(options) {
|
||||||
this.buildDir = options.buildDir || 'dist/';
|
this.options = options;
|
||||||
};
|
this.buildDir = options.buildDir || 'dist/';
|
||||||
|
}
|
||||||
|
|
||||||
Swarm.prototype.deploy = function() {
|
deploy() {
|
||||||
var self = this;
|
let self = this;
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function findBinary(callback) {
|
function findBinary(callback) {
|
||||||
var swarm_bin = shelljs.exec('which swarm').output.split("\n")[0];
|
let swarm_bin = shelljs.exec('which swarm').output.split("\n")[0];
|
||||||
|
|
||||||
if (swarm_bin==='swarm not found' || swarm_bin === ''){
|
if (swarm_bin === 'swarm not found' || swarm_bin === '') {
|
||||||
console.log('=== WARNING: Swarm not in an executable path. Guessing ~/go/bin/swarm for path'.yellow);
|
console.log('=== WARNING: Swarm not in an executable path. Guessing ~/go/bin/swarm for path'.yellow);
|
||||||
swarm_bin = "~/go/bin/swarm";
|
swarm_bin = "~/go/bin/swarm";
|
||||||
|
}
|
||||||
|
|
||||||
|
return callback(null, swarm_bin);
|
||||||
|
},
|
||||||
|
function runCommand(swarm_bin, callback) {
|
||||||
|
let cmd = swarm_bin + " --defaultpath " + self.buildDir + "index.html --recursive up " + self.buildDir;
|
||||||
|
console.log(("=== adding " + self.buildDir + " to swarm").green);
|
||||||
|
console.log(cmd.green);
|
||||||
|
let result = shelljs.exec(cmd);
|
||||||
|
|
||||||
|
return callback(null, result);
|
||||||
|
},
|
||||||
|
function getHashFromOutput(result, callback) {
|
||||||
|
if (result.code !== 0) {
|
||||||
|
return callback("couldn't upload, is the swarm daemon running?");
|
||||||
|
}
|
||||||
|
|
||||||
|
let rows = result.output.split("\n");
|
||||||
|
let dir_hash = rows.reverse()[1];
|
||||||
|
|
||||||
|
return callback(null, dir_hash);
|
||||||
|
},
|
||||||
|
function printUrls(dir_hash, callback) {
|
||||||
|
console.log(("=== DApp available at http://localhost:8500/bzz:/" + dir_hash + "/").green);
|
||||||
|
|
||||||
|
return callback();
|
||||||
}
|
}
|
||||||
|
], function (err, result) {
|
||||||
return callback(null, swarm_bin);
|
|
||||||
},
|
|
||||||
function runCommand(swarm_bin, callback) {
|
|
||||||
var cmd = swarm_bin + " --defaultpath " + self.buildDir + "index.html --recursive up " + self.buildDir;
|
|
||||||
console.log(("=== adding " + self.buildDir + " to swarm").green);
|
|
||||||
console.log(cmd.green);
|
|
||||||
var result = shelljs.exec(cmd);
|
|
||||||
|
|
||||||
return callback(null, result);
|
|
||||||
},
|
|
||||||
function getHashFromOutput(result, callback) {
|
|
||||||
if (result.code !== 0) {
|
|
||||||
return callback("couldn't upload, is the swarm daemon running?");
|
|
||||||
}
|
|
||||||
|
|
||||||
var rows = result.output.split("\n");
|
|
||||||
var dir_hash = rows.reverse()[1];
|
|
||||||
|
|
||||||
return callback(null, dir_hash);
|
|
||||||
},
|
|
||||||
function printUrls(dir_hash, callback) {
|
|
||||||
console.log(("=== DApp available at http://localhost:8500/bzz:/" + dir_hash + "/").green);
|
|
||||||
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
], function(err, result) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log("error uploading to swarm".red);
|
console.log("error uploading to swarm".red);
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Swarm;
|
module.exports = Swarm;
|
||||||
|
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
var async = require('async');
|
let async = require('async');
|
||||||
|
|
||||||
function asyncEachObject(object, iterator, callback) {
|
function asyncEachObject(object, iterator, callback) {
|
||||||
async.each(
|
async.each(
|
||||||
Object.keys(object || {}),
|
Object.keys(object || {}),
|
||||||
function(key, next){
|
function (key, next) {
|
||||||
iterator(key, object[key], next);
|
iterator(key, object[key], next);
|
||||||
},
|
},
|
||||||
callback
|
callback
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async.eachObject = asyncEachObject;
|
async.eachObject = asyncEachObject;
|
||||||
|
|
||||||
module.exports = async;
|
module.exports = async;
|
||||||
|
@ -5,9 +5,9 @@ function extend(filename, async) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
async._waterfall = async.waterfall;
|
async._waterfall = async.waterfall;
|
||||||
async.waterfall = function(_tasks, callback) {
|
async.waterfall = function (_tasks, callback) {
|
||||||
var tasks = _tasks.map(function(t) {
|
let tasks = _tasks.map(function (t) {
|
||||||
var fn = function() {
|
let fn = function () {
|
||||||
console.log("async " + filename + ": " + t.name);
|
console.log("async " + filename + ": " + t.name);
|
||||||
t.apply(t, arguments);
|
t.apply(t, arguments);
|
||||||
};
|
};
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
/*global exit */
|
/*global exit */
|
||||||
var path = require('path');
|
let path = require('path');
|
||||||
var globule = require('globule');
|
let globule = require('globule');
|
||||||
var merge = require('merge');
|
let merge = require('merge');
|
||||||
var http = require('http');
|
let http = require('http');
|
||||||
var shelljs = require('shelljs');
|
let shelljs = require('shelljs');
|
||||||
|
|
||||||
function joinPath() {
|
function joinPath() {
|
||||||
return path.join.apply(path.join, arguments);
|
return path.join.apply(path.join, arguments);
|
||||||
@ -22,15 +22,15 @@ function recursiveMerge(target, source) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function checkIsAvailable(url, callback) {
|
function checkIsAvailable(url, callback) {
|
||||||
http.get(url, function(res) {
|
http.get(url, function (res) {
|
||||||
callback(true);
|
callback(true);
|
||||||
}).on('error', function(res) {
|
}).on('error', function (res) {
|
||||||
callback(false);
|
callback(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function runCmd(cmd, options) {
|
function runCmd(cmd, options) {
|
||||||
var result = shelljs.exec(cmd, options || {silent: true});
|
let result = shelljs.exec(cmd, options || {silent: true});
|
||||||
if (result.code !== 0) {
|
if (result.code !== 0) {
|
||||||
console.log("error doing.. " + cmd);
|
console.log("error doing.. " + cmd);
|
||||||
console.log(result.output);
|
console.log(result.output);
|
||||||
@ -53,6 +53,7 @@ function exit(code) {
|
|||||||
process.exit(code);
|
process.exit(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: Maybe desired to just `module.exports = this` ?
|
||||||
module.exports = {
|
module.exports = {
|
||||||
joinPath: joinPath,
|
joinPath: joinPath,
|
||||||
filesMatchingPattern: filesMatchingPattern,
|
filesMatchingPattern: filesMatchingPattern,
|
||||||
|
16
package.json
16
package.json
@ -31,6 +31,8 @@
|
|||||||
"shelljs": "^0.5.0",
|
"shelljs": "^0.5.0",
|
||||||
"solc": "0.4.8",
|
"solc": "0.4.8",
|
||||||
"toposort": "^1.0.0",
|
"toposort": "^1.0.0",
|
||||||
|
"underscore": "^1.8.3",
|
||||||
|
"underscore.string": "^3.3.4",
|
||||||
"web3": "^0.18.2"
|
"web3": "^0.18.2"
|
||||||
},
|
},
|
||||||
"author": "Iuri Matias <iuri.matias@gmail.com>",
|
"author": "Iuri Matias <iuri.matias@gmail.com>",
|
||||||
@ -59,5 +61,19 @@
|
|||||||
"mocha-sinon": "^1.1.4",
|
"mocha-sinon": "^1.1.4",
|
||||||
"sinon": "^1.15.4",
|
"sinon": "^1.15.4",
|
||||||
"toposort": "^1.0.0"
|
"toposort": "^1.0.0"
|
||||||
|
},
|
||||||
|
"jshintConfig": {
|
||||||
|
"indent": 2,
|
||||||
|
"white": true,
|
||||||
|
"node": true,
|
||||||
|
"undef": true,
|
||||||
|
"-W058": true,
|
||||||
|
"-W014": true,
|
||||||
|
"expr": true,
|
||||||
|
"esversion": 6,
|
||||||
|
"unused": false,
|
||||||
|
"globals": {
|
||||||
|
"node": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
18
test/abi.js
18
test/abi.js
@ -1,23 +1,23 @@
|
|||||||
/*globals describe, it*/
|
/*globals describe, it*/
|
||||||
var ABIGenerator = require('../lib/contracts/abi.js');
|
let ABIGenerator = require('../lib/contracts/abi.js');
|
||||||
var assert = require('assert');
|
let assert = require('assert');
|
||||||
|
|
||||||
// TODO: instead 'eval' the code with a fake web3 object
|
// TODO: instead 'eval' the code with a fake web3 object
|
||||||
// and check the generate code interacts as expected
|
// and check the generate code interacts as expected
|
||||||
describe('embark.ABIGenerator', function() {
|
describe('embark.ABIGenerator', function() {
|
||||||
this.timeout(0);
|
this.timeout(0);
|
||||||
describe('#generateProvider', function() {
|
describe('#generateProvider', function() {
|
||||||
var generator = new ABIGenerator({blockchainConfig: {rpcHost: 'somehost', rpcPort: '1234'}, contractsManager: {}});
|
let generator = new ABIGenerator({blockchainConfig: {rpcHost: 'somehost', rpcPort: '1234'}, contractsManager: {}});
|
||||||
|
|
||||||
it('should generate code to connect to a provider', function() {
|
it('should generate code to connect to a provider', function() {
|
||||||
var providerCode = "\nif (typeof web3 !== 'undefined' && typeof Web3 !== 'undefined') {\n\tweb3 = new Web3(web3.currentProvider);\n} else if (typeof Web3 !== 'undefined') {\n\tweb3 = new Web3(new Web3.providers.HttpProvider(\"http://somehost:1234\"));\n}\nweb3.eth.defaultAccount = web3.eth.accounts[0];";
|
let providerCode = "\nif (typeof web3 !== 'undefined' && typeof Web3 !== 'undefined') {\n\tweb3 = new Web3(web3.currentProvider);\n} else if (typeof Web3 !== 'undefined') {\n\tweb3 = new Web3(new Web3.providers.HttpProvider(\"http://somehost:1234\"));\n}\nweb3.eth.defaultAccount = web3.eth.accounts[0];";
|
||||||
|
|
||||||
assert.equal(generator.generateProvider(), providerCode);
|
assert.equal(generator.generateProvider(), providerCode);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#generateContracts', function() {
|
describe('#generateContracts', function() {
|
||||||
var generator = new ABIGenerator({blockchainConfig: {}, contractsManager: {
|
let generator = new ABIGenerator({blockchainConfig: {}, contractsManager: {
|
||||||
contracts: {
|
contracts: {
|
||||||
SimpleStorage: {
|
SimpleStorage: {
|
||||||
abiDefinition: [{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"type":"constructor"}],
|
abiDefinition: [{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"type":"constructor"}],
|
||||||
@ -35,19 +35,19 @@ describe('embark.ABIGenerator', function() {
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
describe('with EmbarkJS', function() {
|
describe('with EmbarkJS', function() {
|
||||||
var withEmbarkJS = true;
|
let withEmbarkJS = true;
|
||||||
|
|
||||||
it('should generate contract code', function() {
|
it('should generate contract code', function() {
|
||||||
var contractCode = "\n\nSimpleStorage = new EmbarkJS.Contract({abi: [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}], address: '0x123', code: '12345', gasEstimates: 12000});\nFoo = new EmbarkJS.Contract({abi: [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}], address: '0x124', code: '123456', gasEstimates: 12000});";
|
let contractCode = "\n\nSimpleStorage = new EmbarkJS.Contract({abi: [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}], address: '0x123', code: '12345', gasEstimates: 12000});\nFoo = new EmbarkJS.Contract({abi: [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}], address: '0x124', code: '123456', gasEstimates: 12000});";
|
||||||
assert.equal(generator.generateContracts(withEmbarkJS), contractCode);
|
assert.equal(generator.generateContracts(withEmbarkJS), contractCode);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with default interface', function() {
|
describe('with default interface', function() {
|
||||||
var withEmbarkJS = false;
|
let withEmbarkJS = false;
|
||||||
|
|
||||||
it('should generate contract code', function() {
|
it('should generate contract code', function() {
|
||||||
var contractCode = "\n\nSimpleStorageAbi = [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}];\nSimpleStorageContract = web3.eth.contract(SimpleStorageAbi);\nSimpleStorage = SimpleStorageContract.at('0x123');\nFooAbi = [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}];\nFooContract = web3.eth.contract(FooAbi);\nFoo = FooContract.at('0x124');";
|
let contractCode = "\n\nSimpleStorageAbi = [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}];\nSimpleStorageContract = web3.eth.contract(SimpleStorageAbi);\nSimpleStorage = SimpleStorageContract.at('0x123');\nFooAbi = [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}];\nFooContract = web3.eth.contract(FooAbi);\nFoo = FooContract.at('0x124');";
|
||||||
assert.equal(generator.generateContracts(withEmbarkJS), contractCode);
|
assert.equal(generator.generateContracts(withEmbarkJS), contractCode);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
/*globals describe, it*/
|
/*globals describe, it*/
|
||||||
var Blockchain = require('../lib/cmds/blockchain/blockchain.js');
|
const Blockchain = require('../lib/cmds/blockchain/blockchain');
|
||||||
var assert = require('assert');
|
|
||||||
|
|
||||||
describe('embark.Blockchain', function() {
|
const assert = require('assert');
|
||||||
//var Client = function() {};
|
|
||||||
|
describe('embark.Blockchain', function () {
|
||||||
|
//let Client = function() {};
|
||||||
//Client.prototype.name = "ClientName";
|
//Client.prototype.name = "ClientName";
|
||||||
|
|
||||||
describe('#initializer', function() {
|
describe('#initializer', function () {
|
||||||
//var client = new Client();
|
//let client = new Client();
|
||||||
|
|
||||||
describe('with empty config', function() {
|
describe('with empty config', function () {
|
||||||
it('should have a default config', function() {
|
it('should have a default config', function () {
|
||||||
var config = {
|
let config = {
|
||||||
networkType: 'custom',
|
networkType: 'custom',
|
||||||
genesisBlock: false,
|
genesisBlock: false,
|
||||||
geth_bin: 'geth',
|
geth_bin: 'geth',
|
||||||
@ -31,15 +32,15 @@ describe('embark.Blockchain', function() {
|
|||||||
account: {},
|
account: {},
|
||||||
bootnodes: ""
|
bootnodes: ""
|
||||||
};
|
};
|
||||||
var blockchain = Blockchain(config, 'geth');
|
let blockchain = new Blockchain(config, 'geth');
|
||||||
|
|
||||||
assert.deepEqual(blockchain.config, config);
|
assert.deepEqual(blockchain.config, config);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with config', function() {
|
describe('with config', function () {
|
||||||
it('should take config params', function() {
|
it('should take config params', function () {
|
||||||
var config = {
|
let config = {
|
||||||
networkType: 'livenet',
|
networkType: 'livenet',
|
||||||
genesisBlock: 'foo/bar/genesis.json',
|
genesisBlock: 'foo/bar/genesis.json',
|
||||||
geth_bin: 'geth',
|
geth_bin: 'geth',
|
||||||
@ -59,7 +60,7 @@ describe('embark.Blockchain', function() {
|
|||||||
account: {},
|
account: {},
|
||||||
bootnodes: ""
|
bootnodes: ""
|
||||||
};
|
};
|
||||||
var blockchain = Blockchain(config, 'geth');
|
let blockchain = new Blockchain(config, 'geth');
|
||||||
|
|
||||||
assert.deepEqual(blockchain.config, config);
|
assert.deepEqual(blockchain.config, config);
|
||||||
});
|
});
|
||||||
|
55
test/cmd.js
55
test/cmd.js
@ -1,5 +1,5 @@
|
|||||||
var Embark = require('../lib/index');
|
let Embark = require('../lib/index');
|
||||||
var Cmd = require('../lib/cmd');
|
let Cmd = require('../lib/cmd');
|
||||||
|
|
||||||
// Function to send a line to stdin
|
// Function to send a line to stdin
|
||||||
function sendLine(line) {
|
function sendLine(line) {
|
||||||
@ -8,8 +8,8 @@ function sendLine(line) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var passingLines = function () {
|
let passingLines = function () {
|
||||||
var lines = [];
|
let lines = [];
|
||||||
lines.push('Initializing Embark Template....');
|
lines.push('Initializing Embark Template....');
|
||||||
lines.push('Installing packages.. this can take a few seconds');
|
lines.push('Installing packages.. this can take a few seconds');
|
||||||
lines.push('Init complete');
|
lines.push('Init complete');
|
||||||
@ -21,35 +21,32 @@ describe('embark.Cmd', function () {
|
|||||||
|
|
||||||
describe('#new', function () {
|
describe('#new', function () {
|
||||||
it('it should create an app with a name', function (done) {
|
it('it should create an app with a name', function (done) {
|
||||||
// var cmd = new Cmd(Embark);
|
let cmd = new Cmd(Embark);
|
||||||
// var pl = passingLines();
|
let pl = passingLines();
|
||||||
// var appname = 'deleteapp';
|
let appname = 'deleteapp';
|
||||||
// cmd.newApp(appname, function (output) {
|
cmd.newApp(appname, function (output) {
|
||||||
// var lines = output.split('\n');
|
let lines = output.split('\n');
|
||||||
// console.log(lines);
|
console.log(lines);
|
||||||
// assert.equal(lines[0], pl[0]);
|
assert.equal(lines[0], pl[0]);
|
||||||
// assert.equal(lines[1], pl[1]);
|
assert.equal(lines[1], pl[1]);
|
||||||
// assert.equal(lines[2], pl[2]);
|
assert.equal(lines[2], pl[2]);
|
||||||
// assert.equal(lines[3], 'App ready at ./' + appname);
|
assert.equal(lines[3], 'App ready at ./' + appname);
|
||||||
// });
|
});
|
||||||
|
|
||||||
//TODO: future branch will test this in vorpal vs commander
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('it should prompt when given an empty app name', function (done) {
|
it('it should prompt when given an empty app name', function (done) {
|
||||||
// var cmd = new Cmd(Embark);
|
let cmd = new Cmd(Embark);
|
||||||
// var pl = passingLines();
|
let pl = passingLines();
|
||||||
// var appname = 'deleteapp';
|
let appname = 'deleteapp';
|
||||||
//
|
|
||||||
// cmd.newApp(undefined, function (output) {
|
cmd.newApp(undefined, function (output) {
|
||||||
// var lines = output.split('\n');
|
let lines = output.split('\n');
|
||||||
// console.log(lines);
|
console.log(lines);
|
||||||
// sendLine(appname + '\n');
|
sendLine(appname + '\n');
|
||||||
// assert.equal(lines[0], pl[0]);
|
assert.equal(lines[0], pl[0]);
|
||||||
// done();
|
});
|
||||||
// });
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
});
|
});
|
@ -1,20 +1,20 @@
|
|||||||
/*globals describe, it*/
|
/*globals describe, it*/
|
||||||
var Compiler = require('../lib/contracts/compiler.js');
|
let Compiler = require('../lib/contracts/compiler.js');
|
||||||
var TestLogger = require('../lib/core/test_logger.js');
|
let TestLogger = require('../lib/core/test_logger.js');
|
||||||
var assert = require('assert');
|
let assert = require('assert');
|
||||||
var fs = require('fs');
|
let fs = require('fs');
|
||||||
|
|
||||||
var readFile = function(file) {
|
let readFile = function(file) {
|
||||||
return {filename: file, content: fs.readFileSync(file).toString()};
|
return {filename: file, content: fs.readFileSync(file).toString()};
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('embark.Compiler', function() {
|
describe('embark.Compiler', function() {
|
||||||
var compiler = new Compiler({logger: new TestLogger({})});
|
let compiler = new Compiler({logger: new TestLogger({})});
|
||||||
|
|
||||||
describe('#compile_solidity', function() {
|
describe('#compile_solidity', function() {
|
||||||
this.timeout(0);
|
this.timeout(0);
|
||||||
|
|
||||||
var expectedObject = {};
|
let expectedObject = {};
|
||||||
|
|
||||||
expectedObject["SimpleStorage"] = {"code":"606060405234610000576040516020806100f083398101604052515b60008190555b505b60bf806100316000396000f300606060405263ffffffff60e060020a6000350416632a1afcd98114603657806360fe47b11460525780636d4ce63c146061575b6000565b346000576040607d565b60408051918252519081900360200190f35b34600057605f6004356083565b005b346000576040608c565b60408051918252519081900360200190f35b60005481565b60008190555b50565b6000545b905600a165627a7a72305820a250be048d43f54e9afbb37211dc73ba843d23b95863b60afe703903500077220029","realRuntimeBytecode": "606060405263ffffffff60e060020a6000350416632a1afcd98114603657806360fe47b11460525780636d4ce63c146061575b6000565b346000576040607d565b60408051918252519081900360200190f35b34600057605f6004356083565b005b346000576040608c565b60408051918252519081900360200190f35b60005481565b60008190555b50565b6000545b905600a165627a7a72305820","runtimeBytecode":"606060405263ffffffff60e060020a6000350416632a1afcd98114603657806360fe47b11460525780636d4ce63c146061575b6000565b346000576040607d565b60408051918252519081900360200190f35b34600057605f6004356083565b005b346000576040608c565b60408051918252519081900360200190f35b60005481565b60008190555b50565b6000545b905600a165627a7a72305820a250be048d43f54e9afbb37211dc73ba843d23b95863b60afe703903500077220029","swarmHash": "a250be048d43f54e9afbb37211dc73ba843d23b95863b60afe70390350007722","gasEstimates":{"creation":[20131,38200],"external":{"get()":269,"set(uint256)":20163,"storedData()":224},"internal":{}},"functionHashes":{"get()":"6d4ce63c","set(uint256)":"60fe47b1","storedData()":"2a1afcd9"},"abiDefinition":[{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"payable":false,"type":"constructor"}]};
|
expectedObject["SimpleStorage"] = {"code":"606060405234610000576040516020806100f083398101604052515b60008190555b505b60bf806100316000396000f300606060405263ffffffff60e060020a6000350416632a1afcd98114603657806360fe47b11460525780636d4ce63c146061575b6000565b346000576040607d565b60408051918252519081900360200190f35b34600057605f6004356083565b005b346000576040608c565b60408051918252519081900360200190f35b60005481565b60008190555b50565b6000545b905600a165627a7a72305820a250be048d43f54e9afbb37211dc73ba843d23b95863b60afe703903500077220029","realRuntimeBytecode": "606060405263ffffffff60e060020a6000350416632a1afcd98114603657806360fe47b11460525780636d4ce63c146061575b6000565b346000576040607d565b60408051918252519081900360200190f35b34600057605f6004356083565b005b346000576040608c565b60408051918252519081900360200190f35b60005481565b60008190555b50565b6000545b905600a165627a7a72305820","runtimeBytecode":"606060405263ffffffff60e060020a6000350416632a1afcd98114603657806360fe47b11460525780636d4ce63c146061575b6000565b346000576040607d565b60408051918252519081900360200190f35b34600057605f6004356083565b005b346000576040608c565b60408051918252519081900360200190f35b60005481565b60008190555b50565b6000545b905600a165627a7a72305820a250be048d43f54e9afbb37211dc73ba843d23b95863b60afe703903500077220029","swarmHash": "a250be048d43f54e9afbb37211dc73ba843d23b95863b60afe70390350007722","gasEstimates":{"creation":[20131,38200],"external":{"get()":269,"set(uint256)":20163,"storedData()":224},"internal":{}},"functionHashes":{"get()":"6d4ce63c","set(uint256)":"60fe47b1","storedData()":"2a1afcd9"},"abiDefinition":[{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"payable":false,"type":"constructor"}]};
|
||||||
|
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
/*globals describe, it*/
|
/*globals describe, it*/
|
||||||
var Config = require('../lib/core/config.js');
|
let Config = require('../lib/core/config.js');
|
||||||
var Plugins = require('../lib/core/plugins.js');
|
let Plugins = require('../lib/core/plugins.js');
|
||||||
var assert = require('assert');
|
let assert = require('assert');
|
||||||
var fs = require('fs');
|
|
||||||
|
|
||||||
describe('embark.Config', function() {
|
describe('embark.Config', function() {
|
||||||
var config = new Config({
|
let config = new Config({
|
||||||
env: 'myenv',
|
env: 'myenv',
|
||||||
configDir: './test/test1/config/'
|
configDir: './test/test1/config/'
|
||||||
});
|
});
|
||||||
@ -14,7 +13,7 @@ describe('embark.Config', function() {
|
|||||||
describe('#loadBlockchainConfigFile', function() {
|
describe('#loadBlockchainConfigFile', function() {
|
||||||
it('should load blockchain config correctly', function() {
|
it('should load blockchain config correctly', function() {
|
||||||
config.loadBlockchainConfigFile();
|
config.loadBlockchainConfigFile();
|
||||||
var expectedConfig = {
|
let expectedConfig = {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"networkType": "custom",
|
"networkType": "custom",
|
||||||
"genesisBlock": "config/development/genesis.json",
|
"genesisBlock": "config/development/genesis.json",
|
||||||
@ -36,7 +35,7 @@ describe('embark.Config', function() {
|
|||||||
describe('#loadContractsConfigFile', function() {
|
describe('#loadContractsConfigFile', function() {
|
||||||
it('should load contract config correctly', function() {
|
it('should load contract config correctly', function() {
|
||||||
config.loadContractsConfigFile();
|
config.loadContractsConfigFile();
|
||||||
var expectedConfig = {
|
let expectedConfig = {
|
||||||
"gas": "auto",
|
"gas": "auto",
|
||||||
"contracts": {
|
"contracts": {
|
||||||
"SimpleStorage": {
|
"SimpleStorage": {
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
/*globals describe, it*/
|
/*globals describe, it*/
|
||||||
var Console = require('../lib/dashboard/console.js');
|
let Console = require('../lib/dashboard/console.js');
|
||||||
var Plugins = require('../lib/core/plugins.js');
|
let Plugins = require('../lib/core/plugins.js');
|
||||||
var assert = require('assert');
|
let assert = require('assert');
|
||||||
var version = require('../package.json').version;
|
let version = require('../package.json').version;
|
||||||
|
|
||||||
describe('embark.Console', function() {
|
describe('embark.Console', function() {
|
||||||
var plugins = new Plugins({plugins: {}});
|
let plugins = new Plugins({plugins: {}});
|
||||||
var console = new Console({plugins: plugins, version: version});
|
let console = new Console({plugins: plugins, version: version});
|
||||||
|
|
||||||
describe('#executeCmd', function() {
|
describe('#executeCmd', function() {
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ describe('embark.Console', function() {
|
|||||||
|
|
||||||
it('it should provide a help text', function(done) {
|
it('it should provide a help text', function(done) {
|
||||||
console.executeCmd('help', function(output) {
|
console.executeCmd('help', function(output) {
|
||||||
var lines = output.split('\n');
|
let lines = output.split('\n');
|
||||||
assert.equal(lines[0], 'Welcome to Embark ' + version);
|
assert.equal(lines[0], 'Welcome to Embark ' + version);
|
||||||
assert.equal(lines[2], 'possible commands are:');
|
assert.equal(lines[2], 'possible commands are:');
|
||||||
done();
|
done();
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/*globals describe, it*/
|
/*globals describe, it*/
|
||||||
var ContractsManager = require('../lib/contracts/contracts.js');
|
let ContractsManager = require('../lib/contracts/contracts.js');
|
||||||
var Logger = require('../lib/core/logger.js');
|
let Logger = require('../lib/core/logger.js');
|
||||||
var assert = require('assert');
|
let assert = require('assert');
|
||||||
var fs = require('fs');
|
let fs = require('fs');
|
||||||
|
|
||||||
var readFile = function(file) {
|
let readFile = function(file) {
|
||||||
return {filename: file, content: fs.readFileSync(file).toString()};
|
return {filename: file, content: fs.readFileSync(file).toString()};
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('embark.Contratcs', function() {
|
describe('embark.Contratcs', function() {
|
||||||
|
this.timeout(0);
|
||||||
describe('simple', function() {
|
describe('simple', function() {
|
||||||
var contractsManager = new ContractsManager({
|
let contractsManager = new ContractsManager({
|
||||||
contractFiles: [
|
contractFiles: [
|
||||||
readFile('test/contracts/simple_storage.sol'),
|
readFile('test/contracts/simple_storage.sol'),
|
||||||
readFile('test/contracts/token.sol')
|
readFile('test/contracts/token.sol')
|
||||||
@ -41,7 +41,7 @@ describe('embark.Contratcs', function() {
|
|||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
var contracts = contractsManager.listContracts();
|
let contracts = contractsManager.listContracts();
|
||||||
assert.equal(contracts.length, 2);
|
assert.equal(contracts.length, 2);
|
||||||
|
|
||||||
assert.equal(contracts[0].deploy, true);
|
assert.equal(contracts[0].deploy, true);
|
||||||
@ -70,7 +70,7 @@ describe('embark.Contratcs', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('config with contract instances', function() {
|
describe('config with contract instances', function() {
|
||||||
var contractsManager = new ContractsManager({
|
let contractsManager = new ContractsManager({
|
||||||
contractFiles: [
|
contractFiles: [
|
||||||
readFile('test/contracts/simple_storage.sol'),
|
readFile('test/contracts/simple_storage.sol'),
|
||||||
readFile('test/contracts/token_storage.sol')
|
readFile('test/contracts/token_storage.sol')
|
||||||
@ -110,7 +110,7 @@ describe('embark.Contratcs', function() {
|
|||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
var contracts = contractsManager.listContracts();
|
let contracts = contractsManager.listContracts();
|
||||||
assert.equal(contracts.length, 4);
|
assert.equal(contracts.length, 4);
|
||||||
|
|
||||||
assert.equal(contracts[0].className, "MySimpleStorage");
|
assert.equal(contracts[0].className, "MySimpleStorage");
|
||||||
@ -127,7 +127,7 @@ describe('embark.Contratcs', function() {
|
|||||||
//assert.equal(contracts[3].code, '');
|
//assert.equal(contracts[3].code, '');
|
||||||
//assert.equal(contracts[3].runtimeBytecode, '');
|
//assert.equal(contracts[3].runtimeBytecode, '');
|
||||||
|
|
||||||
var parentContract = contracts[2];
|
let parentContract = contracts[2];
|
||||||
|
|
||||||
//MySimpleStorage
|
//MySimpleStorage
|
||||||
assert.equal(contracts[0].deploy, true);
|
assert.equal(contracts[0].deploy, true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user