88 lines
2.3 KiB
JavaScript
88 lines
2.3 KiB
JavaScript
function getLegacySoloBackend() {
|
|
return {
|
|
name: 'solo',
|
|
type: 'solo',
|
|
host: (config.miningSource && config.miningSource.host) || config.daemon.host,
|
|
port: (config.miningSource && config.miningSource.port) || config.daemon.port,
|
|
alwaysPoll: (config.miningSource && config.miningSource.alwaysPoll) || config.daemon.alwaysPoll || false,
|
|
walletAddress: null
|
|
};
|
|
}
|
|
|
|
function getConfiguredBackends() {
|
|
if (!config.mining || !config.mining.backends) {
|
|
return null;
|
|
}
|
|
return config.mining.backends;
|
|
}
|
|
|
|
function getActiveBackendName(backends) {
|
|
if (config.mining && config.mining.active) {
|
|
return config.mining.active;
|
|
}
|
|
|
|
let enabled = Object.keys(backends).filter(function (name) {
|
|
return backends[name] && backends[name].enabled;
|
|
});
|
|
|
|
if (enabled.length === 0) {
|
|
throw new Error('No enabled mining backend configured');
|
|
}
|
|
|
|
return enabled[0];
|
|
}
|
|
|
|
function normalizeBackend(name, backend) {
|
|
return {
|
|
name: name,
|
|
type: backend.type || (name === 'solo' ? 'solo' : 'merge-mining'),
|
|
parentCoin: backend.parentCoin || null,
|
|
host: backend.host,
|
|
port: backend.port,
|
|
alwaysPoll: backend.alwaysPoll || false,
|
|
walletAddress: backend.walletAddress || null
|
|
};
|
|
}
|
|
|
|
function getActiveMiningBackend() {
|
|
let backends = getConfiguredBackends();
|
|
if (!backends) {
|
|
return getLegacySoloBackend();
|
|
}
|
|
|
|
let activeName = getActiveBackendName(backends);
|
|
let backend = backends[activeName];
|
|
if (!backend) {
|
|
throw new Error('Active mining backend "' + activeName + '" is not defined');
|
|
}
|
|
if (!backend.enabled) {
|
|
throw new Error('Active mining backend "' + activeName + '" is disabled');
|
|
}
|
|
if (!backend.host || !backend.port) {
|
|
throw new Error('Active mining backend "' + activeName + '" is missing host/port');
|
|
}
|
|
|
|
return normalizeBackend(activeName, backend);
|
|
}
|
|
exports.getActiveMiningBackend = getActiveMiningBackend;
|
|
|
|
function getMiningRpcConfig() {
|
|
let backend = getActiveMiningBackend();
|
|
return {
|
|
host: backend.host,
|
|
port: backend.port
|
|
};
|
|
}
|
|
exports.getMiningRpcConfig = getMiningRpcConfig;
|
|
|
|
function getMiningTemplateAddress(defaultAddress) {
|
|
let backend = getActiveMiningBackend();
|
|
return backend.walletAddress || defaultAddress;
|
|
}
|
|
exports.getMiningTemplateAddress = getMiningTemplateAddress;
|
|
|
|
function isSoloMiningBackend() {
|
|
return getActiveMiningBackend().type === 'solo';
|
|
}
|
|
exports.isSoloMiningBackend = isSoloMiningBackend;
|