Skip to content

Commit

Permalink
Merge pull request #28 from Adamant-im/dev
Browse files Browse the repository at this point in the history
Release 0.5.0
  • Loading branch information
zyuhel authored Jan 30, 2019
2 parents 3e8b582 + 815da23 commit a552315
Show file tree
Hide file tree
Showing 26 changed files with 1,711 additions and 149 deletions.
34 changes: 34 additions & 0 deletions api/http/chatrooms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

const Router = require('../../helpers/router');
const httpApi = require('../../helpers/httpApi');

/**
* Binds api with modules and creates common url.
* - End point: `/api/chatrooms`
*
* - Sanitized
* - get /:ID
* - get /:ID/:ID
* @memberof module:chatrooms
* @requires helpers/Router
* @requires helpers/httpApi
* @constructor
* @param {Object} chatroomsModule - Module chats instance.
* @param {scope} app - Network app.
*/
// Constructor
function ChatroomsHttpApi (chatroomsModule, app) {

const router = new Router();

router.map(chatroomsModule.internal, {
'get /U*/U*': 'getMessages',
'get /U*': 'getChats',
});


httpApi.registerEndpoint('/api/chatrooms', app, router, chatroomsModule.isLoaded);
}

module.exports = ChatroomsHttpApi;
32 changes: 32 additions & 0 deletions api/http/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

var Router = require('../../helpers/router');
var httpApi = require('../../helpers/httpApi');
var schema = require('../../schema/node.js');

/**
* Binds api with modules and creates common url.
* - End point: `/api/node`
* - Public API:
- get /status
* @memberof module:node
* @requires helpers/Router
* @requires helpers/httpApi
* @constructor
* @param {Object} nodeModule - Module node instance.
* @param {scope} app - Network app.
*/

function NodeHttpApi (nodeModule, app) {

var router = new Router();

router.map(nodeModule.shared, {
'get /status': 'getStatus',
});


httpApi.registerEndpoint('/api/node', app, router, nodeModule.isLoaded);
}

module.exports = NodeHttpApi;
108 changes: 74 additions & 34 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ var httpApi = require('./helpers/httpApi.js');
var Sequence = require('./helpers/sequence.js');
var util = require('util');
var z_schema = require('./helpers/z_schema.js');

process.stdin.resume();

var versionBuild = fs.readFileSync(path.join(__dirname, 'build'), 'utf8');
Expand All @@ -51,7 +50,7 @@ var lastCommit = '';

if (typeof gc !== 'undefined') {
setInterval(function () {
// eslint-disable-next-line no-undef
// eslint-disable-next-line no-undef
gc();
}, 60000);
}
Expand Down Expand Up @@ -138,7 +137,10 @@ var config = {
multisignatures: './modules/multisignatures.js',
dapps: './modules/dapps.js',
chats: './modules/chats.js',
chatrooms: './modules/chatrooms.js',
states: './modules/states.js',
node: './modules/node.js',
chats: './modules/chats.js',
crypto: './modules/crypto.js',
sql: './modules/sql.js',
cache: './modules/cache.js'
Expand All @@ -148,7 +150,9 @@ var config = {
blocks: { http: './api/http/blocks.js' },
dapps: { http: './api/http/dapps.js' },
chats: { http: './api/http/chats.js' },
chatrooms: { http: './api/http/chatrooms.js' },
states: { http: './api/http/states.js' },
node: { http: './api/http/node.js' },
delegates: { http: './api/http/delegates.js' },
loader: { http: './api/http/loader.js' },
multisignatures: { http: './api/http/multisignatures.js' },
Expand All @@ -165,8 +169,11 @@ var config = {
* The Object is initialized here and pass to others as parameter.
* @property {object} - Logger instance.
*/
var logger = new Logger({ echo: appConfig.consoleLogLevel, errorLevel: appConfig.fileLogLevel,
filename: appConfig.logFileName });
var logger = new Logger({
echo: appConfig.consoleLogLevel,
errorLevel: appConfig.fileLogLevel,
filename: appConfig.logFileName
});

// Trying to get last git commit
try {
Expand All @@ -182,7 +189,10 @@ try {
var d = require('domain').create();

d.on('error', function (err) {
logger.fatal('Domain master', { message: err.message, stack: err.stack });
logger.fatal('Domain master', {
message: err.message,
stack: err.stack
});
process.exit(0);
});

Expand Down Expand Up @@ -219,13 +229,11 @@ d.run(function () {
}

fs.writeFileSync('./config.json', JSON.stringify(appConfig, null, 4));

cb(null, appConfig);
} else {
cb(null, appConfig);
}
},

logger: function (cb) {
cb(null, logger);
},
Expand All @@ -248,15 +256,28 @@ d.run(function () {
block: genesisblock
});
},

public: function (cb) {
packageJson: function (cb) {
cb(null, packageJson);
},
public: function (cb) {
cb(null, path.join(__dirname, 'public'));
},

schema: function (cb) {
cb(null, new z_schema());
},

/**
* ws client PWA,
* @method clientWs
* @param {object} wsconfig - config from ws client PWA,
* @param {nodeStyleCallback} cb - Callback function with created Method:
* `emit`.
*/
clientWs: ['config', function (scope, cb) {
var ClientWs = require('./modules/clientWs');
cb(null, new ClientWs(scope.config.wsClient, logger));
}],
/**
* Once config is completed, creates app, http & https servers & sockets with express.
* @method network
Expand All @@ -280,7 +301,9 @@ d.run(function () {

require('./helpers/request-limiter')(app, appConfig);

app.use(compression({ level: 9 }));
app.use(compression({
level: 9
}));
app.use(cors());
app.options('*', cors());

Expand Down Expand Up @@ -360,9 +383,17 @@ d.run(function () {
scope.network.app.set('view engine', 'ejs');
scope.network.app.set('views', path.join(__dirname, 'public'));
scope.network.app.use(scope.network.express.static(path.join(__dirname, 'public')));
scope.network.app.use(bodyParser.raw({limit: '2mb'}));
scope.network.app.use(bodyParser.urlencoded({extended: true, limit: '2mb', parameterLimit: 5000}));
scope.network.app.use(bodyParser.json({limit: '2mb'}));
scope.network.app.use(bodyParser.raw({
limit: '2mb'
}));
scope.network.app.use(bodyParser.urlencoded({
extended: true,
limit: '2mb',
parameterLimit: 5000
}));
scope.network.app.use(bodyParser.json({
limit: '2mb'
}));
scope.network.app.use(methodOverride());

var ignore = ['id', 'name', 'lastBlockId', 'blockId', 'transactionId', 'address', 'recipientId', 'senderId', 'previousBlock'];
Expand Down Expand Up @@ -412,9 +443,9 @@ d.run(function () {
ed: function (cb) {
cb(null, require('./helpers/ed.js'));
},
accounts: function (cb) {
cb(null, require('./helpers/accounts.js'));
},
accounts: function (cb) {
cb(null, require('./helpers/accounts.js'));
},
bus: ['ed', function (scope, cb) {
var changeCase = require('change-case');
var bus = function () {
Expand All @@ -426,12 +457,12 @@ d.run(function () {

// executes the each module onBind function
modules.forEach(function (module) {
if (typeof(module[eventName]) === 'function') {
if (typeof (module[eventName]) === 'function') {
module[eventName].apply(module[eventName], args);
}
if (module.submodules) {
async.each(module.submodules, function (submodule) {
if (submodule && typeof(submodule[eventName]) === 'function') {
if (submodule && typeof (submodule[eventName]) === 'function') {
submodule[eventName].apply(submodule[eventName], args);
}
});
Expand Down Expand Up @@ -460,11 +491,11 @@ d.run(function () {
* @param {object} scope - The results from current execution,
* at leats will contain the required elements.
* @param {function} cb - Callback function.
*/
*/
logic: ['db', 'bus', 'schema', 'genesisblock', function (scope, cb) {
var Transaction = require('./logic/transaction.js');
var Chat = require('./logic/chat.js');
var State = require('./logic/state.js');
var Chat = require('./logic/chat.js');
var State = require('./logic/state.js');
var Block = require('./logic/block.js');
var Account = require('./logic/account.js');
var Peers = require('./logic/peers.js');
Expand All @@ -490,18 +521,21 @@ d.run(function () {
block: genesisblock
});
},
clientWs: function (cb) {
cb(null, scope.clientWs);
},
account: ['db', 'bus', 'ed', 'schema', 'genesisblock', 'logger', function (scope, cb) {
new Account(scope.db, scope.schema, scope.logger, cb);
}],
transaction: ['db', 'bus', 'ed', 'schema', 'genesisblock', 'account', 'logger', function (scope, cb) {
new Transaction(scope.db, scope.ed, scope.schema, scope.genesisblock, scope.account, scope.logger, cb);
transaction: ['db', 'bus', 'ed', 'schema', 'genesisblock', 'account', 'logger', 'clientWs', function (scope, cb) {
new Transaction(scope.db, scope.ed, scope.schema, scope.genesisblock, scope.account, scope.logger, scope.clientWs, cb);
}],
chat: ['db', 'bus', 'ed', 'schema', 'account', 'logger', function (scope, cb) {
new Chat(scope.db, scope.ed, scope.schema, scope.account, scope.logger, cb);
}],
state: ['db', 'bus', 'ed', 'schema', 'account', 'logger', function (scope, cb) {
new State(scope.db, scope.ed, scope.schema, scope.account, scope.logger, cb);
}],
chat: ['db', 'bus', 'ed', 'schema', 'account', 'logger', function (scope, cb) {
new Chat(scope.db, scope.ed, scope.schema, scope.account, scope.logger, cb);
}],
state: ['db', 'bus', 'ed', 'schema', 'account', 'logger', function (scope, cb) {
new State(scope.db, scope.ed, scope.schema, scope.account, scope.logger, cb);
}],
block: ['db', 'bus', 'ed', 'schema', 'genesisblock', 'account', 'transaction', function (scope, cb) {
new Block(scope.ed, scope.schema, scope.transaction, cb);
}],
Expand All @@ -528,7 +562,10 @@ d.run(function () {
var d = require('domain').create();

d.on('error', function (err) {
scope.logger.fatal('Domain ' + name, {message: err.message, stack: err.stack});
scope.logger.fatal('Domain ' + name, {
message: err.message,
stack: err.stack
});
});

d.run(function () {
Expand All @@ -552,7 +589,7 @@ d.run(function () {
* @param {object} scope - The results from current execution,
* at leats will contain the required elements.
* @param {function} cb - Callback function.
*/
*/
api: ['modules', 'logger', 'network', function (scope, cb) {
Object.keys(config.api).forEach(function (moduleName) {
Object.keys(config.api[moduleName]).forEach(function (protocol) {
Expand Down Expand Up @@ -648,7 +685,7 @@ d.run(function () {
process.once('cleanup', function () {
scope.logger.info('Cleaning up...');
async.eachSeries(modules, function (module, cb) {
if (typeof(module.cleanup) === 'function') {
if (typeof (module.cleanup) === 'function') {
module.cleanup(cb);
} else {
setImmediate(cb);
Expand Down Expand Up @@ -724,10 +761,13 @@ d.run(function () {
*/
process.on('uncaughtException', function (err) {
// Handle error safely
logger.fatal('System error', { message: err.message, stack: err.stack });
logger.fatal('System error', {
message: err.message,
stack: err.stack
});
/**
* emits cleanup once 'uncaughtException'.
* @emits cleanup
*/
process.emit('cleanup');
});
});
14 changes: 9 additions & 5 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"port": 36666,
"address": "0.0.0.0",
"version": "0.4.2",
"minVersion": ">=0.4.0",
"fileLogLevel": "info",
"logFileName": "logs/adamant.log",
"consoleLogLevel": "none",
Expand Down Expand Up @@ -32,7 +30,9 @@
"enabled": true,
"access": {
"public": false,
"whiteList": ["127.0.0.1"]
"whiteList": [
"127.0.0.1"
]
},
"options": {
"limits": {
Expand Down Expand Up @@ -106,8 +106,12 @@
},
"dapp": {
"masterrequired": true,
"masterpassword": "",
"masterpassword": "rJ1T2sZH3cLU",
"autoexec": []
},
"wsClient": {
"portWS": 36668,
"enabled": true
},
"nethash": "bd330166898377fb28743ceef5e43a5d9d0a3efd9b3451fb7bc53530bb0a6d64"
}
}
Loading

0 comments on commit a552315

Please sign in to comment.