-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
78 lines (70 loc) · 2.99 KB
/
api.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* eslint-disable max-params */
/* eslint-disable no-prototype-builtins */
const fetch = require('node-fetch-retry');
const baseIdena = 'https://api.idena.org/'
const get = (base, endpoint, authorization) => fetch(base + endpoint, {
method: 'GET',
retry: 5,
pause: 30000,
headers: {
accept: 'application/json, text/plain, */*',
authorization,
'accept-encoding': 'gzip',
'user-agent': 'okhttp/3.12.1',
Referer: 'https://scan.idena.io/'
}
})
.then((response) => response.json())
.then((response) => response.hasOwnProperty('result') ? response.result : response)
.catch((err) => err)
const post = (base, endpoint, authorization, body) => fetch(base + endpoint, {
method: 'POST',
retry: 5,
pause: 30000,
headers: {
accept: 'application/json, text/plain, */*',
authorization,
'content-type': 'application/json;charset=utf-8',
'accept-encoding': 'gzip',
'user-agent': 'okhttp/3.12.1',
Referer: 'https://scan.idena.io/'
},
body: JSON.stringify(body)
})
.then((response) => response.json())
.then((response) => response.hasOwnProperty('result') ? response.result : response)
.catch((err) => err)
const getIdentity = (address) => get(baseIdena, `api/identity/${address}`)
const getPool = (address) => get(baseIdena, `api/pool/${address}`)
const getDelegators = (address) => get(baseIdena, `api/pool/${address}/delegators?limit=30`)
const getDelegatorRewards = (epoch, address) => get(baseIdena, `/api/epoch/${epoch}/address/${address}/delegateeRewards?limit=30`)
const getDelegatorTotalRewards = (address) => get(baseIdena, `/api/address/${address}/delegateeTotalRewards?limit=30`)
const getEpochRewards = (address) => get(baseIdena, `api/identity/${address}/epochrewards?limit=30`)
const getPenalties = (address) => get(baseIdena, `api/identity/${address}/penalties?limit=30`)
const getBalanceChanges = (address) => get(baseIdena, `api/identity/${address}/balance/changes?limit=30`)
const getTxs = (address) => get(baseIdena, `api/identity/${address}/txs?limit=30`)
const getEpochIdentity = (epoch, address) => get(baseIdena, `api/epoch/${epoch}/identity/${address}`)
const getEpoch = (epoch) => get(baseIdena, `api/epoch/${epoch}`)
const getLastEpoch = () => get(baseIdena, 'api/epoch/last')
const getOnlineMinners = () => get(baseIdena, 'api/onlineminers/count')
const getOnlineIdentities = () => get(baseIdena, 'api/onlineidentities/count')
const getIdenaPrice = () => get('https://api.coingecko.com/', 'api/v3/simple/price?ids=idena&vs_currencies=usd%2Cidr&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true&include_last_updated_at=true')
module.exports = {
get,
post,
getIdentity,
getPool,
getDelegators,
getDelegatorRewards,
getDelegatorTotalRewards,
getEpochRewards,
getPenalties,
getBalanceChanges,
getTxs,
getEpochIdentity,
getEpoch,
getLastEpoch,
getOnlineMinners,
getOnlineIdentities,
getIdenaPrice
}