rpc/server: add notification filters
And check state string correctness on unmarshaling.
This commit is contained in:
parent
78716c5335
commit
8f55f0ac76
4 changed files with 192 additions and 33 deletions
|
@ -2,7 +2,10 @@ package server
|
|||
|
||||
import (
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
|
||||
"go.uber.org/atomic"
|
||||
)
|
||||
|
||||
|
@ -16,7 +19,11 @@ type (
|
|||
// cheaper doing it this way rather than creating a map),
|
||||
// pointing to EventID is an obvious overkill at the moment, but
|
||||
// that's not for long.
|
||||
feeds [maxFeeds]response.EventID
|
||||
feeds [maxFeeds]feed
|
||||
}
|
||||
feed struct {
|
||||
event response.EventID
|
||||
filter interface{}
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -34,3 +41,27 @@ const (
|
|||
// a lot in terms of memory used.
|
||||
notificationBufSize = 1024
|
||||
)
|
||||
|
||||
func (f *feed) Matches(r *response.Notification) bool {
|
||||
if r.Event != f.event {
|
||||
return false
|
||||
}
|
||||
if f.filter == nil {
|
||||
return true
|
||||
}
|
||||
switch f.event {
|
||||
case response.TransactionEventID:
|
||||
filt := f.filter.(request.TxFilter)
|
||||
tx := r.Payload[0].(*transaction.Transaction)
|
||||
return tx.Type == filt.Type
|
||||
case response.NotificationEventID:
|
||||
filt := f.filter.(request.NotificationFilter)
|
||||
notification := r.Payload[0].(result.NotificationEvent)
|
||||
return notification.Contract.Equals(filt.Contract)
|
||||
case response.ExecutionEventID:
|
||||
filt := f.filter.(request.ExecutionFilter)
|
||||
applog := r.Payload[0].(result.ApplicationLog)
|
||||
return len(applog.Executions) != 0 && applog.Executions[0].VMState == filt.State
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue