-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (48 loc) · 1.21 KB
/
index.js
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
const RPC_URL = 'https://api.node.glif.io/'
const miners = [
'f02118066',
'f0142637',
'f02851470',
'f02365956',
'f02370792',
'f02035252',
'f02933563',
'f02933536'
]
console.log('FULL INFO FOR MINER', miners[0])
console.log(await rpc('Filecoin.StateMinerInfo', miners[0], null))
console.log('\n===\n')
for (const m of miners) {
const { PeerId } = await rpc('Filecoin.StateMinerInfo', m, null)
const found =
PeerId === '12D3KooW9pcSn5RbbAtG3A3PTzewM2JRongceqvWewHyGj7qp6Ha'
? 'FOUND: first advertisement'
: PeerId === '12D3KooWKa1NQKxveFmppQAjkHG8RGpjoQ2ivubeNuEUgZGgc2T6'
? 'FOUND: second advertisement'
: ''
console.log('miner: %s provider id: %s', m, PeerId, found)
}
/**
* @param {string} method
* @param {unknown[]} params
*/
async function rpc (method, ...params) {
const res = await fetch(RPC_URL, {
method: 'POST',
headers: {
'content-type': 'application/json',
accepts: 'application/json'
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method,
params
})
})
if (!res.ok) {
throw new Error(`JSON RPC failed with ${res.code}: ${await res.text()}`)
}
const body = await res.json()
return body.result
}