116 lines
3.6 KiB
JavaScript
116 lines
3.6 KiB
JavaScript
function getLegacySoloBackend() {
|
|
return {
|
|
name: 'solo',
|
|
type: 'solo',
|
|
coin: config.coin,
|
|
symbol: config.symbol,
|
|
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,
|
|
cnAlgorithm: config.cnAlgorithm || 'cryptonight',
|
|
cnVariant: config.cnVariant || 0,
|
|
cnBlobType: config.cnBlobType || 0,
|
|
includeHeight: typeof config.includeHeight !== 'undefined' ? config.includeHeight : false,
|
|
isRandomX: config.isRandomX || false
|
|
};
|
|
}
|
|
|
|
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,
|
|
coin: backend.coin || config.coin,
|
|
symbol: backend.symbol || config.symbol,
|
|
host: backend.host,
|
|
port: backend.port,
|
|
alwaysPoll: backend.alwaysPoll || false,
|
|
walletAddress: backend.walletAddress || null,
|
|
cnAlgorithm: backend.cnAlgorithm || config.cnAlgorithm || 'cryptonight',
|
|
cnVariant: typeof backend.cnVariant !== 'undefined' ? backend.cnVariant : (config.cnVariant || 0),
|
|
cnBlobType: typeof backend.cnBlobType !== 'undefined' ? backend.cnBlobType : (config.cnBlobType || 0),
|
|
includeHeight: typeof backend.includeHeight !== 'undefined' ? backend.includeHeight : (typeof config.includeHeight !== 'undefined' ? config.includeHeight : false),
|
|
isRandomX: typeof backend.isRandomX !== 'undefined' ? backend.isRandomX : (config.isRandomX || false)
|
|
};
|
|
}
|
|
|
|
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;
|
|
|
|
function getActiveMiningParams() {
|
|
let backend = getActiveMiningBackend();
|
|
return {
|
|
coin: backend.coin,
|
|
symbol: backend.symbol,
|
|
cnAlgorithm: backend.cnAlgorithm,
|
|
cnVariant: backend.cnVariant,
|
|
cnBlobType: backend.cnBlobType,
|
|
includeHeight: backend.includeHeight,
|
|
isRandomX: backend.isRandomX
|
|
};
|
|
}
|
|
exports.getActiveMiningParams = getActiveMiningParams;
|