neorpc: rename BlockNotifications fields to follow triggers exactly

Be more consistent.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
Roman Khimov 2025-02-11 16:05:48 +03:00
parent 93be186685
commit 25e2d80363
4 changed files with 17 additions and 9 deletions

View file

@ -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

View file

@ -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"`
}

View file

@ -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
}

View file

@ -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)
}