-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJupUnlock.js
114 lines (96 loc) · 3.61 KB
/
JupUnlock.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
const Logger = require("@youpaichris/logger");
const fs = require("fs");
const path = require("path");
const logger = new Logger();
const { Wallet } = require('@project-serum/anchor');
const dotenv = require("dotenv");
dotenv.config();
const { Connection, Keypair } = require('@solana/web3.js');
const Worker = require("./src/worker.js");
const { getSPLBalance } = require("./src/spl.js");
const bs58 = require('bs58');
const readlineSync = require('readline-sync');
const { appendObjectToCSV, sleep, decryptUsingAESGCM, convertCSVToObjectSync } = require('./src/utils.js');
const logsPath = path.join(__dirname, 'logs');
// 如果logs文件夹不存在则创建
if (!fs.existsSync(logsPath)) {
fs.mkdirSync(logsPath);
}
const successPath = path.join(logsPath, 'UnlockSuccess.csv');
const errorPath = path.join(logsPath, 'UnlockError.csv');
let rpc = ""; // RPC,到https://www.helius.dev/注册获取
const wallet_path = ''; // 钱包文件路径
const CONCURRENCY = 1; // 线程数
const pwd = readlineSync.question('Please enter your password: ', {
hideEchoBack: true // 密码不回显
});
const walletData = convertCSVToObjectSync(wallet_path);
async function processWallet(wt, ...args) {
const privateKey = decryptUsingAESGCM(wt.a, wt.e, wt.i, wt.s, pwd)
const connection = new Connection(rpc);
const wallet = new Wallet(Keypair.fromSecretKey(bs58.decode(privateKey)));
let p = new Worker('1', rpc, privateKey); // 请根据实际情况替换worker的实例化方式
let date;
// 查询SOL余额
const SOLBalance = await connection.getBalance(wallet.publicKey);
logger.info('wallet address:', wt.Address, 'SOLBalance:', SOLBalance);
if (SOLBalance < 0.0003 * 10 ** 9) {
logger.error(`钱包:${wt.Address}余额不足, SOL余额:${SOLBalance}`);
date = new Date().toLocaleString();
await appendObjectToCSV({ date, ...wt, Error: `余额不足,SOL余额:${SOLBalance}` }, errorPath);
}
const MAX_RETRY = 100;
let num = 0;
while (num < MAX_RETRY) {
try {
const txid = await p.unlock();
if (txid) {
logger.success(`交易成功:https://solscan.io/tx/${txid}`);
// 获取当前本地时间
date = new Date().toLocaleString();
await appendObjectToCSV({ date, ...wt }, successPath)
break;
} else {
num++;
logger.warn('交易失败,休息6秒后重试...');
await sleep(0.1);
if (num === MAX_RETRY) {
logger.error('重试次数已达上限');
date = new Date().toLocaleString();
await appendObjectToCSV({ date, ...wt, Error: '重试次数已达上限' }, errorPath)
break;
}
}
} catch (error) {
num++;
if (num === MAX_RETRY) {
logger.error('重试次数已达上限');
date = new Date().toLocaleString();
await appendObjectToCSV({ date, ...wt, Error: error }, errorPath)
break;
}
logger.error(`交易失败,休息6秒后重试...错误原因: ${error}`);
await sleep(0.1);
}
}
// 随机暂停 5-10分钟
const sleepTime = Math.floor(Math.random() * (10 - 7) + 1);
logger.info(`休息${sleepTime}分钟后继续...`)
await sleep(sleepTime);
}
async function processQueue() {
if (walletData.length === 0) return true;
const wt = walletData.shift();
await processWallet(wt, pwd);
return processQueue();
}
(async function start() {
logger.warn(`当前版本为: 1.0.0`);
const results = await Promise.all(
Array.from({ length: Math.min(CONCURRENCY, walletData.length) }, processQueue)
);
if (results.every(res => res)) {
logger.warn(`所有线程执行完毕`);
process.exit(0);
}
})();