forked from dcb9/janus
-
Notifications
You must be signed in to change notification settings - Fork 27
/
eth_unsubscribe.go
55 lines (48 loc) · 1.41 KB
/
eth_unsubscribe.go
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
package transformer
import (
"github.com/labstack/echo"
"github.com/qtumproject/janus/pkg/eth"
"github.com/qtumproject/janus/pkg/notifier"
"github.com/qtumproject/janus/pkg/qtum"
)
// ETHUnsubscribe implements ETHProxy
type ETHUnsubscribe struct {
*qtum.Qtum
*notifier.Agent
}
func (p *ETHUnsubscribe) Method() string {
return "eth_unsubscribe"
}
func (p *ETHUnsubscribe) Request(rawreq *eth.JSONRPCRequest, c echo.Context) (interface{}, eth.JSONRPCError) {
notifier := getNotifier(c)
if notifier == nil {
p.GetLogger().Log("msg", "eth_unsubscribe only supported over websocket")
/*
// TODO
{
"jsonrpc": "2.0",
"id": 580,
"error": {
"code": -32601,
"message": "The method eth_unsubscribe does not exist/is not available"
}
}
*/
return nil, eth.NewMethodNotFoundError("eth_subscribe")
}
var req eth.EthUnsubscribeRequest
if err := unmarshalRequest(rawreq.Params, &req); err != nil {
// TODO: Correct error code?
return nil, eth.NewInvalidParamsError(err.Error())
}
return p.request(&req, notifier)
}
func (p *ETHUnsubscribe) request(req *eth.EthUnsubscribeRequest, notifier *notifier.Notifier) (eth.EthUnsubscribeResponse, eth.JSONRPCError) {
if len(*req) != 1 {
// TODO: Correct error code?
return false, eth.NewInvalidParamsError("requires one parameter")
}
param := (*req)[0]
success := notifier.Unsubscribe(param)
return eth.EthUnsubscribeResponse(success), nil
}