forked from Sfippa/api-client-v1-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
71 lines (60 loc) · 2.25 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var API = require('../api')
var endpoints = require('./endpoints')
var api = new API('https://blockchain.info', endpoints)
module.exports = {
getBlock: getBlock,
getTx: getTx,
getBlockHeight: getBlockHeight,
getAddress: getAddress,
getMultiAddress: getMultiAddress,
getUnspentOutputs: getUnspentOutputs,
getBalance: getBalance,
getLatestBlock: getLatestBlock,
getUnconfirmedTx: getUnconfirmedTx,
getBlocks: getBlocks
}
function getBlock (blockHash, options) {
options = options || {}
return api.request('rawblock', { hash: blockHash, apiCode: options.apiCode })
}
function getTx (txHash, options) {
options = options || {}
return api.request('rawtx', { hash: txHash, apiCode: options.apiCode })
}
function getBlockHeight (blockHeight, options) {
options = options || {}
return api.request('blockHeight', { height: blockHeight, apiCode: options.apiCode })
}
function getAddress (address, options) {
options = options || {}
var params = { address: address, limit: options.limit, offset: options.offset, apiCode: options.apiCode }
return api.request('address', params)
}
function getMultiAddress (addresses, options) {
options = options || {}
addresses = (addresses instanceof Array ? addresses : [addresses]).join('|')
var params = { active: addresses, limit: options.limit, offset: options.offset, apiCode: options.apiCode }
return api.request('multiaddr', params)
}
function getUnspentOutputs (addresses, options) {
options = options || {}
addresses = (addresses instanceof Array ? addresses : [addresses]).join('|')
return api.request('unspent', { active: addresses, confirmations: options.confirmations, limit: options.limit, apiCode: options.apiCode })
}
function getBalance (addresses, options) {
options = options || {}
addresses = (addresses instanceof Array ? addresses : [addresses]).join('|')
return api.request('balance', { active: addresses, apiCode: options.apiCode })
}
function getLatestBlock (options) {
options = options || {}
return api.request('latestblock', options)
}
function getUnconfirmedTx (options) {
options = options || {}
return api.request('unconfTxs', options)
}
function getBlocks (time, options) {
options = options || {}
return api.request('blocks', { time: time, apiCode: options.apiCode })
}