jsir 1.0.3 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,54 +1,64 @@
1
1
  #!/usr/bin/env node
2
- let {run, coinNum, trim, getLibDataDir, lisPid, fileCleaner} = require('../index')
3
- const Web3 = require("web3");
4
2
  if (!process.argv[2]) {
5
- console.log("http provider required")
3
+ console.log("web3 http provider required")
6
4
  return
7
5
  }
8
6
 
9
- let web3 = new Web3(new Web3.providers.HttpProvider(trim(process.argv[2])));
7
+ let {run, web3BatchReq, trim, createLimitLogger2, lisPid, timeStr, sleep, getOrFn} = require('../index')
8
+ const Web3 = require("web3");
10
9
  let randomHex = require('randomhex');
11
10
 
12
- let usdtAddr = '0xdac17f958d2ee523a2206206994597c13d831ec7'
13
- const usdtCon = new web3.eth.Contract(require('../source/usdtAbi'), usdtAddr);
14
- let fs = require("fs")
11
+ let accountLog = createLimitLogger2('ethPrivateHit.account')
12
+ let recordLog = createLimitLogger2('ethPrivateHit.log')
13
+ let batchNum = 365
14
+ lisPid(`ethPrivateHit`)
15
+ let web3Map = {}
16
+ let web3 = new Web3()
15
17
 
16
- let home = getLibDataDir()
17
- let trysFile = `${home}/ethHitTrys.txt`
18
- let privateFile = `${home}/ethPrivates.txt`
19
- let errorFile = `${home}/ethHit.error`
20
- lisPid("ethPrivateHit")
21
- fileCleaner(errorFile)
22
18
  run(async ()=>{
23
- let num = Number(readTrys() || 1)
19
+ let trys = 1
24
20
  while (true) {
21
+ await sleep(1)
25
22
  try {
26
- fs.writeFileSync(trysFile, String(num))
27
- let key = randomHex(32);
28
- let account = web3.eth.accounts.privateKeyToAccount(key)
29
- account.usdtBalance = coinNum(await usdtCon.methods.balanceOf(account.address).call(), 6)
30
- account.balance = coinNum(await web3.eth.getBalance(account.address))
31
- if ((account.balance + account.usdtBalance) > 0) {
32
- log(`account: ${JSON.stringify(account, null, 2)}`)
23
+ let accounts = []
24
+ for(let i = 0; i<batchNum; i++) {
25
+ accounts.push(web3.eth.accounts.privateKeyToAccount(randomHex(32)))
33
26
  }
34
- num ++
27
+ for(let url of process.argv.slice(2)) {
28
+ let web3Obj = getOrFn(web3Map, url, () => {
29
+ return {web3: new Web3(trim(url))}
30
+ })
31
+ if (!web3Obj.chainId) {
32
+ web3Obj.chainId = await web3Obj.web3.eth.getChainId()
33
+ }
34
+ await processChain(accounts, web3Obj.web3, web3Obj.chainId, trys)
35
+ }
36
+ trys ++
35
37
  } catch (e) {
36
- logErr(e)
38
+ recordLog(e)
37
39
  }
38
40
  }
39
41
  })
40
42
 
41
- function log(s) {
42
- fs.appendFileSync(privateFile, s + '\n')
43
- }
44
- function logErr(s) {
45
- fs.appendFileSync(errorFile, s + '\n')
46
- }
47
-
48
- function readTrys() {
49
- try {
50
- return trim(fs.readFileSync(trysFile))
51
- }catch (e) {
52
-
43
+ async function processChain(accounts, web3, chainId, trys) {
44
+ let calls = []
45
+ for(let account of accounts) {
46
+ calls.push({
47
+ method: web3.eth.getBalance,
48
+ args: [account.address],
49
+ callback: (error, bal) => {
50
+ if (error) {
51
+ recordLog(error)
52
+ return
53
+ }
54
+ if (bal > 0) {
55
+ account.balance = bal
56
+ account.chainId = chainId
57
+ accountLog(`account: ${JSON.stringify(account, null, 2)}`)
58
+ }
59
+ }
60
+ })
53
61
  }
62
+ await web3BatchReq(calls, 49, 9, web3)
63
+ recordLog(`${timeStr()}: ${chainId} ${trys * batchNum}`)
54
64
  }