jsir 1.2.9 → 1.3.0
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.
- package/cmd/ooa.js +211 -274
- package/evalCode.js +17 -0
- package/index.js +0 -1
- package/package.json +2 -2
- package/util.js +141 -51
- package/cmd/ethPrivateHit.js +0 -64
- package/ethWeb.js +0 -1241
- package/source/uniFact.json +0 -193
- package/source/uniPair.json +0 -713
package/evalCode.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const {info: $info, msg: $msg, warn: $warn, error: $error,
|
|
2
|
+
infoStr: $infoStr, msgStr: $msgStr, warnStr: $warnStr, errorStr: $errorStr,
|
|
3
|
+
tableStr: $tableStr, nableStr: $nableStr,
|
|
4
|
+
errorMsg: $errorMsg, errorStack: $errorStack, errorTag: $errorTag} = require("./util");
|
|
5
|
+
require = require("./util").requireG;
|
|
6
|
+
module.exports = ($text = '', $cmdName = '', $args = [],
|
|
7
|
+
$cmdDir, $cmdMap, $require, $data,
|
|
8
|
+
$nextLine, $nextText, $setTips, $delTips,
|
|
9
|
+
$enter) => {
|
|
10
|
+
const $defArgs = () => $args;
|
|
11
|
+
|
|
12
|
+
return eval(`(async ()=>{try {${$text};
|
|
13
|
+
} catch(e) {
|
|
14
|
+
throw $errorTag(e, $cmdName);
|
|
15
|
+
}
|
|
16
|
+
})()`)
|
|
17
|
+
}
|
package/index.js
CHANGED
package/package.json
CHANGED
package/util.js
CHANGED
|
@@ -17,6 +17,7 @@ const globalDirectories = require('global-dirs');
|
|
|
17
17
|
const emptyFn = ()=>{}
|
|
18
18
|
const dayJs = require('dayjs')
|
|
19
19
|
const table = require('console.table')
|
|
20
|
+
const _fs = require("fs");
|
|
20
21
|
|
|
21
22
|
let _globalLog = createLimitLogger2(`${setting.name}.log`, null, false)
|
|
22
23
|
global.$log = str => {
|
|
@@ -28,7 +29,10 @@ global.$log = str => {
|
|
|
28
29
|
const $log = global.$log
|
|
29
30
|
let _globalDraft= createLimitLogger2(`draft.log`, null, false)
|
|
30
31
|
global.$draft = str => {
|
|
31
|
-
if (
|
|
32
|
+
if (getType(str) === 'RegExp') {
|
|
33
|
+
let results = draftQuery(trim(str.source))
|
|
34
|
+
return results.map(i => i.split(/\n/).slice(1).join('\n'))
|
|
35
|
+
} else if (trim(str)) {
|
|
32
36
|
_globalDraft(`---------${timeStr()}\n${str.split("\n").filter(i => trim(i)).join("\n")}`)
|
|
33
37
|
}
|
|
34
38
|
}
|
|
@@ -87,13 +91,88 @@ async function _buildConfig() {
|
|
|
87
91
|
$config._buildId = setTimeout(_buildConfig, 3000);
|
|
88
92
|
}
|
|
89
93
|
|
|
94
|
+
function isArgsMatch(text, args, callback, useMd5) {
|
|
95
|
+
let match = false
|
|
96
|
+
for (let arg of args) {
|
|
97
|
+
let r = true
|
|
98
|
+
for (let str of arg.split(',').filter(item => trim(item) !== '')) {
|
|
99
|
+
let reg = new RegExp(str, 'i')
|
|
100
|
+
if (!reg.test(text) && !(useMd5 && ('0x' + md5(text).substr(0, 8)) === str)) {
|
|
101
|
+
r = false
|
|
102
|
+
break
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (r) {
|
|
106
|
+
match = true
|
|
107
|
+
break
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (match && callback) {
|
|
111
|
+
callback()
|
|
112
|
+
}
|
|
113
|
+
return match
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function draftQuery(fLine) {
|
|
117
|
+
let lines = []
|
|
118
|
+
let text = String(_fs.readFileSync(getLibDataDir() + "/log/draft.log"))
|
|
119
|
+
let temp = []
|
|
120
|
+
for (let line of text.split("\n")) {
|
|
121
|
+
if (!trim(line)) {
|
|
122
|
+
continue
|
|
123
|
+
}
|
|
124
|
+
if (line.startsWith("---------")) {
|
|
125
|
+
if (temp.length > 0) {
|
|
126
|
+
lines.push(temp.join('\n'))
|
|
127
|
+
}
|
|
128
|
+
temp = []
|
|
129
|
+
temp.push(warnStr(line))
|
|
130
|
+
} else {
|
|
131
|
+
temp.push(line)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (temp.length > 0) {
|
|
135
|
+
lines.push(temp.join('\n'))
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
let results = []
|
|
139
|
+
if (!/^\d+$/.test(fLine)) {
|
|
140
|
+
let items = fLine.split(/\s+/).filter(i => i)
|
|
141
|
+
for (let line of lines) {
|
|
142
|
+
if (isArgsMatch(line, items.filter(item => !/^\d+$/.test(item)))) {
|
|
143
|
+
results.push(line)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
lines = results
|
|
148
|
+
results = []
|
|
149
|
+
|
|
150
|
+
let nums = items.filter(item => /^\d+$/.test(item))
|
|
151
|
+
if (nums.length > 0) {
|
|
152
|
+
fLine = nums[nums.length - 1]
|
|
153
|
+
} else {
|
|
154
|
+
fLine = lines.length
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (fLine && /^\d+$/.test(fLine)) {
|
|
158
|
+
let index = Math.abs(parseInt(fLine));
|
|
159
|
+
results.push(...lines.slice(- index))
|
|
160
|
+
}
|
|
161
|
+
return results
|
|
162
|
+
}
|
|
163
|
+
|
|
90
164
|
function tableStr(...args) {
|
|
91
165
|
return trim(table.getTable(...args))
|
|
92
166
|
}
|
|
93
|
-
|
|
94
167
|
function nableStr(rows) {
|
|
95
168
|
return tableStr(wrapRows(rows))
|
|
96
169
|
}
|
|
170
|
+
console.table = (...args) => {
|
|
171
|
+
console.log(tableStr(...args))
|
|
172
|
+
}
|
|
173
|
+
console.nable = (rows) => {
|
|
174
|
+
console.log(nableStr(rows))
|
|
175
|
+
}
|
|
97
176
|
|
|
98
177
|
function timeStr(fmt, date) {
|
|
99
178
|
return dayJs(date || new Date()).format(fmt || 'YYYY/MM/DD HH:mm:ss')
|
|
@@ -117,8 +196,8 @@ function getVl(...obj) {
|
|
|
117
196
|
}
|
|
118
197
|
}
|
|
119
198
|
|
|
120
|
-
|
|
121
|
-
async function cacheFn(key, fn, validMs, awaitRefresh) {
|
|
199
|
+
const cacheFnRespMap = {};
|
|
200
|
+
async function cacheFn(key, fn, validMs, awaitRefresh = true) {
|
|
122
201
|
getOr($fnCache, key, {
|
|
123
202
|
validMsTime: 0
|
|
124
203
|
});
|
|
@@ -126,20 +205,12 @@ async function cacheFn(key, fn, validMs, awaitRefresh) {
|
|
|
126
205
|
// do nothing
|
|
127
206
|
} else {
|
|
128
207
|
$fnCache[key].validMsTime = Date.now() * 3;
|
|
129
|
-
|
|
130
|
-
cacheFnResp = (async () => {
|
|
208
|
+
cacheFnRespMap[key] = (async () => {
|
|
131
209
|
let val;
|
|
132
210
|
try {
|
|
133
211
|
val = await fn()
|
|
134
212
|
} finally {
|
|
135
|
-
|
|
136
|
-
sync = false
|
|
137
|
-
} else {
|
|
138
|
-
$fnCache[key].validMsTime = 0
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
if (!sync) {
|
|
142
|
-
return;
|
|
213
|
+
$fnCache[key].validMsTime = 0
|
|
143
214
|
}
|
|
144
215
|
$fnCache[key] = {
|
|
145
216
|
val,
|
|
@@ -149,7 +220,7 @@ async function cacheFn(key, fn, validMs, awaitRefresh) {
|
|
|
149
220
|
})();
|
|
150
221
|
}
|
|
151
222
|
if (awaitRefresh || !$fnCache[key].valInit) {
|
|
152
|
-
await
|
|
223
|
+
await cacheFnRespMap[key];
|
|
153
224
|
}
|
|
154
225
|
return $fnCache[key].val
|
|
155
226
|
}
|
|
@@ -238,49 +309,52 @@ function createLimitLogger2(fileName, maxChars, logInfo = true) {
|
|
|
238
309
|
}
|
|
239
310
|
}
|
|
240
311
|
|
|
241
|
-
function textDataFile(fileName, fn) {
|
|
242
|
-
let dataDir = getLibDataDir() + "/data"
|
|
243
|
-
let path = dataDir + "/" + fileName
|
|
244
|
-
if (!fs.existsSync(path)) {
|
|
245
|
-
mkdir(dataDir)
|
|
246
|
-
fs.writeFileSync(path, "")
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
let text = String(fs.readFileSync(path))
|
|
250
|
-
if (!fn) {
|
|
251
|
-
return text
|
|
252
|
-
}
|
|
253
|
-
let val = fn(text)
|
|
254
|
-
if (vl(val) && getType(val) === 'Promise') {
|
|
255
|
-
return val.then(result => {
|
|
256
|
-
if (vl(result) || String(result) === '') {
|
|
257
|
-
fileLock(fileName, () => fs.writeFileSync(path, result))
|
|
258
|
-
}
|
|
259
|
-
return result
|
|
260
|
-
})
|
|
261
|
-
} else {
|
|
262
|
-
if (vl(val) || String(val) === '') {
|
|
263
|
-
fileLock(fileName, () => fs.writeFileSync(path, val))
|
|
264
|
-
}
|
|
265
|
-
return val
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
312
|
function objDataFile(fileName, fn, fmt) {
|
|
313
|
+
fileName = trim(fileName)
|
|
270
314
|
return dataFile(fileName, fn, fmt, {})
|
|
271
315
|
}
|
|
272
316
|
function arrayDataFile(fileName, fn, fmt) {
|
|
317
|
+
fileName = trim(fileName)
|
|
273
318
|
return dataFile(fileName, fn, fmt, [])
|
|
274
319
|
}
|
|
275
|
-
function
|
|
320
|
+
function iobjDataFile(fileName, fn, fmt) {
|
|
321
|
+
return dataFile(getInitName(fileName), fn, fmt, {}, true)
|
|
322
|
+
}
|
|
323
|
+
function iarrayDataFile(fileName, fn, fmt) {
|
|
324
|
+
return dataFile(getInitName(fileName), fn, fmt, [], true)
|
|
325
|
+
}
|
|
326
|
+
function getInitName(fileName) {
|
|
327
|
+
fileName = trim(fileName)
|
|
328
|
+
let ooaDir = getLibDataDir() + "/ooa"
|
|
329
|
+
if (!fileName.startsWith("/")) {
|
|
330
|
+
fileName = 'i ' + fileName.replace(/i\s+/, '')
|
|
331
|
+
if (!/\..+/.test(fileName)) {
|
|
332
|
+
fileName = fileName + '.js'
|
|
333
|
+
}
|
|
334
|
+
fileName = ooaDir + '/' + fileName
|
|
335
|
+
}
|
|
336
|
+
return fileName;
|
|
337
|
+
}
|
|
338
|
+
function dataFile(fileName, fn, fmt, defaultObj = {}, returnStr = false) {
|
|
276
339
|
let dataDir = getLibDataDir() + "/data"
|
|
277
|
-
|
|
340
|
+
fileName = trim(fileName)
|
|
341
|
+
let path
|
|
342
|
+
if (fileName.startsWith("/")) {
|
|
343
|
+
path = fileName
|
|
344
|
+
} else {
|
|
345
|
+
path = dataDir + "/" + fileName
|
|
346
|
+
}
|
|
347
|
+
let prefixStr = returnStr ? 'return ' : '';
|
|
278
348
|
if (!fs.existsSync(path)) {
|
|
279
349
|
mkdir(dataDir)
|
|
280
|
-
fs.writeFileSync(path, JSON.stringify(defaultObj, null, fmt ? 2:null))
|
|
350
|
+
fs.writeFileSync(path, prefixStr + JSON.stringify(defaultObj, null, fmt ? 2:null))
|
|
281
351
|
}
|
|
282
352
|
|
|
283
|
-
let
|
|
353
|
+
let text = String(fs.readFileSync(path));
|
|
354
|
+
if (returnStr) {
|
|
355
|
+
text = text.replace(/return\s+/, '')
|
|
356
|
+
}
|
|
357
|
+
let obj = JSON.parse(text)
|
|
284
358
|
if (!fn) {
|
|
285
359
|
return obj
|
|
286
360
|
}
|
|
@@ -291,14 +365,14 @@ function dataFile(fileName, fn, fmt, defaultObj = {}) {
|
|
|
291
365
|
if (result && typeof result === 'object') {
|
|
292
366
|
obj = result
|
|
293
367
|
}
|
|
294
|
-
fileLock(fileName, () => fs.writeFileSync(path, JSON.stringify(obj, null, fmt ? 2:null)))
|
|
368
|
+
fileLock(fileName, () => fs.writeFileSync(path, prefixStr + JSON.stringify(obj, null, fmt ? 2:null)))
|
|
295
369
|
resolve(obj)
|
|
296
370
|
})
|
|
297
371
|
} else {
|
|
298
372
|
if (val && typeof val === 'object') {
|
|
299
373
|
obj = val
|
|
300
374
|
}
|
|
301
|
-
fileLock(fileName, () => fs.writeFileSync(path, JSON.stringify(obj, null, fmt ? 2:null)))
|
|
375
|
+
fileLock(fileName, () => fs.writeFileSync(path, prefixStr + JSON.stringify(obj, null, fmt ? 2:null)))
|
|
302
376
|
return obj
|
|
303
377
|
}
|
|
304
378
|
}
|
|
@@ -1059,6 +1133,18 @@ function objProfileRows(result) {
|
|
|
1059
1133
|
return temp
|
|
1060
1134
|
}
|
|
1061
1135
|
|
|
1136
|
+
function errorTag(e, tag) {
|
|
1137
|
+
if (!tag) {
|
|
1138
|
+
return e;
|
|
1139
|
+
}
|
|
1140
|
+
if (!isError(e)) {
|
|
1141
|
+
e = new Error(e)
|
|
1142
|
+
e.stack = e.stack.split(/\n/)[0]
|
|
1143
|
+
}
|
|
1144
|
+
e.stack = e.stack + `\n at ${tag}`
|
|
1145
|
+
return e
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1062
1148
|
module.exports = {
|
|
1063
1149
|
run,
|
|
1064
1150
|
reget,
|
|
@@ -1122,7 +1208,6 @@ module.exports = {
|
|
|
1122
1208
|
emptyFn,
|
|
1123
1209
|
setConfig,
|
|
1124
1210
|
axios,
|
|
1125
|
-
textDataFile,
|
|
1126
1211
|
arrayDataFile,
|
|
1127
1212
|
dataFile,
|
|
1128
1213
|
strEq,
|
|
@@ -1146,5 +1231,10 @@ module.exports = {
|
|
|
1146
1231
|
errorMsg,
|
|
1147
1232
|
tableStr,
|
|
1148
1233
|
nableStr,
|
|
1149
|
-
objProfileRows
|
|
1234
|
+
objProfileRows,
|
|
1235
|
+
errorTag,
|
|
1236
|
+
iobjDataFile,
|
|
1237
|
+
iarrayDataFile,
|
|
1238
|
+
isArgsMatch,
|
|
1239
|
+
draftQuery
|
|
1150
1240
|
}
|
package/cmd/ethPrivateHit.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
if (!process.argv[2]) {
|
|
3
|
-
console.log("web3 http provider required")
|
|
4
|
-
return
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
let {run, web3BatchReq, trim, createLimitLogger2, lisPid, timeStr, sleep, getOrFn} = {...require('../util'), ...require('../ethWeb')}
|
|
8
|
-
const Web3 = require("web3");
|
|
9
|
-
let randomHex = require('randomhex');
|
|
10
|
-
|
|
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()
|
|
17
|
-
|
|
18
|
-
run(async ()=>{
|
|
19
|
-
let trys = 1
|
|
20
|
-
while (true) {
|
|
21
|
-
await sleep(1)
|
|
22
|
-
try {
|
|
23
|
-
let accounts = []
|
|
24
|
-
for(let i = 0; i<batchNum; i++) {
|
|
25
|
-
accounts.push(web3.eth.accounts.privateKeyToAccount(randomHex(32)))
|
|
26
|
-
}
|
|
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 ++
|
|
37
|
-
} catch (e) {
|
|
38
|
-
recordLog(e)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
|
|
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
|
-
})
|
|
61
|
-
}
|
|
62
|
-
await web3BatchReq(calls, 49, 9, web3)
|
|
63
|
-
recordLog(`${timeStr()}: ${chainId} ${trys * batchNum}`)
|
|
64
|
-
}
|