-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathnet.js
53 lines (53 loc) · 1.44 KB
/
net.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
const Block = require('./block.js')
const Mempool = require('./mempool.js')
const Key = require('./key.js')
const Log = require('./log.js')
const axios = require('axios')
const fs = require('fs')
const crypto = require('crypto')
const peek = function(host, o) {
axios({
method: "post",
url: host + "/peek",
data: { q: o.q },
}).then(function(res) {
Log.debug("BITBUS", res.data)
})
}
const block = function(host, o, path, cb) {
if (!process.env.DEV && !fs.existsSync(path)) fs.mkdirSync(path, { recursive: true })
Key.gen(o).then(function(t) {
axios({
method: "post",
url: host + "/block",
headers: {
'Content-type': 'application/json; charset=utf-8',
'Accept': 'application/json; charset=utf-8'
},
data: { tx: t },
responseType: "stream"
}).then(function(res) {
Block.crawl(res.data, o, path, cb)
}).catch(function(err) {
Log.debug("BITBUS", err)
})
})
}
const mempool = function(host, o, path, hashpool, cb) {
if (!process.env.DEV && !fs.existsSync(path)) fs.mkdirSync(path, { recursive: true })
Key.gen(o).then(function(t) {
axios({
method: "post",
url: host + "/mempool",
data: { tx: t },
responseType: "stream"
}).then(function(res) {
Mempool.crawl(res.data, o, path, hashpool, cb)
}).catch(function(err) {
Log.debug("BITBUS", err)
})
})
}
module.exports = {
peek: peek, block: block, mempool: mempool
}