jsir 1.1.8 → 1.2.3
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 +72 -17
- package/ethWeb.js +52 -38
- package/index.js +4 -2
- package/package.json +7 -7
- package/sol.js +7 -9
- package/util.js +20 -1
package/cmd/ooa.js
CHANGED
|
@@ -108,14 +108,30 @@ const _mainCmdMap = {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
function getFileOpenExe(fileName) {
|
|
112
|
+
fileName = trim(fileName);
|
|
113
|
+
let strs = fileName.split('.')
|
|
114
|
+
let suffix = ''
|
|
115
|
+
if (strs.length > 1) {
|
|
116
|
+
suffix = strs[strs.length - 1]
|
|
117
|
+
}
|
|
118
|
+
if (!suffix) {
|
|
119
|
+
return 'idea'
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
let exe = getConfig(`${suffix}_exe`)
|
|
123
|
+
return exe || 'idea';
|
|
124
|
+
}
|
|
125
|
+
|
|
111
126
|
run(async () => {
|
|
112
127
|
try {
|
|
113
128
|
_fs.mkdirSync(_home)
|
|
114
129
|
} catch (e) {}
|
|
115
130
|
|
|
116
131
|
if (_args[0] === 'config') {
|
|
117
|
-
let
|
|
118
|
-
|
|
132
|
+
let fileName = 'config.json';
|
|
133
|
+
let configFile = getLibDataDir() + '/' + fileName;
|
|
134
|
+
e(`"${getFileOpenExe(fileName)}" "${configFile}"`)
|
|
119
135
|
return
|
|
120
136
|
}
|
|
121
137
|
|
|
@@ -204,7 +220,8 @@ async function fileLine(name) {
|
|
|
204
220
|
}
|
|
205
221
|
let tempDir = getLibDataDir() + "/ooa"
|
|
206
222
|
mkdir(tempDir)
|
|
207
|
-
let
|
|
223
|
+
let fileName = `f ${toJsirFileName(name)}`
|
|
224
|
+
let workFile = `${tempDir}/${fileName}`;
|
|
208
225
|
if (!_fs.existsSync(workFile)) {
|
|
209
226
|
_fs.writeFileSync(workFile, '');
|
|
210
227
|
}
|
|
@@ -212,7 +229,7 @@ async function fileLine(name) {
|
|
|
212
229
|
_fs.unlinkSync(workFile)
|
|
213
230
|
await sleep(1000)
|
|
214
231
|
_fs.writeFileSync(workFile, text)
|
|
215
|
-
e(`
|
|
232
|
+
e(`"${getFileOpenExe(fileName)}" "${workFile}"`)
|
|
216
233
|
let watcher = _Chokidar.watch([workFile]);
|
|
217
234
|
|
|
218
235
|
text = trim(text)
|
|
@@ -329,13 +346,26 @@ function _nextLine(callback, preStr, hidden, resolve) {
|
|
|
329
346
|
input: process.stdin,
|
|
330
347
|
output: process.stdout
|
|
331
348
|
})
|
|
349
|
+
_rl.on("SIGINT", async () => {
|
|
350
|
+
if (_noAppendNextLine) {
|
|
351
|
+
process.exit(0);
|
|
352
|
+
} else {
|
|
353
|
+
_haveWrapperInput = true;
|
|
354
|
+
_rl.clearLine(0)
|
|
355
|
+
nextLine();
|
|
356
|
+
}
|
|
357
|
+
});
|
|
332
358
|
}
|
|
333
359
|
_haveStartRead = true
|
|
334
360
|
_haveWrapperInput = false
|
|
335
361
|
|
|
336
362
|
_rl._writeToOutput = function _writeToOutput(stringToWrite){
|
|
337
363
|
if(hidden && stringToWrite.indexOf("\n") === -1 && stringToWrite !== promitStr){
|
|
338
|
-
|
|
364
|
+
if (stringToWrite.indexOf(promitStr) === -1) {
|
|
365
|
+
_rl.output.write("*");
|
|
366
|
+
} else {
|
|
367
|
+
_rl.output.write(promitStr + stringToWrite.replace(promitStr, '').replace(/[\s\S]/g, '*'));
|
|
368
|
+
}
|
|
339
369
|
} else {
|
|
340
370
|
_rl.output.write(stringToWrite);
|
|
341
371
|
}
|
|
@@ -363,10 +393,9 @@ function _nextLine(callback, preStr, hidden, resolve) {
|
|
|
363
393
|
let promitStr = (preStr
|
|
364
394
|
|| ((callback && callback !== wrapperInput) ? "-> ":"")
|
|
365
395
|
|| [Object.values(global.$tips).filter(i => String(i)).join(','), repoTip].filter(i => i).join('-') + `> `)
|
|
366
|
-
|
|
367
|
-
|
|
396
|
+
promitStr = '\x1B[32m' + promitStr + '\x1B[39m'
|
|
397
|
+
_rl.setPrompt(promitStr);
|
|
368
398
|
_rl.prompt()
|
|
369
|
-
process.stdout.write('\x1B[39m')
|
|
370
399
|
}
|
|
371
400
|
|
|
372
401
|
async function nextText(callback, preStr, hidden) {
|
|
@@ -409,7 +438,8 @@ function dealSourceCmds() {
|
|
|
409
438
|
}
|
|
410
439
|
|
|
411
440
|
async function save(args) {
|
|
412
|
-
let
|
|
441
|
+
let name = toJsirFileName(args.join(' '))
|
|
442
|
+
let path = `${_home}/${name}`
|
|
413
443
|
if (_fs.existsSync(path)) {
|
|
414
444
|
warn('already exist')
|
|
415
445
|
return
|
|
@@ -432,8 +462,12 @@ console.log($args)`;
|
|
|
432
462
|
resp = await getCbText();
|
|
433
463
|
}
|
|
434
464
|
_fs.writeFileSync(path, resp)
|
|
435
|
-
e(`
|
|
465
|
+
e(`"${getFileOpenExe(name)}" "${path}"`)
|
|
436
466
|
info(`${path} created`)
|
|
467
|
+
|
|
468
|
+
if (name.split(/\s+/)[0] === 'i') {
|
|
469
|
+
await dealInitData();
|
|
470
|
+
}
|
|
437
471
|
}
|
|
438
472
|
|
|
439
473
|
function rename(old, _new) {
|
|
@@ -465,10 +499,18 @@ function hisToCmdMap() {
|
|
|
465
499
|
_cmdMap = cmdMap
|
|
466
500
|
}
|
|
467
501
|
|
|
468
|
-
function listCmd() {
|
|
502
|
+
function listCmd(onlyRepo = false) {
|
|
503
|
+
let jsLibDir;
|
|
504
|
+
if (onlyRepo) {
|
|
505
|
+
jsLibDir = trim(getConfig("jsLibSource"))
|
|
506
|
+
if (!(jsLibDir && _fs.existsSync(jsLibDir))) {
|
|
507
|
+
jsLibDir = null;
|
|
508
|
+
warn('require config.jsLibSource')
|
|
509
|
+
}
|
|
510
|
+
}
|
|
469
511
|
let newCmdMap = {}
|
|
470
512
|
let items = Object.values(_cmdMap)
|
|
471
|
-
.filter(i => _fs.existsSync(_home + "/" + i))
|
|
513
|
+
.filter(i => _fs.existsSync(_home + "/" + i) && (!jsLibDir || _fs.existsSync(jsLibDir + "/" + i)))
|
|
472
514
|
.sort((a,b) => {
|
|
473
515
|
return String(_types[a.split(/\s+/)[0]]) >= String(_types[b.split(/\s+/)[0]]) ? 1:-1
|
|
474
516
|
})
|
|
@@ -649,8 +691,8 @@ async function wrapperInput(str) {
|
|
|
649
691
|
if (_cmdMap[strs[0]]) {
|
|
650
692
|
putHis(_cmdMap[strs[0]])
|
|
651
693
|
let path = _home + '/' + _cmdMap[strs[0]]
|
|
652
|
-
let fileName =
|
|
653
|
-
let firstName =
|
|
694
|
+
let fileName = trim(_cmdMap[strs[0]]);
|
|
695
|
+
let firstName = fileName.split(/\s+/)[0]
|
|
654
696
|
if (firstName === 'f') {
|
|
655
697
|
await fileLine(fileName.replace(/^\s*f\s*/, ''))
|
|
656
698
|
} else if (firstName !== 'e') {
|
|
@@ -730,6 +772,9 @@ async function dealKeyword(str, strs, fstr, ostr) {
|
|
|
730
772
|
newName = toJsirFileName(newName)
|
|
731
773
|
if (rename(_home + '/' + name, _home + '/' + newName)) {
|
|
732
774
|
info(`${_home + '/' + newName} renamed`)
|
|
775
|
+
if (newName.split(/\s+/)[0] === 'i') {
|
|
776
|
+
await dealInitData()
|
|
777
|
+
}
|
|
733
778
|
}
|
|
734
779
|
let jsLibDir = trim(getConfig("jsLibSource"))
|
|
735
780
|
if (jsLibDir && _fs.existsSync(jsLibDir)) {
|
|
@@ -774,6 +819,9 @@ async function dealKeyword(str, strs, fstr, ostr) {
|
|
|
774
819
|
}
|
|
775
820
|
}
|
|
776
821
|
info(`${name} pulled`)
|
|
822
|
+
if (name.split(/\s+/)[0] === 'i') {
|
|
823
|
+
await dealInitData()
|
|
824
|
+
}
|
|
777
825
|
} else {
|
|
778
826
|
warn('require config.jsLibSource')
|
|
779
827
|
}
|
|
@@ -789,6 +837,9 @@ async function dealKeyword(str, strs, fstr, ostr) {
|
|
|
789
837
|
mkdir(cmdsDir)
|
|
790
838
|
_fs.writeFileSync(cmdsDir + "/" + name, String(_fs.readFileSync(_home + '/' + name)))
|
|
791
839
|
info(`${name} pushed`)
|
|
840
|
+
if (name.split(/\s+/)[0] === 'i') {
|
|
841
|
+
await dealInitData()
|
|
842
|
+
}
|
|
792
843
|
} else {
|
|
793
844
|
warn('require config.jsLibSource')
|
|
794
845
|
}
|
|
@@ -799,7 +850,7 @@ async function dealKeyword(str, strs, fstr, ostr) {
|
|
|
799
850
|
warn("no items")
|
|
800
851
|
} else {
|
|
801
852
|
let path = _home + '/' + name
|
|
802
|
-
e(`
|
|
853
|
+
e(`"${getFileOpenExe(name)}" "${path}"`)
|
|
803
854
|
}
|
|
804
855
|
} else if (/^c\d*$/.test(fstr)) {
|
|
805
856
|
let name = _cmdMap[trim(fstr.replace(/^c/, ''))]
|
|
@@ -825,6 +876,11 @@ async function dealKeyword(str, strs, fstr, ostr) {
|
|
|
825
876
|
listCmd()
|
|
826
877
|
} else if (fstr === 'f') {
|
|
827
878
|
await fileLine(trim(ostr.join(' ')))
|
|
879
|
+
} else if (fstr === '%') {
|
|
880
|
+
listCmd(true)
|
|
881
|
+
} else if (fstr === 'q') {
|
|
882
|
+
console.log("Bye!")
|
|
883
|
+
process.exit(0)
|
|
828
884
|
} else {
|
|
829
885
|
await save(strs)
|
|
830
886
|
}
|
|
@@ -906,8 +962,7 @@ function filterCmd(args){
|
|
|
906
962
|
if (!isJsirFileName(file)) {
|
|
907
963
|
continue
|
|
908
964
|
}
|
|
909
|
-
|
|
910
|
-
isArgsMatch(fileName, args, () => {
|
|
965
|
+
isArgsMatch(file, args, () => {
|
|
911
966
|
if (Object.values(cmdMap).indexOf(file) === -1) {
|
|
912
967
|
cmdMap[i] = file
|
|
913
968
|
i ++
|
package/ethWeb.js
CHANGED
|
@@ -64,10 +64,10 @@ async function _ethBatchQuery(calls = [], web3) {
|
|
|
64
64
|
return await Promise.all(pros);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
async function ethBatchQuery(calls = [], web3, batchNum = 49, asyncNum = 33) {
|
|
67
|
+
async function ethBatchQuery(calls = [], web3, batchNum = 49, asyncNum = 33, useWebReq = false) {
|
|
68
68
|
web3 = web3 || global.web3;
|
|
69
69
|
let chainId = global.chainId || await web3.eth.getChainId()
|
|
70
|
-
if (batchCallAddressMap[chainId]) {
|
|
70
|
+
if (batchCallAddressMap[chainId] && !useWebReq) {
|
|
71
71
|
return await ethBatchQuery_(calls, web3, batchNum, asyncNum)
|
|
72
72
|
} else {
|
|
73
73
|
let transResult = result => {
|
|
@@ -113,7 +113,7 @@ async function ethBatchQuery(calls = [], web3, batchNum = 49, asyncNum = 33) {
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
async function ethBatchQuery_(calls = [], web3, batchNum
|
|
116
|
+
async function ethBatchQuery_(calls = [], web3, batchNum, asyncNum) {
|
|
117
117
|
if (calls.length <= 0) {
|
|
118
118
|
return []
|
|
119
119
|
}
|
|
@@ -187,9 +187,24 @@ async function initSender(web3, wallet, froms, resetNum) {
|
|
|
187
187
|
senderNonce[aIndex] = Number(await web3.eth.getTransactionCount(walletGet(wallet, aIndex).address)) -1
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
let sender = (txObject) => {
|
|
190
|
+
let sender = async (txObject) => {
|
|
191
191
|
let aIndex = froms[randomInt(froms.length) - 1]
|
|
192
192
|
let adInfo = walletGet(wallet, aIndex)
|
|
193
|
+
|
|
194
|
+
if (!(txObject.gasLimit || txObject.gas)) {
|
|
195
|
+
try {
|
|
196
|
+
let gas = await web3.eth.estimateGas({
|
|
197
|
+
from: adInfo.address,
|
|
198
|
+
to: txObject.to,
|
|
199
|
+
value: txObject.value,
|
|
200
|
+
data: txObject.data
|
|
201
|
+
})
|
|
202
|
+
txObject.gasLimit = gas + 10000;
|
|
203
|
+
} catch (e) {
|
|
204
|
+
return [Promise.reject(e), {}, aIndex]
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
193
208
|
if (senderBlock[aIndex]) {
|
|
194
209
|
return []
|
|
195
210
|
}
|
|
@@ -243,6 +258,21 @@ async function initSenderWithKeys(web3, privateKeys, resetNum) {
|
|
|
243
258
|
let sender = async (txObject) => {
|
|
244
259
|
let key = privateKeys[randomInt(privateKeys.length) - 1]
|
|
245
260
|
let adds = keyMap[key]
|
|
261
|
+
|
|
262
|
+
if (!(txObject.gasLimit || txObject.gas)) {
|
|
263
|
+
try {
|
|
264
|
+
let gas = await web3.eth.estimateGas({
|
|
265
|
+
from: adds,
|
|
266
|
+
to: txObject.to,
|
|
267
|
+
value: txObject.value,
|
|
268
|
+
data: txObject.data
|
|
269
|
+
})
|
|
270
|
+
txObject.gasLimit = gas + 10000;
|
|
271
|
+
} catch (e) {
|
|
272
|
+
return [Promise.reject(e), {}, adds]
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
246
276
|
if (senderBlock[adds]) {
|
|
247
277
|
return []
|
|
248
278
|
}
|
|
@@ -288,7 +318,7 @@ function txnSign(txObject, privateKey) {
|
|
|
288
318
|
let params = {
|
|
289
319
|
nonce: web3.utils.toHex(txObject.nonce),
|
|
290
320
|
gasPrice: web3.utils.toHex(txObject.gasPrice),
|
|
291
|
-
gasLimit: web3.utils.toHex(txObject.gasLimit),
|
|
321
|
+
gasLimit: web3.utils.toHex(txObject.gasLimit || txObject.gas),
|
|
292
322
|
to: txObject.to,
|
|
293
323
|
value: web3.utils.toHex(txObject.value),
|
|
294
324
|
data: txObject.data
|
|
@@ -485,7 +515,7 @@ function getPairAmtNoFee(a, b, baseAmt) {
|
|
|
485
515
|
}
|
|
486
516
|
|
|
487
517
|
let tokenMapLoaded = {}
|
|
488
|
-
async function getTokenMap(tokens, web3) {
|
|
518
|
+
async function getTokenMap(tokens, web3, batchNum, asyncNum) {
|
|
489
519
|
web3 = web3 || global.web3;
|
|
490
520
|
let chainId = global.chainId || await web3.getChainId()
|
|
491
521
|
if (!tokenMapCache[chainId]) {
|
|
@@ -524,7 +554,7 @@ async function getTokenMap(tokens, web3) {
|
|
|
524
554
|
name: 'decimals'
|
|
525
555
|
})
|
|
526
556
|
}
|
|
527
|
-
let results = await ethBatchQuery(calls, web3,
|
|
557
|
+
let results = await ethBatchQuery(calls, web3, batchNum, asyncNum)
|
|
528
558
|
for(let i = 0; i<results.length; i+=3) {
|
|
529
559
|
let token = calls[i].address
|
|
530
560
|
try {
|
|
@@ -785,7 +815,7 @@ async function ethWrite(sender, address, {data, abi, method, args, gasPrice, gas
|
|
|
785
815
|
let avgGasPrice = await cacheFn('getGasPrice', async () => await web3.eth.getGasPrice(), 1000 * 5)
|
|
786
816
|
let txObject = {
|
|
787
817
|
gasPrice: gasPrice ? gasPrice * 1000000000 : avgGasPrice,
|
|
788
|
-
gasLimit: gasLimit
|
|
818
|
+
gasLimit: gasLimit,
|
|
789
819
|
to: address,
|
|
790
820
|
value
|
|
791
821
|
}
|
|
@@ -804,16 +834,19 @@ async function ethWrite(sender, address, {data, abi, method, args, gasPrice, gas
|
|
|
804
834
|
console.log("No address to used")
|
|
805
835
|
return {}
|
|
806
836
|
}
|
|
807
|
-
|
|
837
|
+
msg = trim(msg)
|
|
838
|
+
msg = msg ? msg + ' ':''
|
|
839
|
+
console.log(`${msg}send ${signedTx.hash} ${txObject.gasPrice/1000000000}g`)
|
|
808
840
|
result = result.then(resp => {
|
|
809
|
-
console.log('\x1B[32m%s\x1B[39m', `${msg}
|
|
841
|
+
console.log('\x1B[32m%s\x1B[39m', `${msg}${signedTx.hash} 交易成功`)
|
|
810
842
|
return true
|
|
811
843
|
}).catch(async e => {
|
|
812
|
-
console.log('\x1B[35m%s\x1B[39m', `${msg}
|
|
844
|
+
console.log('\x1B[35m%s\x1B[39m', `${msg}${signedTx.hash} 交易失败`)
|
|
813
845
|
if (onError) {
|
|
814
846
|
return await onError(e)
|
|
815
847
|
} else {
|
|
816
848
|
console.error(e.toString().split("\n")[0])
|
|
849
|
+
$log(new Error(e.stack).stack);
|
|
817
850
|
return false
|
|
818
851
|
}
|
|
819
852
|
})
|
|
@@ -991,7 +1024,7 @@ async function batchTranfer(ethTranserWrite, token, froms, tos, min, max) {
|
|
|
991
1024
|
for(let from of froms) {
|
|
992
1025
|
let sender = await newSender(from)
|
|
993
1026
|
for(let to of tos) {
|
|
994
|
-
let fromAddress = String(
|
|
1027
|
+
let fromAddress = String(from).startsWith('0x') ? from:global.$wallet.getAddress(from);
|
|
995
1028
|
let toAddress = String(to).startsWith('0x') ? to:global.$wallet.getAddress(to);
|
|
996
1029
|
|
|
997
1030
|
if (token) {
|
|
@@ -1001,10 +1034,10 @@ async function batchTranfer(ethTranserWrite, token, froms, tos, min, max) {
|
|
|
1001
1034
|
if (Number(tb) >= min) {
|
|
1002
1035
|
continue
|
|
1003
1036
|
}
|
|
1004
|
-
|
|
1037
|
+
let transferAmt = bMin(max, tb)
|
|
1038
|
+
if (Number(fb) < Number(transferAmt)) {
|
|
1005
1039
|
continue
|
|
1006
1040
|
}
|
|
1007
|
-
let transferAmt = bMin(max, tb)
|
|
1008
1041
|
let fmtTransferAmt = exDcmNum(transferAmt, -decimals).toString()
|
|
1009
1042
|
pros.push(ethTranserWrite(sender, token, {
|
|
1010
1043
|
abi: erc20Abi,
|
|
@@ -1019,10 +1052,10 @@ async function batchTranfer(ethTranserWrite, token, froms, tos, min, max) {
|
|
|
1019
1052
|
if (Number(tb) >= min) {
|
|
1020
1053
|
continue
|
|
1021
1054
|
}
|
|
1022
|
-
|
|
1055
|
+
let transferAmt = bMin(max, tb)
|
|
1056
|
+
if (Number(fb) < Number(transferAmt)) {
|
|
1023
1057
|
continue
|
|
1024
1058
|
}
|
|
1025
|
-
let transferAmt = bMin(max, tb)
|
|
1026
1059
|
let fmtTransferAmt = exDcmNum(transferAmt, -decimals).toString()
|
|
1027
1060
|
pros.push(ethTranserWrite(sender, toAddress, {
|
|
1028
1061
|
value: transferAmt,
|
|
@@ -1048,7 +1081,7 @@ async function batchCollect(ethTranserWrite, token, froms, to, remain) {
|
|
|
1048
1081
|
for(let from of froms) {
|
|
1049
1082
|
let sender = await newSender(from)
|
|
1050
1083
|
|
|
1051
|
-
let fromAddress = String(from).startsWith('0x') ?
|
|
1084
|
+
let fromAddress = String(from).startsWith('0x') ? from:global.$wallet.getAddress(from);
|
|
1052
1085
|
let toAddress = String(to).startsWith('0x') ? to:global.$wallet.getAddress(to);
|
|
1053
1086
|
|
|
1054
1087
|
if (token) {
|
|
@@ -1104,26 +1137,6 @@ async function getContractJson(address) {
|
|
|
1104
1137
|
return JSON.parse(String(fs.readFileSync(obj[address]['abiPath'])))
|
|
1105
1138
|
}
|
|
1106
1139
|
}
|
|
1107
|
-
|
|
1108
|
-
const agent = new https.Agent({
|
|
1109
|
-
rejectUnauthorized: false
|
|
1110
|
-
});
|
|
1111
|
-
let home = getLibDataDir() + '/abi'
|
|
1112
|
-
mkdir(home)
|
|
1113
|
-
let file = `${home}/${address}`
|
|
1114
|
-
if (fs.existsSync(file)) {
|
|
1115
|
-
let str = String(fs.readFileSync(file))
|
|
1116
|
-
let strs = str.split('\n').map(item => trim(item)).filter(item => item)
|
|
1117
|
-
return {abi: JSON.parse(strs[1])}
|
|
1118
|
-
}
|
|
1119
|
-
return got(`https://api-cn.etherscan.com/api?module=contract&action=getabi&address=${address}`,
|
|
1120
|
-
{ httpsAgent: agent }).then(resp => {
|
|
1121
|
-
if (resp.data.status !== '1') {
|
|
1122
|
-
return ''
|
|
1123
|
-
}
|
|
1124
|
-
fs.writeFileSync(file, `${Date.now()}\n${resp.data.result}`)
|
|
1125
|
-
return {abi: JSON.parse(resp.data.result)}
|
|
1126
|
-
})
|
|
1127
1140
|
}
|
|
1128
1141
|
|
|
1129
1142
|
async function transferToken(ethTranserWrite, sender, address, token, amt, msg) {
|
|
@@ -1229,5 +1242,6 @@ module.exports = {
|
|
|
1229
1242
|
getTokenBal,
|
|
1230
1243
|
transferToken,
|
|
1231
1244
|
tokenApprove,
|
|
1232
|
-
txnInputReplacer
|
|
1245
|
+
txnInputReplacer,
|
|
1246
|
+
abiDecoder
|
|
1233
1247
|
}
|
package/index.js
CHANGED
|
@@ -129,7 +129,8 @@ const {
|
|
|
129
129
|
getTokenBal,
|
|
130
130
|
transferToken,
|
|
131
131
|
tokenApprove,
|
|
132
|
-
txnInputReplacer
|
|
132
|
+
txnInputReplacer,
|
|
133
|
+
abiDecoder
|
|
133
134
|
} = require('./ethWeb')
|
|
134
135
|
|
|
135
136
|
module.exports = {
|
|
@@ -259,5 +260,6 @@ module.exports = {
|
|
|
259
260
|
warn,
|
|
260
261
|
error,
|
|
261
262
|
txnInputReplacer,
|
|
262
|
-
parseSteps
|
|
263
|
+
parseSteps,
|
|
264
|
+
abiDecoder
|
|
263
265
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsir",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"author": "",
|
|
28
28
|
"license": "ISC",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@ethersproject/abi": "
|
|
31
|
-
"abi-decoder": "^2.
|
|
30
|
+
"@ethersproject/abi": "^5.5.0",
|
|
31
|
+
"abi-decoder": "^2.4.0",
|
|
32
32
|
"address": "^1.1.2",
|
|
33
33
|
"axios": "^0.20.0",
|
|
34
34
|
"bignumber.js": "^9.0.0",
|
|
@@ -36,16 +36,16 @@
|
|
|
36
36
|
"console.table": "^0.10.0",
|
|
37
37
|
"dayjs": "^1.10.4",
|
|
38
38
|
"ethereumjs-tx": "^1.3.7",
|
|
39
|
-
"ethereumjs-util": "
|
|
39
|
+
"ethereumjs-util": "^7.1.3",
|
|
40
40
|
"ethers": "^5.1.0",
|
|
41
41
|
"global-dirs": "^3.0.0",
|
|
42
|
-
"keccak": "
|
|
42
|
+
"keccak": "^3.0.2",
|
|
43
43
|
"md5": "^2.3.0",
|
|
44
44
|
"pad": "^3.2.0",
|
|
45
45
|
"randomhex": "^0.1.5",
|
|
46
46
|
"server": "^1.0.30",
|
|
47
47
|
"urlencode": "^1.1.0",
|
|
48
|
-
"web3": "^1.
|
|
49
|
-
"web3-eth-contract": "
|
|
48
|
+
"web3": "^1.6.1",
|
|
49
|
+
"web3-eth-contract": "^1.6.1"
|
|
50
50
|
}
|
|
51
51
|
}
|
package/sol.js
CHANGED
|
@@ -107,13 +107,13 @@ async function exeMethods(web3, deployInfo, sol, method, text) {
|
|
|
107
107
|
deployInfo.address);
|
|
108
108
|
text = text + '\n' + fs.readFileSync(deployInfo.abiPath.replace('.json', '.sol').replace('/bin', ''))
|
|
109
109
|
|
|
110
|
-
let args = reget(text, new RegExp(`@${method}
|
|
111
|
-
let sendArgs = reget(text, new RegExp(`@${method}
|
|
112
|
-
let callArgs = reget(text, new RegExp(`@${method}
|
|
113
|
-
let value = reget(text, new RegExp(`@${method}
|
|
114
|
-
let gas = reget(text, new RegExp(`@${method}
|
|
115
|
-
let from = reget(text, new RegExp(`@${method}
|
|
116
|
-
let expect = reget(text, new RegExp(`@${method}
|
|
110
|
+
let args = reget(text, new RegExp(`@${method}\.args[ :=]+(.*)`))
|
|
111
|
+
let sendArgs = reget(text, new RegExp(`@${method}(\.send)`))
|
|
112
|
+
let callArgs = reget(text, new RegExp(`@${method}(\.call)`))
|
|
113
|
+
let value = reget(text, new RegExp(`@${method}\.value[ :=]+(.*)`));
|
|
114
|
+
let gas = reget(text, new RegExp(`@${method}\.gas[ :=]+(.*)`));
|
|
115
|
+
let from = reget(text, new RegExp(`@${method}\.from[ :=]+(.*)`));
|
|
116
|
+
let expect = reget(text, new RegExp(`@${method}\.expect[ :=]+(.*)`));
|
|
117
117
|
let action = 'call';
|
|
118
118
|
|
|
119
119
|
let fnStr = reget(text, new RegExp(`\\s+(function\\s+${method}\\s*\\([\\s\\S]*?)\\{`));
|
|
@@ -121,11 +121,9 @@ async function exeMethods(web3, deployInfo, sol, method, text) {
|
|
|
121
121
|
action = 'send'
|
|
122
122
|
}
|
|
123
123
|
if (callArgs) {
|
|
124
|
-
args = callArgs;
|
|
125
124
|
action = 'call'
|
|
126
125
|
}
|
|
127
126
|
if (sendArgs) {
|
|
128
|
-
args = sendArgs;
|
|
129
127
|
action = 'send'
|
|
130
128
|
}
|
|
131
129
|
|
package/util.js
CHANGED
|
@@ -811,8 +811,27 @@ function parseSteps(str) {
|
|
|
811
811
|
let result = []
|
|
812
812
|
for (let item of items) {
|
|
813
813
|
let ss = item.split('-').map(trim).filter(i => i)
|
|
814
|
+
let _len = result.length
|
|
815
|
+
let numReg = /^\d+$/
|
|
816
|
+
if (ss[0] && !numReg.test(ss[0])) {
|
|
817
|
+
result.push(ss[0]);
|
|
818
|
+
}
|
|
819
|
+
if (ss[1] && !numReg.test(ss[1])) {
|
|
820
|
+
result.push(ss[1]);
|
|
821
|
+
}
|
|
822
|
+
if (ss[2] && !numReg.test(ss[2])) {
|
|
823
|
+
result.push(ss[2]);
|
|
824
|
+
}
|
|
825
|
+
if (result.length > _len) {
|
|
826
|
+
continue
|
|
827
|
+
}
|
|
828
|
+
|
|
814
829
|
if (ss.length > 1) {
|
|
815
|
-
|
|
830
|
+
if (Number(ss[0]) > Number(ss[1])) {
|
|
831
|
+
result.push(...range(Number(ss[1]), Number(ss[0]), ss[2] ? Number(ss[2]):null))
|
|
832
|
+
} else {
|
|
833
|
+
result.push(...range(Number(ss[0]), Number(ss[1]), ss[2] ? Number(ss[2]):null))
|
|
834
|
+
}
|
|
816
835
|
} else {
|
|
817
836
|
result.push(Number(ss[0]))
|
|
818
837
|
}
|