-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkecca.html
109 lines (86 loc) · 3.5 KB
/
kecca.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
<html>
<head>
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/web3/1.7.4/web3.min.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="/driver/eth-session.js"></script>
</head>
<body>
<h2>Tools</h2>
<div id="tools">
<label style="display: inline-block; width: 6em">Start:</label>
<input id="start" name="start" type="text" value="2576102650" style="text-align: right" /><br />
<label style="display: inline-block; width: 6em">Interval:</label>
<input id="interval" name="interval" type="text" value="32000" style="text-align: right" /><br />
<label style="display: inline-block; width: 6em">Slot:</label>
<input id="slot" name="slot" type="text" value="4" style="text-align: right" /><br />
<label style="display: inline-block; width: 6em">Delay (ms):</label>
<input id="delay" name="delay" type="text" value="50" style="text-align: right" /><br />
<button id="process">Process</button>
<button id="stop">Stop</button><br />
<div id="tools-output"></div>
</div>
<h2>Logs</h2>
<div id="logs"></div>
<script>
let isRunning = false;
let minHash = null;
let minRes = null;
const session = new EthereumSession({
chain: EthereumSession.COMMON_CHAINS[1],
contractAddress: "0xdba31cDA9FD6428ec7a72aa4220BCe79C051CD9C",
contractABI: [{"inputs":[{"internalType":"uint256","name":"start","type":"uint256"},{"internalType":"uint256","name":"stop","type":"uint256"},{"internalType":"uint256","name":"slot","type":"uint256"}],"name":"minHashForRange","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"}]
});
const process = async () => {
if(isRunning)
return;
isRunning = true;
const startEl = document.getElementById('start');
const intervalEl = document.getElementById('interval');
const slotEl = document.getElementById('slot');
const delayEl = document.getElementById('delay');
const start = BigInt(startEl.value);
const interval = BigInt(intervalEl.value);
const slot = Number(slotEl.value);
const delay = Number(delayEl.value);
console.log({ delay });
if(await session.connectWeb3(true)){
for(let i = start; i < Number.MAX_SAFE_INTEGER; i += interval){
await new Promise(resolve => setTimeout(resolve, delay));
session.contract.methods.minHashForRange(i, i+interval, slot).call((err, res) => {
if(res){
const hash = BigInt(res[1]);
if(minHash === null){
minHash = hash;
minRes = res;
document.getElementById('logs').innerHTML += '<hr />'
+`${res[0]}: ${res[1]}`;
}
else if(hash < minHash){
minHash = hash;
minRes = res;
document.getElementById('logs').innerHTML += '<hr />'
+`${res[0].toLocaleString()}: ${res[1]}`;
}
startEl.value = i.toString();
}
else{
console.error(err);
}
});
if(!isRunning)
break;
}
}
};
const stop = () => {
isRunning = false;
};
window.addEventListener( 'DOMContentLoaded', () => {
document.getElementById('process').addEventListener('click', process);
document.getElementById('stop').addEventListener('click', stop);
});
</script>
</body>
</html>