github.com/status-im/status-go@v1.1.0/services/subscriptions/filters_shh.go (about) 1 package subscriptions 2 3 import ( 4 "fmt" 5 6 "github.com/status-im/status-go/rpc" 7 ) 8 9 type whisperFilter struct { 10 id string 11 rpcClient *rpc.Client 12 } 13 14 func installShhFilter(rpcClient *rpc.Client, method string, args []interface{}) (*whisperFilter, error) { 15 16 if err := validateShhMethod(method); err != nil { 17 return nil, err 18 } 19 20 var result string 21 22 err := rpcClient.Call(&result, rpcClient.UpstreamChainID, method, args...) 23 24 if err != nil { 25 return nil, err 26 } 27 28 filter := &whisperFilter{ 29 id: result, 30 rpcClient: rpcClient, 31 } 32 33 return filter, nil 34 } 35 36 func (wf *whisperFilter) getChanges() ([]interface{}, error) { 37 var result []interface{} 38 39 err := wf.rpcClient.Call(&result, wf.rpcClient.UpstreamChainID, "shh_getFilterMessages", wf.getID()) 40 41 return result, err 42 } 43 44 func (wf *whisperFilter) getID() string { 45 return wf.id 46 } 47 48 func (wf *whisperFilter) uninstall() error { 49 return wf.rpcClient.Call(nil, wf.rpcClient.UpstreamChainID, "shh_deleteMessageFilter", wf.getID()) 50 } 51 52 func validateShhMethod(method string) error { 53 if method != "shh_newMessageFilter" { 54 return fmt.Errorf("unexpected filter method: %s", method) 55 } 56 return nil 57 }