2020-09-02 13:05:31 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2020-10-26 14:46:15 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
2020-09-02 13:05:31 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Delete structure of container.Delete notification from morph chain.
|
|
|
|
type Delete struct {
|
|
|
|
containerID []byte
|
|
|
|
signature []byte
|
2021-05-26 10:55:58 +00:00
|
|
|
token []byte
|
2020-09-02 13:05:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MorphEvent implements Neo:Morph Event interface.
|
|
|
|
func (Delete) MorphEvent() {}
|
|
|
|
|
2021-08-25 10:51:15 +00:00
|
|
|
// ContainerID is a marshalled container structure, defined in API.
|
2020-09-02 13:05:31 +00:00
|
|
|
func (d Delete) ContainerID() []byte { return d.containerID }
|
|
|
|
|
|
|
|
// Signature of marshalled container by container owner.
|
|
|
|
func (d Delete) Signature() []byte { return d.signature }
|
|
|
|
|
2021-05-26 10:55:58 +00:00
|
|
|
// SessionToken returns binary token of the session
|
|
|
|
// within which the eACL was set.
|
|
|
|
func (d Delete) SessionToken() []byte {
|
|
|
|
return d.token
|
|
|
|
}
|
|
|
|
|
2020-09-02 13:05:31 +00:00
|
|
|
// ParseDelete from notification into container event structure.
|
2021-05-26 10:55:58 +00:00
|
|
|
//
|
|
|
|
// Expects 3 stack items.
|
2020-10-26 14:46:15 +00:00
|
|
|
func ParseDelete(params []stackitem.Item) (event.Event, error) {
|
2020-09-02 13:05:31 +00:00
|
|
|
var (
|
|
|
|
ev Delete
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
2021-05-26 10:55:58 +00:00
|
|
|
const expectedItemNumEACL = 3
|
|
|
|
|
|
|
|
if ln := len(params); ln != expectedItemNumEACL {
|
|
|
|
return nil, event.WrongNumberOfParameters(expectedItemNumEACL, ln)
|
2020-09-02 13:05:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// parse container
|
2020-10-26 14:46:15 +00:00
|
|
|
ev.containerID, err = client.BytesFromStackItem(params[0])
|
2020-09-02 13:05:31 +00:00
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not get container: %w", err)
|
2020-09-02 13:05:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// parse signature
|
2020-10-26 14:46:15 +00:00
|
|
|
ev.signature, err = client.BytesFromStackItem(params[1])
|
2020-09-02 13:05:31 +00:00
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not get signature: %w", err)
|
2020-09-02 13:05:31 +00:00
|
|
|
}
|
|
|
|
|
2021-05-26 10:55:58 +00:00
|
|
|
// parse session token
|
|
|
|
ev.token, err = client.BytesFromStackItem(params[2])
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not get session token: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-09-02 13:05:31 +00:00
|
|
|
return ev, nil
|
|
|
|
}
|