-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp.js
More file actions
42 lines (36 loc) · 769 Bytes
/
http.js
File metadata and controls
42 lines (36 loc) · 769 Bytes
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
const ETH = require('./')
const got = require('got')
module.exports = class HTTP extends ETH {
constructor (endpoint) {
super(new RPC(endpoint))
}
}
class RPC {
constructor (endpoint) {
this.endpoint = endpoint
this.destroyed = false
}
async request (method, params) {
const res = await got.post({
url: this.endpoint,
timeout: 5000,
json: {
jsonrpc: '2.0',
method,
params,
id: 1
},
responseType: 'json'
})
if (res.body.error) {
const error = new Error(res.body.error.message)
error.code = res.body.error.code
throw error
}
return res.body.result
}
subscribe () {
throw new Error('HTTP does not support pubsub')
}
destroy () {}
}