feat(plugins): support for idVerifier added; more plugin struct checks
This commit is contained in:
parent
1aacec9df2
commit
609e414535
1 changed files with 27 additions and 4 deletions
|
|
@ -40,14 +40,18 @@ exports.init = function init(databaseHandle) {
|
|||
|
||||
|
||||
function loadPlugin(name, config) {
|
||||
|
||||
// plugins definitions
|
||||
var moduleMethods = {
|
||||
ticker: [ 'ticker' ],
|
||||
trader: [ 'balance', 'purchase', 'sell' ],
|
||||
wallet: [ 'balance', 'sendBitcoins' ]
|
||||
wallet: [ 'balance', 'sendBitcoins' ],
|
||||
idVerifier: [ 'verifyUser', 'verifyTransaction' ]
|
||||
};
|
||||
|
||||
var plugin = null;
|
||||
|
||||
// each used plugin MUST be installed
|
||||
try {
|
||||
plugin = require('lamassu-' + name);
|
||||
|
||||
|
|
@ -55,6 +59,16 @@ function loadPlugin(name, config) {
|
|||
throw new Error(name + ' module is not installed. Try running \'npm install --save lamassu-' + name + '\' first');
|
||||
}
|
||||
|
||||
|
||||
// each plugin MUST implement those
|
||||
if (typeof plugin.SUPPORTED_MODULES !== 'undefined') {
|
||||
if(plugin.SUPPORTED_MODULES === 'string')
|
||||
plugin.SUPPORTED_MODULES = [plugin.SUPPORTED_MODULES];
|
||||
|
||||
if(!(plugin.SUPPORTED_MODULES instanceof Array))
|
||||
throw new Error('\'' + name + '\' fails to implement *required* \'SUPPORTED_MODULES\' constant');
|
||||
}
|
||||
|
||||
plugin.SUPPORTED_MODULES.forEach(function(moduleName) {
|
||||
moduleMethods[moduleName].forEach(function(methodName) {
|
||||
if (typeof plugin[methodName] !== 'function') {
|
||||
|
|
@ -63,9 +77,18 @@ function loadPlugin(name, config) {
|
|||
});
|
||||
});
|
||||
|
||||
if (config !== null) {
|
||||
plugin.config(config);
|
||||
}
|
||||
|
||||
// each plugin SHOULD implement those
|
||||
if (typeof plugin.NAME === 'undefined')
|
||||
logger.warn(new Error('\'' + name + '\' fails to implement *recommended* \'NAME\' field'));
|
||||
|
||||
if (typeof plugin.config !== 'function') {
|
||||
logger.warn(new Error('\'' + name + '\' fails to implement *recommended* \'config\' method'));
|
||||
plugin.config = function() {};
|
||||
|
||||
} else if (config !== null)
|
||||
plugin.config(config); // only when plugin supports it, and config is passed
|
||||
|
||||
|
||||
return plugin;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue