From 35215c77409ed12c59f71c0f9cc1c3d836941827 Mon Sep 17 00:00:00 2001 From: natsoni Date: Thu, 23 May 2024 11:30:30 +0200 Subject: [PATCH] Add check for pool addresses and regexes --- backend/src/api/pools-parser.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/backend/src/api/pools-parser.ts b/backend/src/api/pools-parser.ts index 66f09a9f7..e04565a01 100644 --- a/backend/src/api/pools-parser.ts +++ b/backend/src/api/pools-parser.ts @@ -52,6 +52,28 @@ class PoolsParser { continue; } + // One of the two fields 'addresses' or 'regexes' must be a non-empty array + if (!pool.addresses && !pool.regexes) { + logger.err(`Mining pool ${pool.name} must have at least one of the fields 'addresses' or 'regexes'. Skipping.`); + continue; + } + + pool.addresses = pool.addresses || []; + pool.regexes = pool.regexes || []; + + if (pool.addresses.length === 0 && pool.regexes.length === 0) { + logger.err(`Mining pool ${pool.name} has no 'addresses' nor 'regexes' defined. Skipping.`); + continue; + } + + if (pool.addresses.length === 0) { + logger.warn(`Mining pool ${pool.name} has no 'addresses' defined.`); + } + + if (pool.regexes.length === 0) { + logger.warn(`Mining pool ${pool.name} has no 'regexes' defined.`); + } + const poolDB = await PoolsRepository.$getPoolByUniqueId(pool.id, false); if (!poolDB) { // New mining pool