Skip to content

Commit

Permalink
Add preliminary plugin support
Browse files Browse the repository at this point in the history
-Plugins can now be enabled via settings.json after dropping the plugin files into the new plugins directory
-Enabling plugins will allow extending the normal functionality of the explorer with new database collections, menus, pages and apis + open up a new url for data to be sent from the plugin to the explorer
-A new plugins section was added to the settings with a definition for the generic-snapshots plugin
-Locale strings are now loaded and shared out via the settings so there is generally no more need to explicitly include the locale.js file
-The locale object has been updated to localization within the explorer
-A number of new locale strings have been added and their values replaced with the locale string within the explorer
-Added plugin support verbiage and a link to the generic-snapshots crowdfunding task to the README
  • Loading branch information
joeuhren committed Jun 17, 2024
1 parent 7ebdb5e commit 7884540
Show file tree
Hide file tree
Showing 35 changed files with 1,213 additions and 745 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Written in node.js and mongodb, eIquidus is the most stable, secure, customizabl

Exor accepts targeted donations in an effort to crowdfund various feature and improvement requests for the block explorer and other Exor-related projects. [Browse the list of unfunded tasks](https://exor.io/tasklist/hide-completed/hide-funded/show-unfunded/) and send Exor coins to the correct funding address to help meet the funding goal for tasks that you would like to see developed. Once the funding goal is met, Exor developers will begin work on the task asap and will remain a top priority until completed. If you are a software developer and would like to work on funded tasks in exchange for payment in EXOR, please get in touch with us using one of the [Developer Contact](#developer-contact) links below.

**NEW:** Preliminary plugin support has been added. Help support the first plugin proposal for automatic snapshot creation. More info: [https://exor.io/task/181/b371d98f6217f2f533b3a0c9fedce7b200571c4f/](https://exor.io/task/181/b371d98f6217f2f533b3a0c9fedce7b200571c4f/)

### Premium Support

All code in this project is open source and available free-of-charge under the BSD-3-Clause license. If you require assistance setting up an explorer for your coin, or are interested in hiring a developer to incorporate custom changes for your explorer, you may contact the developer using the [Developer Contact](#developer-contact) links below.
Expand Down Expand Up @@ -980,7 +982,7 @@ You can support us via one of the following options:

### License

Copyright (c) 2019-2023, The Exor Community<br />
Copyright (c) 2019-2024, The Exor Community<br />
Copyright (c) 2017, The Chaincoin Community<br />
Copyright (c) 2015, Iquidus Technology<br />
Copyright (c) 2015, Luke Williams<br />
Expand Down
226 changes: 204 additions & 22 deletions app.js

Large diffs are not rendered by default.

94 changes: 79 additions & 15 deletions lib/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ var mongoose = require('mongoose'),
ClaimAddress = require('../models/claimaddress'),
lib = require('./explorer'),
settings = require('./settings'),
locale = require('./locale'),
fs = require('fs');

function find_address(hash, caseSensitive, cb) {
Expand Down Expand Up @@ -130,7 +129,7 @@ function get_market_data(market, coin_symbol, pair_symbol, cb) {
if (fs.existsSync('./lib/markets/' + market + '.js')) {
exMarket = require('./markets/' + market);

exMarket.get_data({coin: coin_symbol, exchange: pair_symbol, api_error_msg: locale.mkt_unexpected_api_data}, function(err, obj) {
exMarket.get_data({coin: coin_symbol, exchange: pair_symbol, api_error_msg: settings.localization.mkt_unexpected_api_data}, function(err, obj) {
return cb(err, obj);
});
} else
Expand Down Expand Up @@ -248,7 +247,7 @@ function init_markets(cb) {
// check if exchange trading pair exists in the market collection
if (!exists) {
// exchange doesn't exist in the market collection so add a default definition now
console.log('No %s[%s] entry found. Creating new entry now..', market, split_pair[0] + '/' + split_pair[1]);
console.log(`${settings.localization.creating_initial_entry.replace('{1}', `${market}[${split_pair[0]}/${split_pair[1]}]`)}.. ${settings.localization.please_wait}..`);

module.exports.create_market(split_pair[0], split_pair[1], market, function() {
pairCounter++;
Expand Down Expand Up @@ -343,7 +342,7 @@ function init_heavy(cb) {
if (settings.blockchain_specific.heavycoin.enabled == true) {
module.exports.check_heavy(settings.coin.name, function(exists) {
if (exists == false) {
console.log('No heavycoin entry found. Creating new entry now..');
console.log(`${settings.localization.creating_initial_entry.replace('{1}', 'heavycoin')}.. ${settings.localization.please_wait}..`);
module.exports.create_heavy(settings.coin.name, function() {
return cb();
});
Expand Down Expand Up @@ -412,6 +411,68 @@ function init_claimaddress(coin, cb) {
});
}

function init_plugins(coin, cb) {
// check if there are any defined plugins in the settings
if (settings.plugins.allowed_plugins != null && settings.plugins.allowed_plugins.length > 0) {
let checkedPlugins = 0;

// loop through all plugins defined in the settings
settings.plugins.allowed_plugins.forEach(function (plugin) {
// check if this plugin is enabled
if (!plugin.enabled) {
checkedPlugins++;

if (checkedPlugins == settings.plugins.allowed_plugins.length)
return cb();
} else {
const pluginName = (plugin.plugin_name == null ? '' : plugin.plugin_name);

// check if the plugin exists in the plugins directory
if (!fs.existsSync(`./plugins/${pluginName}`)) {
console.log(`WARNING: Plugin '${pluginName}' is not installed in the plugins directory`);

checkedPlugins++;

if (checkedPlugins == settings.plugins.allowed_plugins.length)
return cb();
} else {
// check if the plugin's server_functions file exists
if (!fs.existsSync(`./plugins/${pluginName}/lib/server_functions.js`)) {
console.log(`WARNING: Plugin '${pluginName}' is missing the /lib/server_functions.js file`);

checkedPlugins++;

if (checkedPlugins == settings.plugins.allowed_plugins.length)
return cb();
} else {
// load the server_functions.js file from the plugin
const serverFunctions = require(`../plugins/${pluginName}/lib/server_functions`);

// check if the plugin_load function exists
if (typeof serverFunctions.plugin_load !== 'function') {
console.log(`WARNING: Plugin '${pluginName}' is missing the plugin_load function`);

checkedPlugins++;

if (checkedPlugins == settings.plugins.allowed_plugins.length)
return cb();
} else {
// call the plugin_load function to initialize the plugin
serverFunctions.plugin_load(coin, function() {
checkedPlugins++;

if (checkedPlugins == settings.plugins.allowed_plugins.length)
return cb();
});
}
}
}
}
});
} else
return cb();
}

// find masternode by txid and
function find_masternode(txhash, addr, cb) {
Masternode.findOne({ txhash: txhash, addr: addr }).then((masternode) => {
Expand Down Expand Up @@ -660,7 +721,7 @@ module.exports = {
});

newStats.save().then(() => {
console.log("Initial stats entry created for %s", coin);
console.log(`${settings.localization.entry_created_successfully.replace('{1}', 'stats').replace('{2}', coin)}`);
return cb();
}).catch((err) => {
console.log(err);
Expand Down Expand Up @@ -1014,7 +1075,7 @@ module.exports = {
});

newMarkets.save().then(() => {
console.log("Initial market entry created for %s[%s]", market, coin_symbol + '/' + pair_symbol);
console.log(`${settings.localization.entry_created_successfully.replace('{1}', 'market').replace('{2}', `${market}[${coin_symbol}/${pair_symbol}]`)}`);
return cb();
}).catch((err) => {
console.log(err);
Expand Down Expand Up @@ -1054,7 +1115,7 @@ module.exports = {
});

newRichlist.save().then(() => {
console.log("Initial richlist entry created for %s", coin);
console.log(`${settings.localization.entry_created_successfully.replace('{1}', 'richlist').replace('{2}', coin)}`);
return cb();
}).catch((err) => {
console.log(err);
Expand Down Expand Up @@ -1096,7 +1157,7 @@ module.exports = {
});

newHeavy.save().then(() => {
console.log("Initial heavycoin entry created for %s", coin);
console.log(`${settings.localization.entry_created_successfully.replace('{1}', 'heavycoin').replace('{2}', coin)}`);
return cb();
}).catch((err) => {
console.log(err);
Expand Down Expand Up @@ -1879,15 +1940,15 @@ module.exports = {
},

initialize_data_startup: function(cb) {
console.log('Initializing database.. Please wait...');
console.log(`${settings.localization.initializing_database}.. ${settings.localization.please_wait}..`);

// check if stats collection is initialized
module.exports.check_stats(settings.coin.name, function(stats_exists) {
var skip = true;

// determine if stats collection already exists
if (stats_exists == false) {
console.log('No stats entry found. Creating new entry now..');
console.log(`${settings.localization.creating_initial_entry.replace('{1}', 'stats')}.. ${settings.localization.please_wait}..`);
skip = false;
}

Expand All @@ -1909,7 +1970,7 @@ module.exports = {

// determine if richlist collection already exists
if (richlist_exists == false) {
console.log('No richlist entry found. Creating new entry now..');
console.log(`${settings.localization.creating_initial_entry.replace('{1}', 'richlist')}.. ${settings.localization.please_wait}..`);
skip = false;
}

Expand All @@ -1919,9 +1980,12 @@ module.exports = {
init_heavy(function() {
// check and initialize the claimaddress collection
init_claimaddress(settings.coin.name, function() {
// finished initializing startup data
console.log('Database initialization complete');
return cb();
// initialize all enabled plugins
init_plugins(settings.coin.name, function() {
// finished initializing startup data
console.log('Database initialization complete');
return cb();
});
});
});
});
Expand Down Expand Up @@ -1951,7 +2015,7 @@ module.exports = {

save_tx: function(txid, blockheight, block, cb) {
lib.get_rawtransaction(txid, function(tx) {
if (tx && tx != 'There was an error. Check your console.') {
if (tx && tx != `${settings.localization.ex_error}: ${settings.localization.check_console}`) {
lib.prepare_vin(tx, function(vin, tx_type_vin) {
lib.prepare_vout(tx.vout, txid, vin, ((!settings.blockchain_specific.zksnarks.enabled || typeof tx.vjoinsplit === 'undefined' || tx.vjoinsplit == null) ? [] : tx.vjoinsplit), function(vout, nvin, tx_type_vout) {
lib.syncLoop(nvin.length, function (loop) {
Expand Down
Loading

0 comments on commit 7884540

Please sign in to comment.