-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistlocation.html
More file actions
69 lines (54 loc) · 2 KB
/
listlocation.html
File metadata and controls
69 lines (54 loc) · 2 KB
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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<meta charset="UTF-8">
<script src="https://unpkg.com/web3@latest/dist/web3.min.js"></script>
</head>
<body>
<h1>List of checkins to locations relative to HHS</h1>
<pre id="log" style="width:100%;height:200px"></pre>
<script type="text/javascript">
function log(str,...arguments) {
var logstr=arguments.toString();
document.getElementById("log").innerHTML +=str+" "+logstr+"\n";
}
var url = new URL(window.location.href);
var matchaddress = url.searchParams.get("address");
if (matchaddress) log(`Only showing address: ${matchaddress}`);
const web3 = new Web3( Web3.givenProvider );
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function processevent(object)
{
var ts='';
var decoded=web3.eth.abi.decodeParameters(['uint256'], object.data);
var txHash=object.transactionHash;
const trx = await web3.eth.getTransaction(txHash);
var from = trx.from;
if (matchaddress && matchaddress.toLowerCase() != from.toLowerCase())
return; // only show requested address
for (i = 0; i < 5; i++) {
blockobject= await web3.eth.getBlock(object.blockNumber);
if (!blockobject) {
await sleep(1000);
}
}
if (blockobject)
ts = new Date(blockobject.timestamp * 1000).toString(); // javascript uses milliseconds
var dist=decoded['0'];
log(`${from},${ts},${dist}`);
}
log('From (address), From (name), Date-time, Distance (meters)');
async function f() {
address="0x609F224c0c9405a1e7FD404114ca8A8606edC3a3";
var subscription= web3.eth.subscribe('logs', {fromBlock: '0x0',address: address} )
.on("data", processevent )
.on("changed", console.log)
.on("error",console.log)
}
f();
</script>
</body>
</html>