2020-07-10 14:17:51 +00:00
|
|
|
package event
|
|
|
|
|
2021-04-13 12:53:58 +00:00
|
|
|
import (
|
2021-10-22 10:06:08 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
2023-04-12 14:35:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
|
|
|
util2 "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
2021-08-15 17:03:15 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/mempoolevent"
|
2022-07-28 16:22:32 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
2021-04-13 12:53:58 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2021-10-22 10:06:08 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
2021-04-13 12:53:58 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
2020-07-10 14:17:51 +00:00
|
|
|
|
|
|
|
type scriptHashValue struct {
|
|
|
|
hash util.Uint160
|
|
|
|
}
|
|
|
|
|
|
|
|
type typeValue struct {
|
|
|
|
typ Type
|
|
|
|
}
|
|
|
|
|
|
|
|
type scriptHashWithType struct {
|
|
|
|
scriptHashValue
|
|
|
|
typeValue
|
|
|
|
}
|
|
|
|
|
2021-08-15 17:03:15 +00:00
|
|
|
type notaryRequestTypes struct {
|
|
|
|
notaryRequestMempoolType
|
|
|
|
notaryRequestType
|
|
|
|
scriptHashValue
|
|
|
|
}
|
|
|
|
|
|
|
|
type notaryRequestMempoolType struct {
|
|
|
|
mempoolTyp mempoolevent.Type
|
|
|
|
}
|
|
|
|
|
|
|
|
type notaryRequestType struct {
|
|
|
|
notaryType NotaryType
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetMempoolType is a notary request mempool type getter.
|
|
|
|
func (n notaryRequestMempoolType) GetMempoolType() mempoolevent.Type {
|
|
|
|
return n.mempoolTyp
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetMempoolType is a notary request mempool type setter.
|
|
|
|
func (n *notaryRequestMempoolType) SetMempoolType(typ mempoolevent.Type) {
|
|
|
|
n.mempoolTyp = typ
|
|
|
|
}
|
|
|
|
|
|
|
|
// RequestType is a notary request type getter.
|
|
|
|
func (n notaryRequestType) RequestType() NotaryType {
|
|
|
|
return n.notaryType
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetRequestType is a notary request type setter.
|
|
|
|
func (n *notaryRequestType) SetRequestType(typ NotaryType) {
|
|
|
|
n.notaryType = typ
|
|
|
|
}
|
|
|
|
|
2020-07-10 14:17:51 +00:00
|
|
|
// SetScriptHash is a script hash setter.
|
|
|
|
func (s *scriptHashValue) SetScriptHash(v util.Uint160) {
|
|
|
|
s.hash = v
|
|
|
|
}
|
|
|
|
|
2021-08-15 17:03:15 +00:00
|
|
|
// ScriptHash is a script hash getter.
|
2020-07-24 13:54:03 +00:00
|
|
|
func (s scriptHashValue) ScriptHash() util.Uint160 {
|
2020-07-10 14:17:51 +00:00
|
|
|
return s.hash
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetType is an event type setter.
|
|
|
|
func (s *typeValue) SetType(v Type) {
|
|
|
|
s.typ = v
|
|
|
|
}
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
// GetType is an event type getter.
|
|
|
|
func (s typeValue) GetType() Type {
|
2020-07-10 14:17:51 +00:00
|
|
|
return s.typ
|
|
|
|
}
|
2021-04-13 12:53:58 +00:00
|
|
|
|
|
|
|
// WorkerPoolHandler sets closure over worker pool w with passed handler h.
|
2022-09-28 07:41:01 +00:00
|
|
|
func WorkerPoolHandler(w util2.WorkerPool, h Handler, log *logger.Logger) Handler {
|
2021-04-13 12:53:58 +00:00
|
|
|
return func(e Event) {
|
|
|
|
err := w.Submit(func() {
|
|
|
|
h(e)
|
|
|
|
})
|
|
|
|
if err != nil {
|
2023-04-12 14:35:10 +00:00
|
|
|
log.Warn(logs.EventCouldNotSubmitHandlerToWorkerPool,
|
2021-04-13 12:53:58 +00:00
|
|
|
zap.String("error", err.Error()),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-22 10:06:08 +00:00
|
|
|
|
|
|
|
var errEmptyStackArray = errors.New("stack item array is empty")
|
|
|
|
|
|
|
|
// ParseStackArray parses stack array from raw notification
|
|
|
|
// event received from neo-go RPC node.
|
2022-07-28 16:22:32 +00:00
|
|
|
func ParseStackArray(event *state.ContainedNotificationEvent) ([]stackitem.Item, error) {
|
2021-10-22 10:06:08 +00:00
|
|
|
arr, err := client.ArrayFromStackItem(event.Item)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("stack item is not an array type: %w", err)
|
|
|
|
} else if len(arr) == 0 {
|
|
|
|
return nil, errEmptyStackArray
|
|
|
|
}
|
|
|
|
|
|
|
|
return arr, nil
|
|
|
|
}
|