Salvium: various fixes in paymentprocessor and addresses validation for upcoming carrot hf

This commit is contained in:
gh14
2025-08-31 21:34:22 +00:00
parent 1a06d8a6ad
commit e2abef8b06
2 changed files with 192 additions and 62 deletions

View File

@@ -14,6 +14,17 @@ exports.dateFormat = dateFormat;
let cnUtil = require('cryptoforknote-util');
exports.cnUtil = cnUtil;
require('./configReader.js');
// Initialize log system
let logSystem = 'pool';
require('./exceptionWriter.js')(logSystem);
let threadId = '(Thread ' + process.env.forkId + ') ';
let log = function (severity, system, text, data) {
global.log(severity, system, threadId + text, data);
};
/**
* Generate random instance id
**/
@@ -198,7 +209,7 @@ exports.ringBuffer = function (maxSize) {
// Check if Salvium functionality is enabled
function isSalviumEnabled() {
return config.salvium && config.salvium.enabled === true &&
(config.coin === 'Salvium' || config.symbol === 'SAL' || config.symbol === 'SAL1');
(config.coin === 'Salvium' || config.coin === 'SAL' || config.symbol === 'SAL' || config.symbol === 'SAL1');
}
exports.isSalviumEnabled = isSalviumEnabled;
@@ -216,17 +227,59 @@ exports.getSalviumState = getSalviumState;
// Validate Salvium address with specific prefixes
function validateSalviumAddress(address, type) {
if (!isSalviumEnabled() || !address) return false;
let addressPrefix = getAddressPrefix(address);
if (!addressPrefix) return false;
let prefixes = config.salvium.addressPrefixes[type];
if (!prefixes) return false;
return addressPrefix === parseInt(prefixes.public, 16) ||
addressPrefix === parseInt(prefixes.integrated, 16) ||
addressPrefix === parseInt(prefixes.subaddress, 16);
if (!isSalviumEnabled() || !address) return false;
const sep =
(config.salvium && config.salvium.addressSeparator) ||
(config.poolServer && config.poolServer.paymentId && config.poolServer.paymentId.addressSeparator) ||
"_";
// default to cryptonote, case-insensitive
const normType = (type || "cryptonote").toLowerCase();
// choose which part of a dual address to validate
let candidate = address;
if (address.includes(sep)) {
const parts = address.split(sep);
candidate = normType === "carrot" ? (parts[1] || "") : (parts[0] || "");
}
// get prefix from the selected candidate
const addressPrefix = getAddressPrefix(candidate);
if (!addressPrefix && addressPrefix !== 0) return false;
// pick prefixes set for the requested type
const prefixes =
config.salvium &&
config.salvium.addressPrefixes &&
config.salvium.addressPrefixes[normType];
if (!prefixes) return false;
// support both hex strings ("0x...") and decimal numbers in config
const toInt = (v) => {
if (typeof v === "number") return v;
if (typeof v === "string") {
const s = v.trim().toLowerCase();
if (s.startsWith("0x")) return parseInt(s, 16);
const n = parseInt(s, 10);
return Number.isFinite(n) ? n : NaN;
}
return NaN;
};
const pub = toInt(prefixes.public);
const integ = toInt(prefixes.integrated);
const sub = toInt(prefixes.subaddress);
if (![pub, integ, sub].every(Number.isFinite)) return false;
// Optional: keep your existing debug log
log("warn", logSystem, "prefixy %s : %s : %s", [candidate, addressPrefix, pub]);
return (
addressPrefix === pub ||
addressPrefix === integ ||
addressPrefix === sub
);
}
exports.validateSalviumAddress = validateSalviumAddress;