-
Notifications
You must be signed in to change notification settings - Fork 249
/
filters_shh.go
57 lines (41 loc) · 1.04 KB
/
filters_shh.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
56
57
package subscriptions
import (
"fmt"
"github.com/status-im/status-go/rpc"
)
type whisperFilter struct {
id string
rpcClient *rpc.Client
}
func installShhFilter(rpcClient *rpc.Client, method string, args []interface{}) (*whisperFilter, error) {
if err := validateShhMethod(method); err != nil {
return nil, err
}
var result string
err := rpcClient.Call(&result, method, args...)
if err != nil {
return nil, err
}
filter := &whisperFilter{
id: result,
rpcClient: rpcClient,
}
return filter, nil
}
func (wf *whisperFilter) getChanges() ([]interface{}, error) {
var result []interface{}
err := wf.rpcClient.Call(&result, "shh_getFilterMessages", wf.getID())
return result, err
}
func (wf *whisperFilter) getID() string {
return wf.id
}
func (wf *whisperFilter) uninstall() error {
return wf.rpcClient.Call(nil, "shh_deleteMessageFilter", wf.getID())
}
func validateShhMethod(method string) error {
if method != "shh_newMessageFilter" {
return fmt.Errorf("unexpected filter method: %s", method)
}
return nil
}