[#971] morph/event: Change notification parser's signature

Parsers should have original notification
structure to be able to construct internal
event structure that contains necessary
for unique nonce calculation information.
So notification parsers take raw notification
structure instead of slice of stack items.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-10-22 13:06:08 +03:00 committed by Alex Vanin
parent 3666ae7ad2
commit c167ae26f9
35 changed files with 365 additions and 203 deletions

View file

@ -1,8 +1,14 @@
package event
import (
"errors"
"fmt"
"github.com/nspcc-dev/neo-go/pkg/core/mempoolevent"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
util2 "github.com/nspcc-dev/neofs-node/pkg/util"
"go.uber.org/zap"
)
@ -88,3 +94,18 @@ func WorkerPoolHandler(w util2.WorkerPool, h Handler, log *zap.Logger) Handler {
}
}
}
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 *subscriptions.NotificationEvent) ([]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
}