From d321f08f2f98f0b54d71aa90cdd1802aa550bf05 Mon Sep 17 00:00:00 2001 From: Nuno Faria Date: Sat, 10 May 2025 19:27:52 +0100 Subject: [PATCH 1/2] add support for http /time mining nodes trying to connect to the light node will check the light node time (unix timestamp format) through http /time. This change, along more at `syncing.js` will ensure the light node delivers it. --- expressApp.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/expressApp.js b/expressApp.js index 9d23dae..8d6f628 100644 --- a/expressApp.js +++ b/expressApp.js @@ -25,6 +25,10 @@ const expressApp = express(); expressApp.use(cors()); +expressApp.get('/time', (req, res) => { + res.send(`${Math.floor(Date.now() / 1000)}`); +}); + expressApp.get('/syncing', async (req, res) => { //await syncing.resetTx404(); //await syncing.deleteBlackTxsAndAddress(); From 6283ad434897d3675d81726978d0220eadf95d48 Mon Sep 17 00:00:00 2001 From: Nuno Faria Date: Sat, 10 May 2025 19:34:31 +0100 Subject: [PATCH 2/2] add getTime() and fix peers table creation getTime() relates to changes at expressApp.js to provide the light node unix timestamp over http, a requirement for mining nodes trying to connect. The peers table was throwing an error due to a missing table column, fixed it. --- src/syncing.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/syncing.js b/src/syncing.js index 3301ae8..bf69178 100644 --- a/src/syncing.js +++ b/src/syncing.js @@ -137,6 +137,7 @@ location TEXT not null, area_code TEXT not null, country_code TEXT not null, + mining_address TEXT, status INTEGER DEFAULT 0 ); `); @@ -4297,6 +4298,15 @@ } }; + async function getTime() { + try { + const response = await axios.get("http://"+Item.ip+"/time"); + console.log(`Unix Timestamp: ${response.data}`); + } catch (error) { + console.error('Error fetching time:', error); + } + }; + export default { initChivesLightNode, initChivesLightNodeSql, @@ -4390,5 +4400,6 @@ mkdirForData, deleteBlackTxsAndAddress, restrictToLocalhost, - closeDb - }; \ No newline at end of file + closeDb, + getTime + };