From b3ea7504cbb0e81a957d4778ad5354503101e854 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Fri, 24 Sep 2021 12:15:25 +0300 Subject: [PATCH 1/2] subscriptions: add container hash to notification event External users make use of it. Close #2190. --- docs/notifications.md | 11 ++-- internal/fakechain/fakechain.go | 5 +- pkg/core/blockchain.go | 26 ++++++--- pkg/core/blockchain_test.go | 3 +- pkg/core/blockchainer/blockchainer.go | 5 +- pkg/rpc/client/wsclient.go | 5 +- pkg/rpc/client/wsclient_test.go | 2 +- .../subscriptions/notification_event.go | 56 +++++++++++++++++++ .../subscriptions/notification_event_test.go | 21 +++++++ pkg/rpc/server/server.go | 5 +- pkg/rpc/server/subscription.go | 3 +- 11 files changed, 118 insertions(+), 24 deletions(-) create mode 100644 pkg/rpc/response/result/subscriptions/notification_event.go create mode 100644 pkg/rpc/response/result/subscriptions/notification_event_test.go diff --git a/docs/notifications.md b/docs/notifications.md index ba95c1c38d..6aedecc522 100644 --- a/docs/notifications.md +++ b/docs/notifications.md @@ -16,7 +16,7 @@ Currently supported events: Contents: transaction. Filters: sender and signer. * notification generated during execution - Contents: container hash, contract script hash, stack item. Filters: contract script hash. + Contents: container hash, contract hash, notification name, stack item. Filters: contract hash, notification name. * transaction executed Contents: application execution result. Filters: VM state. @@ -284,10 +284,10 @@ Example: ### `notification_from_execution` notification -Contains three parameters: contract script hash (hex-encoded LE Uint160 -in a string), notification name and stack item (encoded the same way as -`state` field contents for notifications from `getapplicationlog` -response). +Contains four parameters: container hash (block's or transaction's hex-encoded LE +Uint256 hash in a string), contract hash (hex-encoded LE Uint160 in a string), +notification name and stack item (encoded the same way as `state` field contents +for notifications from `getapplicationlog` response). Example: @@ -329,6 +329,7 @@ Example: }, "contract" : "0x1b4357bff5a01bdf2a6581247cf9ed1e24629176", "name" : "transfer", + "container" : "0xe1cd5e57e721d2a2e05fb1f08721b12057b25ab1dd7fd0f33ee1639932fdfad7", } ] } diff --git a/internal/fakechain/fakechain.go b/internal/fakechain/fakechain.go index 6d67f0a6c1..243a31109a 100644 --- a/internal/fakechain/fakechain.go +++ b/internal/fakechain/fakechain.go @@ -19,6 +19,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" + "github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm" @@ -413,7 +414,7 @@ func (chain *FakeChain) SubscribeForExecutions(ch chan<- *state.AppExecResult) { } // SubscribeForNotifications implements Blockchainer interface. -func (chain *FakeChain) SubscribeForNotifications(ch chan<- *state.NotificationEvent) { +func (chain *FakeChain) SubscribeForNotifications(ch chan<- *subscriptions.NotificationEvent) { panic("TODO") } @@ -453,7 +454,7 @@ func (chain *FakeChain) UnsubscribeFromExecutions(ch chan<- *state.AppExecResult } // UnsubscribeFromNotifications implements Blockchainer interface. -func (chain *FakeChain) UnsubscribeFromNotifications(ch chan<- *state.NotificationEvent) { +func (chain *FakeChain) UnsubscribeFromNotifications(ch chan<- *subscriptions.NotificationEvent) { panic("TODO") } diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 896751e384..a5d9aeecd5 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -30,6 +30,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn" "github.com/nspcc-dev/neo-go/pkg/io" + "github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" @@ -647,7 +648,7 @@ func (bc *Blockchain) notificationDispatcher() { // expected, but maps are convenient for adding/deleting elements). blockFeed = make(map[chan<- *block.Block]bool) txFeed = make(map[chan<- *transaction.Transaction]bool) - notificationFeed = make(map[chan<- *state.NotificationEvent]bool) + notificationFeed = make(map[chan<- *subscriptions.NotificationEvent]bool) executionFeed = make(map[chan<- *state.AppExecResult]bool) ) for { @@ -660,7 +661,7 @@ func (bc *Blockchain) notificationDispatcher() { blockFeed[ch] = true case chan<- *transaction.Transaction: txFeed[ch] = true - case chan<- *state.NotificationEvent: + case chan<- *subscriptions.NotificationEvent: notificationFeed[ch] = true case chan<- *state.AppExecResult: executionFeed[ch] = true @@ -673,7 +674,7 @@ func (bc *Blockchain) notificationDispatcher() { delete(blockFeed, ch) case chan<- *transaction.Transaction: delete(txFeed, ch) - case chan<- *state.NotificationEvent: + case chan<- *subscriptions.NotificationEvent: delete(notificationFeed, ch) case chan<- *state.AppExecResult: delete(executionFeed, ch) @@ -693,7 +694,10 @@ func (bc *Blockchain) notificationDispatcher() { } for i := range aer.Events { for ch := range notificationFeed { - ch <- &aer.Events[i] + ch <- &subscriptions.NotificationEvent{ + Container: aer.Container, + NotificationEvent: aer.Events[i], + } } } @@ -710,7 +714,10 @@ func (bc *Blockchain) notificationDispatcher() { if aer.VMState == vm.HaltState { for i := range aer.Events { for ch := range notificationFeed { - ch <- &aer.Events[i] + ch <- &subscriptions.NotificationEvent{ + Container: aer.Container, + NotificationEvent: aer.Events[i], + } } } } @@ -728,7 +735,10 @@ func (bc *Blockchain) notificationDispatcher() { } for i := range aer.Events { for ch := range notificationFeed { - ch <- &aer.Events[i] + ch <- &subscriptions.NotificationEvent{ + Container: aer.Container, + NotificationEvent: aer.Events[i], + } } } } @@ -1653,7 +1663,7 @@ func (bc *Blockchain) SubscribeForTransactions(ch chan<- *transaction.Transactio // transactions use SubscribeForExecutions instead. Make sure this channel is // read from regularly as not reading these events might affect other Blockchain // functions. -func (bc *Blockchain) SubscribeForNotifications(ch chan<- *state.NotificationEvent) { +func (bc *Blockchain) SubscribeForNotifications(ch chan<- *subscriptions.NotificationEvent) { bc.subCh <- ch } @@ -1681,7 +1691,7 @@ func (bc *Blockchain) UnsubscribeFromTransactions(ch chan<- *transaction.Transac // UnsubscribeFromNotifications unsubscribes given channel from new // execution-generated notifications, you can close it afterwards. Passing // non-subscribed channel is a no-op. -func (bc *Blockchain) UnsubscribeFromNotifications(ch chan<- *state.NotificationEvent) { +func (bc *Blockchain) UnsubscribeFromNotifications(ch chan<- *subscriptions.NotificationEvent) { bc.unsubCh <- ch } diff --git a/pkg/core/blockchain_test.go b/pkg/core/blockchain_test.go index 285eeb3799..36b45f85ae 100644 --- a/pkg/core/blockchain_test.go +++ b/pkg/core/blockchain_test.go @@ -31,6 +31,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/io" + "github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" @@ -1397,7 +1398,7 @@ func TestSubscriptions(t *testing.T) { const chBufSize = 16 blockCh := make(chan *block.Block, chBufSize) txCh := make(chan *transaction.Transaction, chBufSize) - notificationCh := make(chan *state.NotificationEvent, chBufSize) + notificationCh := make(chan *subscriptions.NotificationEvent, chBufSize) executionCh := make(chan *state.AppExecResult, chBufSize) bc := newTestChain(t) diff --git a/pkg/core/blockchainer/blockchainer.go b/pkg/core/blockchainer/blockchainer.go index 998b8a8464..97bd64611f 100644 --- a/pkg/core/blockchainer/blockchainer.go +++ b/pkg/core/blockchainer/blockchainer.go @@ -11,6 +11,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/hash" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" + "github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm" @@ -69,13 +70,13 @@ type Blockchainer interface { SetNotary(mod services.Notary) SubscribeForBlocks(ch chan<- *block.Block) SubscribeForExecutions(ch chan<- *state.AppExecResult) - SubscribeForNotifications(ch chan<- *state.NotificationEvent) + SubscribeForNotifications(ch chan<- *subscriptions.NotificationEvent) SubscribeForTransactions(ch chan<- *transaction.Transaction) VerifyTx(*transaction.Transaction) error VerifyWitness(util.Uint160, hash.Hashable, *transaction.Witness, int64) error GetMemPool() *mempool.Pool UnsubscribeFromBlocks(ch chan<- *block.Block) UnsubscribeFromExecutions(ch chan<- *state.AppExecResult) - UnsubscribeFromNotifications(ch chan<- *state.NotificationEvent) + UnsubscribeFromNotifications(ch chan<- *subscriptions.NotificationEvent) UnsubscribeFromTransactions(ch chan<- *transaction.Transaction) } diff --git a/pkg/rpc/client/wsclient.go b/pkg/rpc/client/wsclient.go index ace6811d06..7642899bf3 100644 --- a/pkg/rpc/client/wsclient.go +++ b/pkg/rpc/client/wsclient.go @@ -12,6 +12,7 @@ import ( "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/subscriptions" "github.com/nspcc-dev/neo-go/pkg/util" ) @@ -38,7 +39,7 @@ type WSClient struct { } // Notification represents server-generated notification for client subscriptions. -// Value can be one of block.Block, state.AppExecResult, state.NotificationEvent +// Value can be one of block.Block, state.AppExecResult, subscriptions.NotificationEvent // transaction.Transaction or response.NotaryRequestEvent based on Type. type Notification struct { Type response.EventID @@ -146,7 +147,7 @@ readloop: case response.TransactionEventID: val = &transaction.Transaction{} case response.NotificationEventID: - val = new(state.NotificationEvent) + val = new(subscriptions.NotificationEvent) case response.ExecutionEventID: val = new(state.AppExecResult) case response.NotaryRequestEventID: diff --git a/pkg/rpc/client/wsclient_test.go b/pkg/rpc/client/wsclient_test.go index 3d8de18971..6ba2d4199d 100644 --- a/pkg/rpc/client/wsclient_test.go +++ b/pkg/rpc/client/wsclient_test.go @@ -118,7 +118,7 @@ func TestWSClientEvents(t *testing.T) { // Events from RPC server test chain. var events = []string{ `{"jsonrpc":"2.0","method":"transaction_executed","params":[{"container":"0xe1cd5e57e721d2a2e05fb1f08721b12057b25ab1dd7fd0f33ee1639932fdfad7","trigger":"Application","vmstate":"HALT","gasconsumed":"22910000","stack":[],"notifications":[{"contract":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176","eventname":"contract call","state":{"type":"Array","value":[{"type":"ByteString","value":"dHJhbnNmZXI="},{"type":"Array","value":[{"type":"ByteString","value":"dpFiJB7t+XwkgWUq3xug9b9XQxs="},{"type":"ByteString","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"Integer","value":"1000"}]}]}},{"contract":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176","eventname":"transfer","state":{"type":"Array","value":[{"type":"ByteString","value":"dpFiJB7t+XwkgWUq3xug9b9XQxs="},{"type":"ByteString","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"Integer","value":"1000"}]}}]}]}`, - `{"jsonrpc":"2.0","method":"notification_from_execution","params":[{"contract":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176","eventname":"contract call","state":{"type":"Array","value":[{"type":"ByteString","value":"dHJhbnNmZXI="},{"type":"Array","value":[{"type":"ByteString","value":"dpFiJB7t+XwkgWUq3xug9b9XQxs="},{"type":"ByteString","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"Integer","value":"1000"}]}]}}]}`, + `{"jsonrpc":"2.0","method":"notification_from_execution","params":[{"container":"0xe1cd5e57e721d2a2e05fb1f08721b12057b25ab1dd7fd0f33ee1639932fdfad7","contract":"0x1b4357bff5a01bdf2a6581247cf9ed1e24629176","eventname":"contract call","state":{"type":"Array","value":[{"type":"ByteString","value":"dHJhbnNmZXI="},{"type":"Array","value":[{"type":"ByteString","value":"dpFiJB7t+XwkgWUq3xug9b9XQxs="},{"type":"ByteString","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"Integer","value":"1000"}]}]}}]}`, `{"jsonrpc":"2.0","method":"transaction_executed","params":[{"container":"0xf97a72b7722c109f909a8bc16c22368c5023d85828b09b127b237aace33cf099","trigger":"Application","vmstate":"HALT","gasconsumed":"6042610","stack":[],"notifications":[{"contract":"0xe65ff7b3a02d207b584a5c27057d4e9862ef01da","eventname":"contract call","state":{"type":"Array","value":[{"type":"ByteString","value":"dHJhbnNmZXI="},{"type":"Array","value":[{"type":"ByteString","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"ByteString","value":"IHKCdK+vw29DoHHTKM+j5inZy7A="},{"type":"Integer","value":"123"}]}]}},{"contract":"0xe65ff7b3a02d207b584a5c27057d4e9862ef01da","eventname":"transfer","state":{"type":"Array","value":[{"type":"ByteString","value":"MW6FEDkBnTnfwsN9bD/uGf1YCYc="},{"type":"ByteString","value":"IHKCdK+vw29DoHHTKM+j5inZy7A="},{"type":"Integer","value":"123"}]}}]}]}`, fmt.Sprintf(`{"jsonrpc":"2.0","method":"block_added","params":[%s]}`, b1Verbose), `{"jsonrpc":"2.0","method":"event_missed","params":[]}`, diff --git a/pkg/rpc/response/result/subscriptions/notification_event.go b/pkg/rpc/response/result/subscriptions/notification_event.go new file mode 100644 index 0000000000..783e5ec9f1 --- /dev/null +++ b/pkg/rpc/response/result/subscriptions/notification_event.go @@ -0,0 +1,56 @@ +package subscriptions + +import ( + "encoding/json" + "errors" + "fmt" + + "github.com/nspcc-dev/neo-go/pkg/core/state" + "github.com/nspcc-dev/neo-go/pkg/util" +) + +// NotificationEvent represents wrapper for notification from script execution. +type NotificationEvent struct { + // Container hash is the hash of script container which is either a block or a transaction. + Container util.Uint256 + state.NotificationEvent +} + +// notificationEventAux is an auxiliary struct for JSON marshalling. +type notificationEventAux struct { + Container util.Uint256 `json:"container"` +} + +// MarshalJSON implements implements json.Marshaler interface. +func (ne *NotificationEvent) MarshalJSON() ([]byte, error) { + h, err := json.Marshal(¬ificationEventAux{ + Container: ne.Container, + }) + if err != nil { + return nil, fmt.Errorf("failed to marshal hash: %w", err) + } + exec, err := json.Marshal(ne.NotificationEvent) + if err != nil { + return nil, fmt.Errorf("failed to marshal execution: %w", err) + } + + if h[len(h)-1] != '}' || exec[0] != '{' { + return nil, errors.New("can't merge internal jsons") + } + h[len(h)-1] = ',' + h = append(h, exec[1:]...) + return h, nil +} + +// UnmarshalJSON implements implements json.Unmarshaler interface. +func (ne *NotificationEvent) UnmarshalJSON(data []byte) error { + aux := new(notificationEventAux) + if err := json.Unmarshal(data, aux); err != nil { + return err + } + if err := json.Unmarshal(data, &ne.NotificationEvent); err != nil { + return err + } + ne.Container = aux.Container + return nil +} diff --git a/pkg/rpc/response/result/subscriptions/notification_event_test.go b/pkg/rpc/response/result/subscriptions/notification_event_test.go new file mode 100644 index 0000000000..e22df6447e --- /dev/null +++ b/pkg/rpc/response/result/subscriptions/notification_event_test.go @@ -0,0 +1,21 @@ +package subscriptions + +import ( + "testing" + + "github.com/nspcc-dev/neo-go/internal/testserdes" + "github.com/nspcc-dev/neo-go/pkg/core/state" + "github.com/nspcc-dev/neo-go/pkg/util" + "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" +) + +func TestNotificationEvent_MarshalUnmarshalJSON(t *testing.T) { + testserdes.MarshalUnmarshalJSON(t, &NotificationEvent{ + Container: util.Uint256{1, 2, 3}, + NotificationEvent: state.NotificationEvent{ + ScriptHash: util.Uint160{4, 5, 6}, + Name: "alarm", + Item: stackitem.NewArray([]stackitem.Item{stackitem.NewByteArray([]byte("qwerty"))}), + }, + }, new(NotificationEvent)) +} diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index 34fefe1044..d19e08ba64 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -36,6 +36,7 @@ import ( "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" + "github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions" "github.com/nspcc-dev/neo-go/pkg/services/oracle" "github.com/nspcc-dev/neo-go/pkg/services/oracle/broadcaster" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" @@ -69,7 +70,7 @@ type ( notaryRequestSubs int blockCh chan *block.Block executionCh chan *state.AppExecResult - notificationCh chan *state.NotificationEvent + notificationCh chan *subscriptions.NotificationEvent transactionCh chan *transaction.Transaction notaryRequestCh chan mempoolevent.Event } @@ -181,7 +182,7 @@ func New(chain blockchainer.Blockchainer, conf rpc.Config, coreServer *network.S // These are NOT buffered to preserve original order of events. blockCh: make(chan *block.Block), executionCh: make(chan *state.AppExecResult), - notificationCh: make(chan *state.NotificationEvent), + notificationCh: make(chan *subscriptions.NotificationEvent), transactionCh: make(chan *transaction.Transaction), notaryRequestCh: make(chan mempoolevent.Event), } diff --git a/pkg/rpc/server/subscription.go b/pkg/rpc/server/subscription.go index 062706280d..5e5f690c5f 100644 --- a/pkg/rpc/server/subscription.go +++ b/pkg/rpc/server/subscription.go @@ -7,6 +7,7 @@ import ( "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/subscriptions" "go.uber.org/atomic" ) @@ -72,7 +73,7 @@ func (f *feed) Matches(r *response.Notification) bool { return senderOK && signerOK case response.NotificationEventID: filt := f.filter.(request.NotificationFilter) - notification := r.Payload[0].(*state.NotificationEvent) + notification := r.Payload[0].(*subscriptions.NotificationEvent) hashOk := filt.Contract == nil || notification.ScriptHash.Equals(*filt.Contract) nameOk := filt.Name == nil || notification.Name == *filt.Name return hashOk && nameOk From 5c97e0dcf2658a8e08f8bb7ef700781adb104efd Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Fri, 24 Sep 2021 12:23:30 +0300 Subject: [PATCH 2/2] 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 7642899bf3..8c52ec3451 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 0c997ea42b..e7e676eaaa 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 0000000000..2566bc6230 --- /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 d19e08ba64..cffbf79d59 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 5e5f690c5f..05068b3755 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 {