-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
56 lines (46 loc) · 1.46 KB
/
index.js
File metadata and controls
56 lines (46 loc) · 1.46 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
const API = require('./api')
const assert = require("assert")
module.exports = (config = {}) => {
config = {
baseURL: 'https://cryptapi.io/api/',
supportedTickers: ['btc', 'bch', 'ltc', 'eth', 'xmr', 'iota'],
...config
}
const api = API(config)
const getTickerInfo = ticker => {
assert(ticker, 'requires ticker')
return api.get(`/${ticker}/info`)
}
const tickerCreateAddress = ticker => (address, callback, options = {}) => {
assert(ticker, 'requires ticker')
assert(address, 'requires address')
assert(callback, 'requires callback')
return api.get(`/${ticker}/create`, {
address, callback, ...options
})
}
const tickerLogs = ticker => callback => {
assert(ticker, 'requires ticker')
assert(callback, 'requires callback')
return api.get(`/${ticker}/create`, {
callback
})
}
return config.supportedTickers.reduce((memo, ticker) => {
memo[`${ticker}Info`] = () => getTickerInfo(ticker)
memo[`${ticker}CreateAddress`] = tickerCreateAddress(ticker)
memo[`${ticker}Logs`] = tickerLogs(ticker)
return memo
}, {
getSupportedTickers: () => config.supportedTickers,
_createAddress: (ticker, address, callback, options) => {
const ca = tickerCreateAddress(ticker)
return ca(address, callback, options)
},
_getInfo: (ticker) => getTickerInfo(ticker),
_tickerLogs: (ticker, callback) => {
const ca = tickerLogs(ticker)
return ca(callback)
},
})
}