diff --git a/docs/rpc.md b/docs/rpc.md index 7ab04399e..3f4d37377 100644 --- a/docs/rpc.md +++ b/docs/rpc.md @@ -251,7 +251,11 @@ burned). #### `getblocknotifications` call This method returns notifications from a block organized by trigger type. -Supports filtering by contract and event name. +Supports filtering by contract and event name (the same filter as provided +for subscriptions to execution results, see [notifications specification](notifications.md). +The resulting JSON is an object with three (if matched) field: "onpersist", +"application" and "postpersist" containing arrays of notifications (same JSON +as used in notification service) for the respective triggers. #### Historic calls diff --git a/pkg/neorpc/result/block_notifications.go b/pkg/neorpc/result/block_notifications.go index 832593c81..44376ed7a 100644 --- a/pkg/neorpc/result/block_notifications.go +++ b/pkg/neorpc/result/block_notifications.go @@ -4,9 +4,13 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/state" ) -// BlockNotifications represents notifications from a block organized by trigger type. +// BlockNotifications represents notifications from a block organized by +// trigger type. type BlockNotifications struct { - PrePersistNotifications []state.ContainedNotificationEvent `json:"prepersist,omitempty"` - TxNotifications []state.ContainedNotificationEvent `json:"transactions,omitempty"` - PostPersistNotifications []state.ContainedNotificationEvent `json:"postpersist,omitempty"` + // Block-level execution _before_ any transactions. + OnPersist []state.ContainedNotificationEvent `json:"onpersist,omitempty"` + // Transaction execution. + Application []state.ContainedNotificationEvent `json:"application,omitempty"` + // Block-level execution _after_ all transactions. + PostPersist []state.ContainedNotificationEvent `json:"postpersist,omitempty"` } diff --git a/pkg/services/rpcsrv/server.go b/pkg/services/rpcsrv/server.go index 27715aa44..b27502e0a 100644 --- a/pkg/services/rpcsrv/server.go +++ b/pkg/services/rpcsrv/server.go @@ -3242,21 +3242,21 @@ func (s *Server) getBlockNotifications(reqParams params.Params) (any, *neorpc.Er if err != nil { return nil, neorpc.NewInternalServerError("failed to get app exec results for onpersist") } - notifications.PrePersistNotifications = processAppExecResults([]state.AppExecResult{aers[0]}, filter) + notifications.OnPersist = processAppExecResults([]state.AppExecResult{aers[0]}, filter) for _, txHash := range block.Transactions { aers, err := s.chain.GetAppExecResults(txHash.Hash(), trigger.Application) if err != nil { return nil, neorpc.NewInternalServerError("failed to get app exec results") } - notifications.TxNotifications = append(notifications.TxNotifications, processAppExecResults(aers, filter)...) + notifications.Application = append(notifications.Application, processAppExecResults(aers, filter)...) } aers, err = s.chain.GetAppExecResults(block.Hash(), trigger.PostPersist) if err != nil { return nil, neorpc.NewInternalServerError("failed to get app exec results for postpersist") } - notifications.PostPersistNotifications = processAppExecResults([]state.AppExecResult{aers[0]}, filter) + notifications.PostPersist = processAppExecResults([]state.AppExecResult{aers[0]}, filter) return notifications, nil } diff --git a/pkg/services/rpcsrv/server_test.go b/pkg/services/rpcsrv/server_test.go index c9a113542..4b994c315 100644 --- a/pkg/services/rpcsrv/server_test.go +++ b/pkg/services/rpcsrv/server_test.go @@ -2294,7 +2294,7 @@ var rpcTestCases = map[string][]rpcTestCase{ res, ok := acc.(*result.BlockNotifications) require.True(t, ok) require.NotNil(t, res) - for _, ne := range res.TxNotifications { + for _, ne := range res.Application { require.Equal(t, nativehashes.NeoToken, ne.ScriptHash) require.Equal(t, "Transfer", ne.Name) }