frostfs-node/pkg/morph/event/container/put.go
Leonard Lyubich a3ac294902 [#505] morph/container: Do not parse public key in Put event parser
Morph event structures defined in `pkg/morph/event`  should only carry
notification values without any additional interpretation. All logical work
should be concentrated on app-side.

Change data type of `Put.PublicKey` return to byte slice. `ParsePut` doesn't
unmarshal public key from now.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-05-25 16:35:52 +03:00

60 lines
1.5 KiB
Go

package container
import (
"fmt"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
)
// Put structure of container.Put notification from morph chain.
type Put struct {
rawContainer []byte
signature []byte
publicKey []byte
}
// MorphEvent implements Neo:Morph Event interface.
func (Put) MorphEvent() {}
// Container is a marshalled container structure, defined in API.
func (p Put) Container() []byte { return p.rawContainer }
// Signature of marshalled container by container owner.
func (p Put) Signature() []byte { return p.signature }
// PublicKey of container owner.
func (p Put) PublicKey() []byte { return p.publicKey }
// ParsePut from notification into container event structure.
func ParsePut(params []stackitem.Item) (event.Event, error) {
var (
ev Put
err error
)
if ln := len(params); ln != 3 {
return nil, event.WrongNumberOfParameters(3, ln)
}
// parse container
ev.rawContainer, err = client.BytesFromStackItem(params[0])
if err != nil {
return nil, fmt.Errorf("could not get container: %w", err)
}
// parse signature
ev.signature, err = client.BytesFromStackItem(params[1])
if err != nil {
return nil, fmt.Errorf("could not get signature: %w", err)
}
// parse public key
ev.publicKey, err = client.BytesFromStackItem(params[2])
if err != nil {
return nil, fmt.Errorf("could not get public key: %w", err)
}
return ev, nil
}