-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathindexbak.html
525 lines (431 loc) · 13.8 KB
/
indexbak.html
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<meta http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src * 'unsafe-inline'; style-src 'self' 'unsafe-inline'">
<link href="./styles.css" rel="stylesheet">
<title>Hello World!</title>
</head>
<body>
<div>
<h1>
NFT抢购程序
</h1>
<from id="network">
</from>
<form id="webtype">
<input type="radio" name="webnetwork" value="rpc" id="rpc" onclick='changewebnetwork(this.value)'>rpc地址</input>
<input type="radio" name="webnetwork" value="ws" id="ws" onclick='changewebnetwork(this.value)'>ws地址</input>
</form>
<br>
<input class="inputa" type="text" name="name" id="weburl" placeholder="服务地址" autofocus
value="https://mainnet.infura.io/v3/e1d0b7dea53643a194cadb6ed123f88e" />
<br>
<input type="button" onclick="initweb3()" class="btn btn-add" value="初始化web3"> </input>
</div>
<div style="width:500px;float:left ">
<labe>授权检查:</labe>
<label>代币合约地址:</label><input id="tokenaddresscheck" value="0xc778417E063141139Fce010982780140Aa0cD5Ab">
<br>
<label>授权地址:</label><input id="approveaddress" value="0x10ED43C718714eb63d5aA57B78B54704E256024E">
<br>
<label>gas:</label><input id="approvegas" value="5">
<br>
<label>gaslimint:</label><input id="approvegaslimit" value="420000">
<br>
<button onclick="oncheckapprove()">批量检查授权pancake可以使用该代币</button> <button onclick ="ceshi()" >查询主币</button>
</div>
<div style="width:500px; ">
<labe>监控价格:</labe>
<label>LP池子地址:</label><input id="lpaddress" value="0x09fe9db65c44b9610ab7dcd6853f887d2ade7e7f">
<br>
<label>代币地址:</label><input id="lptokenaddress" value="0x4a2c860cEC6471b9F5F5a336eB4F38bb21683c98">
<br>
<label>交易对地址(U地址):</label><input id="lptoken1address" value="0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d">
<br>
<button onclick="onstartmonitor()">监控价格</button> <button onclick="onstopmonitor()">停止监控</button>
</div>
<div style="width:500px">
<label>设置买入价:</label><input id="buyprice" value="9.8">
<br>
<label>设置买入数量(代币):</label><input id="buynumber" value="100">
<br>
<label>设置买入滑点:</label><input id="buylose" value="0.01">
<br>
<label>设置卖出价:</label><input id="sellprice" value="12">
<br>
<label>设置卖出数量(代币):</label><input id="sellnumber" value="100">
<br>
<label>设置卖出滑点:</label><input id="selllose" value="0.01">
<br>
<label>设置买卖gas:</label><input id="buygas" value="5">
<br>
<label>设置买卖gas limit:</label><input id="buygaslimit" value="420000">
<br>
<button onclick="onstartbuy()">开始自动买入卖出</button>
<button onclick="onstopbuy()">停止自动买入卖出</button>
</div>
<div id="log">
</div> <!-- You can also require other files to run in this process -->
<script src="./renderer.js"></script>
<style type="text/css">
.form-box {
width: 80%;
margin: 5px auto
}
.inputa {
width: 50%;
margin: 5px auto
}
.evmnetwork {
width: 100px;
margin-top: 2px
}
.btn-add {
width: 200px;
margin-top: 2px
}
</style>
</body>
<script>
// You can also require other files to run in this process
require('./renderer.js')
const electron = require('electron');
const { ipcRenderer } = electron;
function init() {
document.querySelector("#rpc").checked = true;
}
init();
var nownetwork = 'eth';
var chainid = 1;
//初始化web3
function initweb3() {
var webtype = "rpc";
const wschecked = document.querySelector('#ws').checked
if (wschecked) {
webtype = "ws";
}
const weburl = document.querySelector('#weburl').value;
var value = { webtype, weburl, chainid, nownetwork };
//console.log(value);
ipcRenderer.send('info:initweb3', value)
}
//查询智能合约功能
function queryContarct() {
const contractaddress = document.querySelector('#Contractaddress').value;
evmnetwork = getNetworkInfo(nownetwork);
if (evmnetwork[0]) {
var apiurl = evmnetwork[1].apiurl;
var value = { contractaddress, apiurl };
ipcRenderer.send('info:queryabi', value)
}
}
//抢购开始函数
function qianggou() {
const nftaddress = document.querySelector('#nftaddress').value;
const inputdata = document.querySelector('#inputdata').value;
const gas = document.querySelector('#qianggougas').value;
const gaslimit = document.querySelector('#qianggougaslimit').value;
const neth = document.querySelector('#neth').value;
value = { nftaddress, inputdata, gas, gaslimit, neth };
console.log("开始抢购,请稍等,或者去区块链网络查看:");
ipcRenderer.send('info:qianggou', value)
}
function ceshi() {
ipcRenderer.send('info:test', {})
}
function init1() {
var network = document.querySelector('#network');
var i = 0;
for (evmnetwork in evmnetworks) {
//console.log(evmnetwork);
var radio = document.createElement("input");
radio.type = "radio";
radio.name = "evmnetwork";
radio.value = evmnetworks[evmnetwork].network;
radio.id = evmnetworks[evmnetwork].network;
if (i == 0) {
radio.checked = true;
nownetwork = evmnetworks[evmnetwork].network;
chainid = evmnetworks[evmnetwork].chainid;
}
i++;
//radio.innerHTML = '"' + evmnetworks[evmnetwork].network + '"';
radio.onclick = function () { changenetwork(this.value) };
network.appendChild(radio);
var label = document.createElement("label");
label.innerHTML = evmnetworks[evmnetwork].network;
network.appendChild(label);
}
}
function changewebnetwork(webtype) {
//alert(webtype);
changenetwork(nownetwork);
}
function changenetwork(network) {
var result = getNetworkInfo(network);
if (result[0]) {
nownetwork = result[1].network;
chainid = result[1].chainid;
var webtype = "rpc";
const wschecked = document.querySelector('#ws').checked
if (wschecked) {
webtype = "ws";
}
if (webtype == "rpc") {
document.querySelector('#weburl').value = result[1].rpc;
}
else {
document.querySelector('#weburl').value = result[1].ws;
}
}
}
function getNetworkInfo(network) {
for (evmnetwork of evmnetworks) {
//console.log(evmnetwork);
if (network == evmnetwork.network) {
return [true, evmnetwork];
}
}
return [false, "false"];
}
init1();
ipcRenderer.on('info:initweb3', (e, value) => {
//console.log(value)
if (value.result) {
console.log("initweb3成功");
}
else {
console.log("initweb3失败");
}
});
var abi = null;
ipcRenderer.on('info:queryabi', (e, value) => {
console.log(value)
if (value.result[0] == true) {
console.log("智能合约查询成功")
abi = value.result;
}
else {
abi = null;
}
});
function cleanchild(selecthtml) {
while (true) {
try {
selecthtml.removeChild(selecthtml.childNodes[0]);
}
catch (e) {
break;
}
}
}
function readfunction(value) {
//debugger;
var selecthtml = document.querySelector('#fangfa');
if (selecthtml != null) {
cleanchild(selecthtml)
}
else {
return;
}
if (abi == null) {
return;
}
var viewmap = null;
var typename = "view"
if (value == "view") {
viewmap = abi[1];
typename = "view";
}
else if (value == "nonpayable") {
viewmap = abi[2];
typename = "nonpayable";
}
else if (value == "payable") {
viewmap = abi[3];
typename = "payable";
}
viewmap.forEach(element => {
var fname = element.name;
var option = document.createElement("option");
option.value = typename;
option.id = fname;
option.innerHTML = fname;
//option.onclick = function () { changefunction(this.value,this.id) };
selecthtml.appendChild(option);
});
}
function changefunction(selecthtml) {
//debugger;
var option = selecthtml.options[selecthtml.selectedIndex];
console.log(option.value)
changefunctionEX(option.value, option.id);
}
function transpara(input) {
type = input.name;
value = input.value;
id = input.id;
if (type == "bool") {
if (value.toLowerCase() == "ture" || value == "1") {
return true;
}
else if (value.toLowerCase() == "false" || value == "0") {
return false;
}
else {
console("错误:" + id + "输入的参数不匹配");
return "error";
}
}
else if (type == "address") {
if (value.indexOf("0x") == -1) {
console("错误:" + id + "输入的参数不匹配");
return "error";
}
else {
return value;
}
}
else {
return value;
}
}
function exce() {
var paralist = document.querySelector('#paralist').getElementsByTagName("input")
var okvalue = [];
var tijiao = true;
for (i = 0; i < paralist.length; i++) {
var result = transpara(paralist[i])
if (result != "error")
okvalue.push(result)
else
tijiao = false;
}
if (tijiao) {
//给后台提交数组
if (useabi != null) {
const nftaddress = document.querySelector('#nftaddress').value;
const gas = document.querySelector('#qianggougas').value;
const gaslimit = document.querySelector('#qianggougaslimit').value;
const neth = document.querySelector('#neth').value;
debugger;
value = { useabi, okvalue, nftaddress, gas, gaslimit, neth };
ipcRenderer.send('info:abishiyong', value)
}
}
}
var useabi = null;
function changefunctionEX(name, value) {
var viewmap = null;
if (name == "view") {
viewmap = abi[1];
}
else if (name == "nonpayable") {
viewmap = abi[2];
}
else if (name == "payable") {
viewmap = abi[3];
}
if (viewmap != null) {
var valueabi = viewmap.get(value);
if (valueabi != null) {
console.log(valueabi);
var inputs = valueabi.inputs;
useabi = valueabi;
var selecthtml = document.querySelector('#paralist');
if (selecthtml != null) {
cleanchild(selecthtml)
}
else {
return;
}
inputs.forEach(element => {
var aname = document.createElement('a');
aname.innerHTML = element.name + "(" + element.type + ")";
selecthtml.appendChild(aname)
var input = document.createElement('input');
input.name = element.type;
input.id = element.name;
selecthtml.appendChild(input);
selecthtml.appendChild(document.createElement('BR'));
});
}
else {
useabi = null;
}
}
}
ipcRenderer.on('info:msg', (e, value) => {
console.log( value)
});
// 检查代币是否授权,没有授权直接授权
function oncheckapprove()
{
const tokenaddresscheck = document.querySelector('#tokenaddresscheck').value;
const approveaddress = document.querySelector('#approveaddress').value;
const approvegas = document.querySelector('#approvegas').value;
const approvegaslimit = document.querySelector('#approvegaslimit').value;
value = { tokenaddresscheck, approveaddress,approvegas,approvegaslimit };
ipcRenderer.send('info:checkapprove', value)
}
//监控价格
function onstartmonitor()
{
const lpaddress = document.querySelector('#lpaddress').value;
const lptokenaddress = document.querySelector('#lptokenaddress').value;
const lptoken1address = document.querySelector('#lptoken1address').value;
value = { lpaddress, lptokenaddress,lptoken1address };
ipcRenderer.send('info:listenprice', value)
}
function onstopmonitor()
{
ipcRenderer.send('info:stoplistenprice', {})
}
//开始自动买入卖出
function onstartbuy()
{
var buyprice = document.querySelector('#buyprice').value;
var buynumber = document.querySelector('#buynumber').value;
var buylose = document.querySelector('#buylose').value;
var sellprice = document.querySelector('#sellprice').value;
var sellnumber = document.querySelector('#sellnumber').value;
var selllose = document.querySelector('#selllose').value;
var buygas = document.querySelector('#buygas').value;
var buygaslimit = document.querySelector('#buygaslimit').value;
var pancakeaddress = document.querySelector('#approveaddress').value;
var value = {buyprice,buynumber,buylose,sellprice,sellnumber,selllose,buygas,buygaslimit,pancakeaddress}
ipcRenderer.send('info:startbuy', value)
}
function onstopbuy()
{
ipcRenderer.send('info:stopbuy', {})
}
function getnowtime()
{
dt = new Date();
var y = dt.getFullYear();
var mt = dt.getMonth() + 1;
var day = dt.getDate();
var h = dt.getHours(); //获取时
var m = dt.getMinutes(); //获取分
var s = dt.getSeconds(); //获取秒
var nowtimet = '当前时间:' + y + '年' + mt + '月' + day + '-' + h + '时' + m + '分' + s + '秒:';
return nowtimet;
}
(function () {
var old = console.log;
var logger = document.getElementById('log');
console.log = function (message) {
var nowtime = (Date.now());
if (typeof message == 'object') {
logger.innerHTML += getnowtime() + (JSON && JSON.stringify ? JSON.stringify(message) : message) + '<br />';
} else {
logger.innerHTML += getnowtime() + message + '<br />';
}
}
})();
</script>
</html>