support alph
This commit is contained in:
parent
9fe4d9145a
commit
90ae1d1852
88
app.js
88
app.js
|
@ -2,12 +2,12 @@ const schedule = require("node-schedule");
|
|||
// const executeWithRetry = require("./public/retry")
|
||||
const Times = require("./public/times");
|
||||
const HashRate = require("./src/hashrate");
|
||||
const {Report, ReportEnx} = require("./src/report");
|
||||
const { Report, ReportEnx } = require("./src/report");
|
||||
const Confirm = require("./src/confirm");
|
||||
const Distribution = require("./src/distribution");
|
||||
const { Balance, DGBBlance } = require("./src/blanace");
|
||||
const Stats = require("./src/stat");
|
||||
const ClearDBData = require("./src/clear")
|
||||
const ClearDBData = require("./src/clear");
|
||||
const Notice = require("./src/notice");
|
||||
|
||||
const method = process.argv[2];
|
||||
|
@ -43,8 +43,8 @@ if (method === "hashrate") {
|
|||
}
|
||||
|
||||
if (method === "report") {
|
||||
let report
|
||||
if(coin === "enx"){
|
||||
let report;
|
||||
if (coin === "enx") {
|
||||
report = new ReportEnx(coin);
|
||||
} else {
|
||||
report = new Report(coin);
|
||||
|
@ -60,29 +60,14 @@ if (method === "report") {
|
|||
}, 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") {
|
||||
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();
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (method === "distribution") {
|
||||
const distribution = new Distribution(coin);
|
||||
schedule.scheduleJob({ hour: [0], minute: [1], second: [0] }, async () => {
|
||||
|
@ -96,27 +81,26 @@ if (method === "distribution") {
|
|||
});
|
||||
}
|
||||
|
||||
// if (method === "balance") {
|
||||
// const special_coins = ["dgbo", "dgbs", "dgbq"];
|
||||
// let balance;
|
||||
// if (special_coins.includes(coin)) {
|
||||
// balance = new DGBBlance(coin);
|
||||
// } else {
|
||||
// balance = new Balance(coin);
|
||||
// }
|
||||
// balance
|
||||
// .main()
|
||||
// .then(() => {
|
||||
// console.log("ok");
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// console.log(err);
|
||||
// })
|
||||
// .finally(() => {
|
||||
// process.exit(0);
|
||||
// });
|
||||
// }
|
||||
|
||||
if (method === "balance") {
|
||||
const special_coins = ["dgbo", "dgbs", "dgbq"];
|
||||
let balance;
|
||||
if (special_coins.includes(coin)) {
|
||||
balance = new DGBBlance(coin);
|
||||
} else {
|
||||
balance = new Balance(coin);
|
||||
}
|
||||
balance
|
||||
.main()
|
||||
.then(() => {
|
||||
console.log("ok");
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
})
|
||||
.finally(() => {
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
if (method === "balance") {
|
||||
const special_coins = ["dgbo", "dgbs", "dgbq"];
|
||||
|
@ -127,15 +111,16 @@ if (method === "balance") {
|
|||
balance = new Balance(coin);
|
||||
}
|
||||
|
||||
let hour = 4
|
||||
if(coin === "rxd" || coin === "alph"){
|
||||
hour = 9
|
||||
let hour = 4;
|
||||
if (coin === "rxd" || coin === "alph") {
|
||||
hour = 9;
|
||||
}
|
||||
|
||||
async function task(balance) {
|
||||
let count = 0; // 让 count 成为 task 内部变量,避免多个 schedule 共享 count
|
||||
const last_height = await balance.node.getblockcount()
|
||||
while (count < 36) { // 最多执行 36 次 (6小时)
|
||||
const last_height = await balance.node.getblockcount();
|
||||
while (count < 36) {
|
||||
// 最多执行 36 次 (6小时)
|
||||
const enable = await balance.query_now_height(last_height);
|
||||
if (enable) {
|
||||
await balance.main();
|
||||
|
@ -148,12 +133,11 @@ if (method === "balance") {
|
|||
}
|
||||
console.log("等待超时,任务结束!");
|
||||
}
|
||||
schedule.scheduleJob({hour: [hour], minute: [10], second: [0]}, async () => {
|
||||
schedule.scheduleJob({ hour: [hour], minute: [10], second: [0] }, async () => {
|
||||
await task(balance);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (method === "stats") {
|
||||
const stats = new Stats(coin);
|
||||
stats.caculate_user_should_distribution("2024-11-28 00:00:00");
|
||||
|
@ -183,7 +167,7 @@ if (method === "clear") {
|
|||
|
||||
if (method === "notice") {
|
||||
const notice = new Notice(coin);
|
||||
schedule.scheduleJob({hour:[9], minute:[30], second:[0]}, () =>{
|
||||
notice.main()
|
||||
})
|
||||
schedule.scheduleJob({ hour: [9], minute: [30], second: [0] }, () => {
|
||||
notice.main();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -484,7 +484,7 @@ class ALPHRPCNode extends HttpNode {
|
|||
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 };
|
||||
return {height, hash: block_hash, time:Math.trunc(timestamp / 1000), block_reward: BigInt(attoAlphAmount), block_fees: null };
|
||||
}
|
||||
}
|
||||
// if(fixedOutputs.length === 1){
|
||||
|
|
|
@ -31,7 +31,7 @@ class Balance extends Init {
|
|||
async query_now_height(last_height){
|
||||
try{
|
||||
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){
|
||||
throw err
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ class DGBBlance extends Init {
|
|||
try{
|
||||
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])])
|
||||
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){
|
||||
throw err
|
||||
}
|
||||
|
|
|
@ -41,9 +41,12 @@ class Confirm extends Init {
|
|||
} else {
|
||||
const now = Date.now().valueOf()
|
||||
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 sql = `SELECT MAX(height) AS max_height FROM alph_blkreportprofitv2 WHERE date <= ? AND state = ?;`
|
||||
const data = await this.distribution.exec(sql, [ymd, 0])
|
||||
console.log("data: ", data);
|
||||
if(!data[0]){
|
||||
console.log(`alph当前时间没有需要更新的成熟区块`);
|
||||
return false
|
||||
|
|
|
@ -321,6 +321,10 @@ class Distribution extends Init {
|
|||
accuracy = 100;
|
||||
should_out_date = end_time;
|
||||
count = 2
|
||||
} else if(this.coin === "alph"){
|
||||
accuracy = 0
|
||||
should_out_date = end_time;
|
||||
count = 0
|
||||
} else {
|
||||
should_out_date = end_time;
|
||||
accuracy = 100000000;
|
||||
|
|
|
@ -50,7 +50,7 @@ class Report extends Init {
|
|||
const values = [];
|
||||
for (let item of data) {
|
||||
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.slice(0, -2);
|
||||
|
@ -78,7 +78,7 @@ class Report extends Init {
|
|||
if (check_result) {
|
||||
const block = this.node.block(check_result);
|
||||
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) {
|
||||
|
|
116
test/caculate.js
116
test/caculate.js
|
@ -1,12 +1,108 @@
|
|||
const Times = require('../public/times')
|
||||
const str = "rxd_miners_stats_20241128"
|
||||
const fs = require("fs");
|
||||
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 `
|
||||
const start = new Date("2024-11-28 00:00:00").valueOf()
|
||||
for(let i=0; i<70; i++){
|
||||
const t = Times.utcTime(start + i * 86400000)
|
||||
const ymd = t.split(" ")[0].replace(/-/g, "")
|
||||
sql += ``+ `rxd_miners_stats_${ymd},`
|
||||
class Init {
|
||||
constructor(coin, method) {
|
||||
this.coin = coin;
|
||||
const config = fs.readFileSync(`../config/${coin}.conf`, "utf-8");
|
||||
const { master, slave, redis_options, node_options, distribution_conf, MAX_MATURE, REPORT_ADDRESS } = JSON.parse(config);
|
||||
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()
|
Loading…
Reference in New Issue