-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3805 from nspcc-dev/block-notifications
- Loading branch information
Showing
7 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package result | ||
|
||
import ( | ||
"github.com/nspcc-dev/neo-go/pkg/core/state" | ||
) | ||
|
||
// BlockNotifications represents notifications from a block organized by | ||
// trigger type. | ||
type BlockNotifications struct { | ||
// 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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package rpcsrv | ||
|
||
import ( | ||
"github.com/nspcc-dev/neo-go/pkg/core/state" | ||
"github.com/nspcc-dev/neo-go/pkg/neorpc" | ||
"github.com/nspcc-dev/neo-go/pkg/neorpc/rpcevent" | ||
"github.com/nspcc-dev/neo-go/pkg/util" | ||
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate" | ||
) | ||
|
||
// notificationEventComparator is a comparator for notification events. | ||
type notificationEventComparator struct { | ||
filter neorpc.SubscriptionFilter | ||
} | ||
|
||
// EventID returns the event ID for the notification event comparator. | ||
func (s notificationEventComparator) EventID() neorpc.EventID { | ||
return neorpc.NotificationEventID | ||
} | ||
|
||
// Filter returns the filter for the notification event comparator. | ||
func (c notificationEventComparator) Filter() neorpc.SubscriptionFilter { | ||
return c.filter | ||
} | ||
|
||
// notificationEventContainer is a container for a notification event. | ||
type notificationEventContainer struct { | ||
ntf *state.ContainedNotificationEvent | ||
} | ||
|
||
// EventID returns the event ID for the notification event container. | ||
func (c notificationEventContainer) EventID() neorpc.EventID { | ||
return neorpc.NotificationEventID | ||
} | ||
|
||
// EventPayload returns the payload for the notification event container. | ||
func (c notificationEventContainer) EventPayload() any { | ||
return c.ntf | ||
} | ||
|
||
func processAppExecResults(aers []state.AppExecResult, filter *neorpc.NotificationFilter) []state.ContainedNotificationEvent { | ||
var notifications []state.ContainedNotificationEvent | ||
for _, aer := range aers { | ||
if aer.VMState == vmstate.Halt { | ||
notifications = append(notifications, filterEvents(aer.Events, aer.Container, filter)...) | ||
} | ||
} | ||
return notifications | ||
} | ||
|
||
func filterEvents(events []state.NotificationEvent, container util.Uint256, filter *neorpc.NotificationFilter) []state.ContainedNotificationEvent { | ||
var notifications []state.ContainedNotificationEvent | ||
for _, evt := range events { | ||
ntf := state.ContainedNotificationEvent{ | ||
Container: container, | ||
NotificationEvent: evt, | ||
} | ||
if filter == nil || rpcevent.Matches(¬ificationEventComparator{ | ||
filter: *filter, | ||
}, ¬ificationEventContainer{ntf: &ntf}) { | ||
notifications = append(notifications, ntf) | ||
} | ||
} | ||
return notifications | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters