Add selectable solo and MM mining backends
Some checks failed
CodeQL / Analyze (javascript) (push) Failing after 36s

This commit is contained in:
Codex Bot
2026-03-21 19:43:12 +01:00
parent cc1c288f52
commit 4d43f4efb0
7 changed files with 246 additions and 5 deletions

87
lib/miningBackends.js Normal file
View File

@@ -0,0 +1,87 @@
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;