From 9fe4d9145a92647545a7544a4d23bddeecdb4afb Mon Sep 17 00:00:00 2001 From: lzx <393768033@qq.com> Date: Fri, 11 Apr 2025 19:59:58 +0800 Subject: [PATCH] some bugs fixed, add alph node method --- README | 5 ++++- app.js | 2 +- lib/node.js | 10 ++++++++-- src/confirm.js | 27 +++++++++++++++++++++------ 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/README b/README index 9cbe845..b3c512e 100644 --- a/README +++ b/README @@ -199,4 +199,7 @@ pm2 start app.js --name enx-hashrate -- hashrate enx pm2 start app.js --name enx-report -- report enx pm2 start app.js --name alph-report -- report alph -pm2 start app.js --name alph-hashrate -- hashrate alph \ No newline at end of file +pm2 start app.js --name alph-hashrate -- hashrate alph +pm2 start app.js --name alph-confirm -- confirm alph +pm2 start app.js --name alph-distribution -- distribution alph +pm2 start app.js --name alph-balance -- balance alph \ No newline at end of file diff --git a/app.js b/app.js index 6b242b0..1c40958 100644 --- a/app.js +++ b/app.js @@ -128,7 +128,7 @@ if (method === "balance") { } let hour = 4 - if(coin === "rxd"){ + if(coin === "rxd" || coin === "alph"){ hour = 9 } diff --git a/lib/node.js b/lib/node.js index 514c616..4dda8d4 100644 --- a/lib/node.js +++ b/lib/node.js @@ -481,12 +481,18 @@ class ALPHRPCNode extends HttpNode { const coinbaseTx = transactions[transactions.length - 1].unsigned if (coinbaseTx.inputs.length === 0) { const {fixedOutputs} = coinbaseTx - if(fixedOutputs.length === 1){ - const {attoAlphAmount, address } = fixedOutputs[0] + for(let item of fixedOutputs){ + const {attoAlphAmount, address } = item if(address === REPORT_ADDRESS){ return {height, hash: block_hash, time:Math.trunc(timestamp / 1000), block_reward: Number(attoAlphAmount), block_fees: null }; } } + // if(fixedOutputs.length === 1){ + // const {attoAlphAmount, address } = fixedOutputs[0] + // if(address === REPORT_ADDRESS){ + // return {height, hash: block_hash, time:Math.trunc(timestamp / 1000), block_reward: Number(attoAlphAmount), block_fees: null }; + // } + // } } return false } catch(err){ diff --git a/src/confirm.js b/src/confirm.js index 93bc6b1..b2cb1d3 100644 --- a/src/confirm.js +++ b/src/confirm.js @@ -1,4 +1,5 @@ const Init = require("./init"); +const Times = require("../public/times"); class Confirm extends Init { constructor(coin) { @@ -28,13 +29,27 @@ class Confirm extends Init { // 查询当前最高成熟高度,即当前最新高度 - MAX_MATURE async query_maxture_height() { try { - const now_height = await this.node.getblockcount(); - const max_height = Number(now_height) - this.MAX_MATURE; - if (!this.isPositiveInteger(max_height)) { - console.log(`当前节点最大高度为${now_height}, 当前成熟高度为${max_height}`); - return false; + if(this.coin !== "alph"){ + const now_height = await this.node.getblockcount(); + const max_height = Number(now_height) - this.MAX_MATURE; + if (!this.isPositiveInteger(max_height)) { + console.log(`当前节点最大高度为${now_height}, 当前成熟高度为${max_height}`); + return false; + } else { + return max_height; + } } else { - return max_height; + const now = Date.now().valueOf() + const max_mature_time = now - this.MAX_MATURE * 60 * 1000 + const ymd = Times.utcTime(max_mature_time) + const sql = `SELECT MAX(height) AS max_height FROM alph_blkreportprofitv2 WHERE date <= ? AND state = ?;` + const data = await this.distribution.exec(sql, [ymd, 0]) + if(!data[0]){ + console.log(`alph当前时间没有需要更新的成熟区块`); + return false + } else { + return data[0].max_height + } } } catch (err) { throw err;