support alph

This commit is contained in:
lzx 2025-04-15 11:15:38 +08:00
parent 9fe4d9145a
commit 90ae1d1852
7 changed files with 157 additions and 70 deletions

94
app.js
View File

@ -2,12 +2,12 @@ const schedule = require("node-schedule");
// const executeWithRetry = require("./public/retry") // const executeWithRetry = require("./public/retry")
const Times = require("./public/times"); const Times = require("./public/times");
const HashRate = require("./src/hashrate"); const HashRate = require("./src/hashrate");
const {Report, ReportEnx} = require("./src/report"); const { Report, ReportEnx } = require("./src/report");
const Confirm = require("./src/confirm"); const Confirm = require("./src/confirm");
const Distribution = require("./src/distribution"); const Distribution = require("./src/distribution");
const { Balance, DGBBlance } = require("./src/blanace"); const { Balance, DGBBlance } = require("./src/blanace");
const Stats = require("./src/stat"); const Stats = require("./src/stat");
const ClearDBData = require("./src/clear") const ClearDBData = require("./src/clear");
const Notice = require("./src/notice"); const Notice = require("./src/notice");
const method = process.argv[2]; const method = process.argv[2];
@ -43,8 +43,8 @@ if (method === "hashrate") {
} }
if (method === "report") { if (method === "report") {
let report let report;
if(coin === "enx"){ if (coin === "enx") {
report = new ReportEnx(coin); report = new ReportEnx(coin);
} else { } else {
report = new Report(coin); report = new Report(coin);
@ -60,29 +60,14 @@ if (method === "report") {
}, interval); }, interval);
} }
// if (method === "confirm") {
// // schedule.scheduleJob({hour:[1], minute:[30], second:[0]}, async () =>{
// // confirm.main();
// // })
// let interval = 600000;
// if (coin === "rxd") {
// interval = 1800000;
// }
// const confirm = new Confirm(coin);
// setInterval(() => {
// confirm.main();
// }, interval);
// }
if (method === "confirm") { if (method === "confirm") {
const confirm = new Confirm(coin); const confirm = new Confirm(coin);
schedule.scheduleJob({hour:[1], minute:[30], second:[0]}, async () =>{ schedule.scheduleJob({ hour: [1], minute: [30], second: [0] }, async () => {
confirm.main(); confirm.main();
}) });
} }
if (method === "distribution") { if (method === "distribution") {
const distribution = new Distribution(coin); const distribution = new Distribution(coin);
schedule.scheduleJob({ hour: [0], minute: [1], second: [0] }, async () => { schedule.scheduleJob({ hour: [0], minute: [1], second: [0] }, async () => {
@ -96,27 +81,26 @@ if (method === "distribution") {
}); });
} }
// if (method === "balance") { if (method === "balance") {
// const special_coins = ["dgbo", "dgbs", "dgbq"]; const special_coins = ["dgbo", "dgbs", "dgbq"];
// let balance; let balance;
// if (special_coins.includes(coin)) { if (special_coins.includes(coin)) {
// balance = new DGBBlance(coin); balance = new DGBBlance(coin);
// } else { } else {
// balance = new Balance(coin); balance = new Balance(coin);
// } }
// balance balance
// .main() .main()
// .then(() => { .then(() => {
// console.log("ok"); console.log("ok");
// }) })
// .catch((err) => { .catch((err) => {
// console.log(err); console.log(err);
// }) })
// .finally(() => { .finally(() => {
// process.exit(0); process.exit(0);
// }); });
// } }
if (method === "balance") { if (method === "balance") {
const special_coins = ["dgbo", "dgbs", "dgbq"]; const special_coins = ["dgbo", "dgbs", "dgbq"];
@ -126,16 +110,17 @@ if (method === "balance") {
} else { } else {
balance = new Balance(coin); balance = new Balance(coin);
} }
let hour = 4 let hour = 4;
if(coin === "rxd" || coin === "alph"){ if (coin === "rxd" || coin === "alph") {
hour = 9 hour = 9;
} }
async function task(balance) { async function task(balance) {
let count = 0; // 让 count 成为 task 内部变量,避免多个 schedule 共享 count let count = 0; // 让 count 成为 task 内部变量,避免多个 schedule 共享 count
const last_height = await balance.node.getblockcount() const last_height = await balance.node.getblockcount();
while (count < 36) { // 最多执行 36 次 (6小时) while (count < 36) {
// 最多执行 36 次 (6小时)
const enable = await balance.query_now_height(last_height); const enable = await balance.query_now_height(last_height);
if (enable) { if (enable) {
await balance.main(); await balance.main();
@ -147,13 +132,12 @@ if (method === "balance") {
count++; count++;
} }
console.log("等待超时,任务结束!"); console.log("等待超时,任务结束!");
} }
schedule.scheduleJob({hour: [hour], minute: [10], second: [0]}, async () => { schedule.scheduleJob({ hour: [hour], minute: [10], second: [0] }, async () => {
await task(balance); await task(balance);
}); });
} }
if (method === "stats") { if (method === "stats") {
const stats = new Stats(coin); const stats = new Stats(coin);
stats.caculate_user_should_distribution("2024-11-28 00:00:00"); stats.caculate_user_should_distribution("2024-11-28 00:00:00");
@ -183,7 +167,7 @@ if (method === "clear") {
if (method === "notice") { if (method === "notice") {
const notice = new Notice(coin); const notice = new Notice(coin);
schedule.scheduleJob({hour:[9], minute:[30], second:[0]}, () =>{ schedule.scheduleJob({ hour: [9], minute: [30], second: [0] }, () => {
notice.main() notice.main();
}) });
} }

View File

@ -484,7 +484,7 @@ class ALPHRPCNode extends HttpNode {
for(let item of fixedOutputs){ for(let item of fixedOutputs){
const {attoAlphAmount, address } = item const {attoAlphAmount, address } = item
if(address === REPORT_ADDRESS){ if(address === REPORT_ADDRESS){
return {height, hash: block_hash, time:Math.trunc(timestamp / 1000), block_reward: Number(attoAlphAmount), block_fees: null }; return {height, hash: block_hash, time:Math.trunc(timestamp / 1000), block_reward: BigInt(attoAlphAmount), block_fees: null };
} }
} }
// if(fixedOutputs.length === 1){ // if(fixedOutputs.length === 1){

View File

@ -31,7 +31,7 @@ class Balance extends Init {
async query_now_height(last_height){ async query_now_height(last_height){
try{ try{
const [chain_height, [db_height]] = await Promise.all([this.node.getblockcount(), this.query_min_height()]) const [chain_height, [db_height]] = await Promise.all([this.node.getblockcount(), this.query_min_height()])
return chain_height > db_height.min_height + this.MAX_MATURE && chain_height > last_height + 2// 在成熟高度基础上再+2高度防止pool_account转账未更新 return chain_height > db_height.min_height + this.MAX_MATURE && chain_height > last_height + 5// 在成熟高度基础上再+2高度防止pool_account转账未更新
} catch(err){ } catch(err){
throw err throw err
} }
@ -152,7 +152,7 @@ class DGBBlance extends Init {
try{ try{
const sql = `SELECT MAX(max_height) AS max_height FROM wallet_in WHERE coin Like "dgb%" AND state = ?;` const sql = `SELECT MAX(max_height) AS max_height FROM wallet_in WHERE coin Like "dgb%" AND state = ?;`
const [chain_height, [db_height]] = await Promise.all([this.node.getblockcount(), this.distribution.exec(sql, [0])]) const [chain_height, [db_height]] = await Promise.all([this.node.getblockcount(), this.distribution.exec(sql, [0])])
return chain_height > db_height.max_height + this.MAX_MATURE && chain_height > last_height + 2 return chain_height > db_height.max_height + this.MAX_MATURE && chain_height > last_height + 5
} catch(err){ } catch(err){
throw err throw err
} }

View File

@ -41,9 +41,12 @@ class Confirm extends Init {
} else { } else {
const now = Date.now().valueOf() const now = Date.now().valueOf()
const max_mature_time = now - this.MAX_MATURE * 60 * 1000 const max_mature_time = now - this.MAX_MATURE * 60 * 1000
console.log("MAX_MATURE:", this.MAX_MATURE);
console.log("max_mature_time: ", max_mature_time);
const ymd = Times.utcTime(max_mature_time) const ymd = Times.utcTime(max_mature_time)
const sql = `SELECT MAX(height) AS max_height FROM alph_blkreportprofitv2 WHERE date <= ? AND state = ?;` const sql = `SELECT MAX(height) AS max_height FROM alph_blkreportprofitv2 WHERE date <= ? AND state = ?;`
const data = await this.distribution.exec(sql, [ymd, 0]) const data = await this.distribution.exec(sql, [ymd, 0])
console.log("data: ", data);
if(!data[0]){ if(!data[0]){
console.log(`alph当前时间没有需要更新的成熟区块`); console.log(`alph当前时间没有需要更新的成熟区块`);
return false return false

View File

@ -321,6 +321,10 @@ class Distribution extends Init {
accuracy = 100; accuracy = 100;
should_out_date = end_time; should_out_date = end_time;
count = 2 count = 2
} else if(this.coin === "alph"){
accuracy = 0
should_out_date = end_time;
count = 0
} else { } else {
should_out_date = end_time; should_out_date = end_time;
accuracy = 100000000; accuracy = 100000000;

View File

@ -50,7 +50,7 @@ class Report extends Init {
const values = []; const values = [];
for (let item of data) { for (let item of data) {
const { date, height, hash, reward, fees } = item; const { date, height, hash, reward, fees } = item;
values.push(date, height, hash, reward, fees, 0); values.push(date, height, hash, reward.toString(), fees, 0);
sql += `(?,?,?,?,?,?), `; sql += `(?,?,?,?,?,?), `;
} }
sql = sql.slice(0, -2); sql = sql.slice(0, -2);
@ -78,7 +78,7 @@ class Report extends Init {
if (check_result) { if (check_result) {
const block = this.node.block(check_result); const block = this.node.block(check_result);
const { height, hash, time, block_reward, block_fees } = block; const { height, hash, time, block_reward, block_fees } = block;
suc_data.push({ date: Times.utcTime(time * 1000), height, hash, reward: block_reward, fees: block_fees }); suc_data.push({ date: Times.utcTime(time * 1000), height, hash, reward: block_reward.toString(), fees: block_fees });
} }
} }
if (suc_data.length === 0) { if (suc_data.length === 0) {

View File

@ -1,12 +1,108 @@
const Times = require('../public/times') const fs = require("fs");
const str = "rxd_miners_stats_20241128" const DBPool = require("../lib/mysql");
const Cache = require("../lib/redis");
const { NEXARPCNode, GRSRPCNode, MONARPCNode, DGBRPCNode, RXDRPCNode, ALPHRPCNode } = require("../lib/node");
let sql = `DROP TABLE IF EXISTS ` class Init {
const start = new Date("2024-11-28 00:00:00").valueOf() constructor(coin, method) {
for(let i=0; i<70; i++){ this.coin = coin;
const t = Times.utcTime(start + i * 86400000) const config = fs.readFileSync(`../config/${coin}.conf`, "utf-8");
const ymd = t.split(" ")[0].replace(/-/g, "") const { master, slave, redis_options, node_options, distribution_conf, MAX_MATURE, REPORT_ADDRESS } = JSON.parse(config);
sql += ``+ `rxd_miners_stats_${ymd},` const { pooldb, sharesdb, distribution, hashrate, users_addresses, balance } = master;
const { pooldb_slave, sharesdb_slave } = slave;
const { node1, node2 } = node_options;
const { redis1 } = redis_options;
const { POOL_FEE } = distribution_conf;
const node_map = {
mona: MONARPCNode,
nexa: NEXARPCNode,
grs: GRSRPCNode,
dgbs: DGBRPCNode,
dgbq: DGBRPCNode,
dgbo: DGBRPCNode,
rxd: RXDRPCNode,
alph: ALPHRPCNode,
};
switch (method) {
case "hashrate":
this.sharesdb = new DBPool(coin, sharesdb);
this.sharesdb_slave = new DBPool(coin, sharesdb_slave);
this.pooldb = new DBPool(coin, pooldb);
this.redis = new Cache(redis1);
// this.pooldb_slave = new DBPool(coin, pooldb_slave)
this.hashratedb = new DBPool(coin, hashrate);
break;
case "report":
this.REPORT_ADDRESS = REPORT_ADDRESS;
this.node = new node_map[coin](node2);
this.distribution = new DBPool(coin, distribution);
this.redis = new Cache(redis1);
break;
case "clear":
this.pooldb = new DBPool(coin, pooldb);
this.sharesdb = new DBPool(coin, sharesdb);
this.hashratedb = new DBPool(coin, hashrate);
break;
case "distribution":
this.pooldb = new DBPool(coin, pooldb);
this.hashratedb = new DBPool(coin, hashrate);
this.distributiondb = new DBPool(coin, distribution);
this.users_addresses = new DBPool(coin, users_addresses);
this.node = new node_map[coin](node2);
this.REPORT_ADDRESS = REPORT_ADDRESS;
this.POOL_FEE = POOL_FEE;
console.log(`当前手续费率为:${POOL_FEE}`);
// this.balance = new DBPool(coin, balance)
break;
case "balance":
this.distribution = new DBPool(coin, distribution);
this.balancedb = new DBPool(coin, balance);
break;
case "confirm":
this.MAX_MATURE = MAX_MATURE;
this.REPORT_ADDRESS = REPORT_ADDRESS;
this.node = new node_map[coin](node2);
this.distribution = new DBPool(coin, distribution);
this.pooldb = new DBPool(coin, pooldb);
break;
case "stats":
this.pooldb = new DBPool(coin, pooldb);
this.hashratedb = new DBPool(coin, hashrate);
this.distribution = new DBPool(coin, distribution);
break;
default:
throw `暂不支持${method}方法 init`;
}
}
sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
} }
sql = sql.slice(0, -1)
console.log(sql); const a = new Init("alph", "report")
async function main() {
const sql1 = `SELECT height FROM alph_blkreportprofitv2;`
const data1 = await a.distribution.exec(sql1)
let sql = `UPDATE alph_blkreportprofitv2 SET reward = CASE height `
const heights = []
for (let item of data1) {
const { height } = item
heights.push(height)
const data = await a.node.verify_block(height, a.REPORT_ADDRESS)
const { block_reward } = data
sql += `WHEN ${height} THEN ${block_reward} `
}
// ✅ 加上 END 和 WHERE
sql += `END WHERE height IN (${heights.join(",")});`
await a.distribution.exec(sql)
}
main()