Skip to content

Commit 25e2d80

Browse files
committed
neorpc: rename BlockNotifications fields to follow triggers exactly
Be more consistent. Signed-off-by: Roman Khimov <[email protected]>
1 parent 93be186 commit 25e2d80

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

docs/rpc.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,11 @@ burned).
251251
#### `getblocknotifications` call
252252

253253
This method returns notifications from a block organized by trigger type.
254-
Supports filtering by contract and event name.
254+
Supports filtering by contract and event name (the same filter as provided
255+
for subscriptions to execution results, see [notifications specification](notifications.md).
256+
The resulting JSON is an object with three (if matched) field: "onpersist",
257+
"application" and "postpersist" containing arrays of notifications (same JSON
258+
as used in notification service) for the respective triggers.
255259

256260
#### Historic calls
257261

pkg/neorpc/result/block_notifications.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ import (
44
"github.com/nspcc-dev/neo-go/pkg/core/state"
55
)
66

7-
// BlockNotifications represents notifications from a block organized by trigger type.
7+
// BlockNotifications represents notifications from a block organized by
8+
// trigger type.
89
type BlockNotifications struct {
9-
PrePersistNotifications []state.ContainedNotificationEvent `json:"prepersist,omitempty"`
10-
TxNotifications []state.ContainedNotificationEvent `json:"transactions,omitempty"`
11-
PostPersistNotifications []state.ContainedNotificationEvent `json:"postpersist,omitempty"`
10+
// Block-level execution _before_ any transactions.
11+
OnPersist []state.ContainedNotificationEvent `json:"onpersist,omitempty"`
12+
// Transaction execution.
13+
Application []state.ContainedNotificationEvent `json:"application,omitempty"`
14+
// Block-level execution _after_ all transactions.
15+
PostPersist []state.ContainedNotificationEvent `json:"postpersist,omitempty"`
1216
}

pkg/services/rpcsrv/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3242,21 +3242,21 @@ func (s *Server) getBlockNotifications(reqParams params.Params) (any, *neorpc.Er
32423242
if err != nil {
32433243
return nil, neorpc.NewInternalServerError("failed to get app exec results for onpersist")
32443244
}
3245-
notifications.PrePersistNotifications = processAppExecResults([]state.AppExecResult{aers[0]}, filter)
3245+
notifications.OnPersist = processAppExecResults([]state.AppExecResult{aers[0]}, filter)
32463246

32473247
for _, txHash := range block.Transactions {
32483248
aers, err := s.chain.GetAppExecResults(txHash.Hash(), trigger.Application)
32493249
if err != nil {
32503250
return nil, neorpc.NewInternalServerError("failed to get app exec results")
32513251
}
3252-
notifications.TxNotifications = append(notifications.TxNotifications, processAppExecResults(aers, filter)...)
3252+
notifications.Application = append(notifications.Application, processAppExecResults(aers, filter)...)
32533253
}
32543254

32553255
aers, err = s.chain.GetAppExecResults(block.Hash(), trigger.PostPersist)
32563256
if err != nil {
32573257
return nil, neorpc.NewInternalServerError("failed to get app exec results for postpersist")
32583258
}
3259-
notifications.PostPersistNotifications = processAppExecResults([]state.AppExecResult{aers[0]}, filter)
3259+
notifications.PostPersist = processAppExecResults([]state.AppExecResult{aers[0]}, filter)
32603260

32613261
return notifications, nil
32623262
}

pkg/services/rpcsrv/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2294,7 +2294,7 @@ var rpcTestCases = map[string][]rpcTestCase{
22942294
res, ok := acc.(*result.BlockNotifications)
22952295
require.True(t, ok)
22962296
require.NotNil(t, res)
2297-
for _, ne := range res.TxNotifications {
2297+
for _, ne := range res.Application {
22982298
require.Equal(t, nativehashes.NeoToken, ne.ScriptHash)
22992299
require.Equal(t, "Transfer", ne.Name)
23002300
}

0 commit comments

Comments
 (0)