Aleksey Savchuk
f0c43c8d80
All checks were successful
Vulncheck / Vulncheck (pull_request) Successful in 3m1s
Pre-commit hooks / Pre-commit (pull_request) Successful in 3m29s
Tests and linters / gopls check (pull_request) Successful in 3m50s
Tests and linters / Lint (pull_request) Successful in 4m35s
DCO action / DCO (pull_request) Successful in 5m12s
Tests and linters / Run gofumpt (pull_request) Successful in 5m33s
Build / Build Components (pull_request) Successful in 5m45s
Tests and linters / Tests with -race (pull_request) Successful in 6m37s
Tests and linters / Tests (pull_request) Successful in 7m17s
Tests and linters / Staticcheck (pull_request) Successful in 7m36s
Tests and linters / Run gofumpt (push) Successful in 1m22s
Tests and linters / Staticcheck (push) Successful in 3m19s
Tests and linters / Lint (push) Successful in 4m35s
Vulncheck / Vulncheck (push) Successful in 5m20s
Build / Build Components (push) Successful in 6m16s
Pre-commit hooks / Pre-commit (push) Successful in 6m37s
Tests and linters / Tests (push) Successful in 6m48s
Tests and linters / Tests with -race (push) Successful in 7m15s
Tests and linters / gopls check (push) Successful in 7m27s
Use `zap.Error` instead of `zap.String` for logging errors: change all expressions like `zap.String("error", err.Error())` or `zap.String("err", err.Error())` to `zap.Error(err)`. Leave similar expressions with other messages unchanged, for example, `zap.String("last_error", lastErr.Error())` or `zap.String("reason", ctx.Err().Error())`. This change was made by applying the following patch: ```diff @@ var err expression @@ -zap.String("error", err.Error()) +zap.Error(err) @@ var err expression @@ -zap.String("err", err.Error()) +zap.Error(err) ``` Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
99 lines
2.4 KiB
Go
99 lines
2.4 KiB
Go
package event
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
|
"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"
|
|
"github.com/nspcc-dev/neo-go/pkg/core/mempoolevent"
|
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type scriptHashValue struct {
|
|
hash util.Uint160
|
|
}
|
|
|
|
type scriptHashWithType struct {
|
|
Hash util.Uint160
|
|
Type Type
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
// SetScriptHash is a script hash setter.
|
|
func (s *scriptHashValue) SetScriptHash(v util.Uint160) {
|
|
s.hash = v
|
|
}
|
|
|
|
// ScriptHash is a script hash getter.
|
|
func (s scriptHashValue) ScriptHash() util.Uint160 {
|
|
return s.hash
|
|
}
|
|
|
|
// WorkerPoolHandler sets closure over worker pool w with passed handler h.
|
|
func WorkerPoolHandler(w util2.WorkerPool, h Handler, log *logger.Logger) Handler {
|
|
return func(ctx context.Context, e Event) {
|
|
err := w.Submit(func() {
|
|
h(ctx, e)
|
|
})
|
|
if err != nil {
|
|
log.Warn(ctx, logs.EventCouldNotSubmitHandlerToWorkerPool,
|
|
zap.Error(err),
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
var errEmptyStackArray = errors.New("stack item array is empty")
|
|
|
|
// ParseStackArray parses stack array from raw notification
|
|
// event received from neo-go RPC node.
|
|
func ParseStackArray(event *state.ContainedNotificationEvent) ([]stackitem.Item, error) {
|
|
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
|
|
}
|