const fs = require("fs"); const DBPool = require("../lib/mysql"); const Cache = require("../lib/redis"); const { NEXARPCNode, GRSRPCNode, MONARPCNode, DGBRPCNode, RXDRPCNode, ALPHRPCNode } = require("../lib/node"); 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)); } } 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()