From 5c97e0dcf2658a8e08f8bb7ef700781adb104efd Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Fri, 24 Sep 2021 12:23:30 +0300 Subject: [PATCH] rpc: move NotaryRequestEvent to the subscriptions pkg It is used for subscriptions only, so move it to the subscriptions pkg. --- pkg/rpc/client/wsclient.go | 4 ++-- pkg/rpc/response/events.go | 15 ++------------- .../result/subscriptions/notary_request_event.go | 13 +++++++++++++ pkg/rpc/server/server.go | 2 +- pkg/rpc/server/subscription.go | 2 +- 5 files changed, 19 insertions(+), 17 deletions(-) create mode 100644 pkg/rpc/response/result/subscriptions/notary_request_event.go diff --git a/pkg/rpc/client/wsclient.go b/pkg/rpc/client/wsclient.go index 7642899bf..8c52ec345 100644 --- a/pkg/rpc/client/wsclient.go +++ b/pkg/rpc/client/wsclient.go @@ -40,7 +40,7 @@ type WSClient struct { // Notification represents server-generated notification for client subscriptions. // Value can be one of block.Block, state.AppExecResult, subscriptions.NotificationEvent -// transaction.Transaction or response.NotaryRequestEvent based on Type. +// transaction.Transaction or subscriptions.NotaryRequestEvent based on Type. type Notification struct { Type response.EventID Value interface{} @@ -151,7 +151,7 @@ readloop: case response.ExecutionEventID: val = new(state.AppExecResult) case response.NotaryRequestEventID: - val = new(response.NotaryRequestEvent) + val = new(subscriptions.NotaryRequestEvent) case response.MissedEventID: // No value. default: diff --git a/pkg/rpc/response/events.go b/pkg/rpc/response/events.go index 0c997ea42..e7e676eaa 100644 --- a/pkg/rpc/response/events.go +++ b/pkg/rpc/response/events.go @@ -3,21 +3,10 @@ package response import ( "encoding/json" "errors" - - "github.com/nspcc-dev/neo-go/pkg/core/mempoolevent" - "github.com/nspcc-dev/neo-go/pkg/network/payload" ) -type ( - // EventID represents an event type happening on the chain. - EventID byte - // NotaryRequestEvent represents P2PNotaryRequest event either added or removed - // from notary payload pool. - NotaryRequestEvent struct { - Type mempoolevent.Type `json:"type"` - NotaryRequest *payload.P2PNotaryRequest `json:"notaryrequest"` - } -) +// EventID represents an event type happening on the chain. +type EventID byte const ( // InvalidEventID is an invalid event id that is the default value of diff --git a/pkg/rpc/response/result/subscriptions/notary_request_event.go b/pkg/rpc/response/result/subscriptions/notary_request_event.go new file mode 100644 index 000000000..2566bc623 --- /dev/null +++ b/pkg/rpc/response/result/subscriptions/notary_request_event.go @@ -0,0 +1,13 @@ +package subscriptions + +import ( + "github.com/nspcc-dev/neo-go/pkg/core/mempoolevent" + "github.com/nspcc-dev/neo-go/pkg/network/payload" +) + +// NotaryRequestEvent represents P2PNotaryRequest event either added or removed +// from notary payload pool. +type NotaryRequestEvent struct { + Type mempoolevent.Type `json:"type"` + NotaryRequest *payload.P2PNotaryRequest `json:"notaryrequest"` +} diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index d19e08ba6..cffbf79d5 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -1705,7 +1705,7 @@ chloop: resp.Payload[0] = tx case e := <-s.notaryRequestCh: resp.Event = response.NotaryRequestEventID - resp.Payload[0] = &response.NotaryRequestEvent{ + resp.Payload[0] = &subscriptions.NotaryRequestEvent{ Type: e.Type, NotaryRequest: e.Data.(*payload.P2PNotaryRequest), } diff --git a/pkg/rpc/server/subscription.go b/pkg/rpc/server/subscription.go index 5e5f690c5..05068b375 100644 --- a/pkg/rpc/server/subscription.go +++ b/pkg/rpc/server/subscription.go @@ -83,7 +83,7 @@ func (f *feed) Matches(r *response.Notification) bool { return applog.VMState.String() == filt.State case response.NotaryRequestEventID: filt := f.filter.(request.TxFilter) - req := r.Payload[0].(*response.NotaryRequestEvent) + req := r.Payload[0].(*subscriptions.NotaryRequestEvent) senderOk := filt.Sender == nil || req.NotaryRequest.FallbackTransaction.Signers[1].Account == *filt.Sender signerOK := true if filt.Signer != nil {