mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
shh: fix shh_subscribe request parsing in jsonrpc api (#14450)
This commit is contained in:
parent
ef7b9fb7d0
commit
1f6cec8924
1 changed files with 17 additions and 14 deletions
31
rpc/json.go
31
rpc/json.go
|
|
@ -163,22 +163,25 @@ func parseRequest(incomingMsg json.RawMessage) ([]rpcRequest, bool, Error) {
|
|||
return nil, false, &invalidMessageError{err.Error()}
|
||||
}
|
||||
|
||||
// subscribe are special, they will always use `subscribeMethod` as first param in the payload
|
||||
if strings.HasSuffix(in.Method, subscribeMethodSuffix) {
|
||||
reqs := []rpcRequest{{id: &in.Id, isPubSub: true}}
|
||||
if len(in.Payload) > 0 {
|
||||
// first param must be subscription name
|
||||
var subscribeMethod [1]string
|
||||
if err := json.Unmarshal(in.Payload, &subscribeMethod); err != nil {
|
||||
log.Debug(fmt.Sprintf("Unable to parse subscription method: %v\n", err))
|
||||
return nil, false, &invalidRequestError{"Unable to parse subscription request"}
|
||||
}
|
||||
// shh_subscribe should not be handled in a special way
|
||||
if !strings.HasPrefix(in.Method, "shh_") {
|
||||
// subscribe are special, they will always use `subscribeMethod` as first param in the payload
|
||||
if strings.HasSuffix(in.Method, subscribeMethodSuffix) {
|
||||
reqs := []rpcRequest{{id: &in.Id, isPubSub: true}}
|
||||
if len(in.Payload) > 0 {
|
||||
// first param must be subscription name
|
||||
var subscribeMethod [1]string
|
||||
if err := json.Unmarshal(in.Payload, &subscribeMethod); err != nil {
|
||||
log.Debug(fmt.Sprintf("Unable to parse subscription method: %v\n", err))
|
||||
return nil, false, &invalidRequestError{"Unable to parse subscription request"}
|
||||
}
|
||||
|
||||
reqs[0].service, reqs[0].method = strings.TrimSuffix(in.Method, subscribeMethodSuffix), subscribeMethod[0]
|
||||
reqs[0].params = in.Payload
|
||||
return reqs, false, nil
|
||||
reqs[0].service, reqs[0].method = strings.TrimSuffix(in.Method, subscribeMethodSuffix), subscribeMethod[0]
|
||||
reqs[0].params = in.Payload
|
||||
return reqs, false, nil
|
||||
}
|
||||
return nil, false, &invalidRequestError{"Unable to parse subscription request"}
|
||||
}
|
||||
return nil, false, &invalidRequestError{"Unable to parse subscription request"}
|
||||
}
|
||||
|
||||
if strings.HasSuffix(in.Method, unsubscribeMethodSuffix) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue