jsir 1.1.9 → 1.2.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 +12 -2
- package/ethWeb.js +41 -27
- package/index.js +4 -2
- package/package.json +1 -1
- package/sol.js +7 -9
package/cmd/ooa.js
CHANGED
|
@@ -487,10 +487,18 @@ function hisToCmdMap() {
|
|
|
487
487
|
_cmdMap = cmdMap
|
|
488
488
|
}
|
|
489
489
|
|
|
490
|
-
function listCmd() {
|
|
490
|
+
function listCmd(onlyRepo = false) {
|
|
491
|
+
let jsLibDir;
|
|
492
|
+
if (onlyRepo) {
|
|
493
|
+
jsLibDir = trim(getConfig("jsLibSource"))
|
|
494
|
+
if (!(jsLibDir && _fs.existsSync(jsLibDir))) {
|
|
495
|
+
jsLibDir = null;
|
|
496
|
+
warn('require config.jsLibSource')
|
|
497
|
+
}
|
|
498
|
+
}
|
|
491
499
|
let newCmdMap = {}
|
|
492
500
|
let items = Object.values(_cmdMap)
|
|
493
|
-
.filter(i => _fs.existsSync(_home + "/" + i))
|
|
501
|
+
.filter(i => _fs.existsSync(_home + "/" + i) && (!jsLibDir || _fs.existsSync(jsLibDir + "/" + i)))
|
|
494
502
|
.sort((a,b) => {
|
|
495
503
|
return String(_types[a.split(/\s+/)[0]]) >= String(_types[b.split(/\s+/)[0]]) ? 1:-1
|
|
496
504
|
})
|
|
@@ -856,6 +864,8 @@ async function dealKeyword(str, strs, fstr, ostr) {
|
|
|
856
864
|
listCmd()
|
|
857
865
|
} else if (fstr === 'f') {
|
|
858
866
|
await fileLine(trim(ostr.join(' ')))
|
|
867
|
+
} else if (fstr === '%') {
|
|
868
|
+
listCmd(true)
|
|
859
869
|
} else {
|
|
860
870
|
await save(strs)
|
|
861
871
|
}
|
package/ethWeb.js
CHANGED
|
@@ -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
|
|
@@ -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
|
})
|
|
@@ -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
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
|
|