2020-08-11 11:46:31 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
2020-08-11 11:46:31 +00:00
|
|
|
|
2021-08-25 11:35:17 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
2020-10-26 14:46:15 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
2020-08-11 11:46:31 +00:00
|
|
|
"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
|
2021-05-19 14:16:48 +00:00
|
|
|
publicKey []byte
|
2021-05-25 15:52:55 +00:00
|
|
|
token []byte
|
2021-08-25 11:35:17 +00:00
|
|
|
|
|
|
|
// For notary notifications only.
|
|
|
|
// Contains raw transactions of notary request.
|
|
|
|
notaryRequest *payload.P2PNotaryRequest
|
2020-08-11 11:46:31 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 09:15:24 +00:00
|
|
|
const expectedItemNumPut = 4
|
|
|
|
|
2020-08-11 11:46:31 +00:00
|
|
|
// 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.
|
2021-05-19 14:16:48 +00:00
|
|
|
func (p Put) PublicKey() []byte { return p.publicKey }
|
2020-08-11 11:46:31 +00:00
|
|
|
|
2021-05-26 10:48:55 +00:00
|
|
|
// SessionToken returns binary token of the session
|
2021-05-25 15:52:55 +00:00
|
|
|
// within which the container was created.
|
|
|
|
func (p Put) SessionToken() []byte {
|
|
|
|
return p.token
|
|
|
|
}
|
|
|
|
|
2021-08-25 11:35:17 +00:00
|
|
|
// NotaryRequest returns raw notary request if notification
|
|
|
|
// was received via notary service. Otherwise, returns nil.
|
|
|
|
func (p Put) NotaryRequest() *payload.P2PNotaryRequest {
|
|
|
|
return p.notaryRequest
|
|
|
|
}
|
|
|
|
|
2021-10-12 14:42:04 +00:00
|
|
|
// PutNamed represents notification event spawned by PutNamed method from Container contract of NeoFS Morph chain.
|
|
|
|
type PutNamed struct {
|
|
|
|
Put
|
|
|
|
|
|
|
|
name, zone string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Name returns "name" arg of contract call.
|
|
|
|
func (x PutNamed) Name() string {
|
|
|
|
return x.name
|
|
|
|
}
|
|
|
|
|
|
|
|
// Zone returns "zone" arg of contract call.
|
|
|
|
func (x PutNamed) Zone() string {
|
|
|
|
return x.zone
|
|
|
|
}
|
|
|
|
|
2020-08-11 11:46:31 +00:00
|
|
|
// ParsePut from notification into container event structure.
|
2020-10-26 14:46:15 +00:00
|
|
|
func ParsePut(params []stackitem.Item) (event.Event, error) {
|
2020-08-11 11:46:31 +00:00
|
|
|
var (
|
|
|
|
ev Put
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
2021-05-25 09:15:24 +00:00
|
|
|
if ln := len(params); ln != expectedItemNumPut {
|
|
|
|
return nil, event.WrongNumberOfParameters(expectedItemNumPut, ln)
|
2020-08-11 11:46:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// parse container
|
2020-10-26 14:46:15 +00:00
|
|
|
ev.rawContainer, err = client.BytesFromStackItem(params[0])
|
2020-08-11 11:46: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-08-11 11:46:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// parse signature
|
2020-10-26 14:46:15 +00:00
|
|
|
ev.signature, err = client.BytesFromStackItem(params[1])
|
2020-08-11 11:46: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-08-11 11:46:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// parse public key
|
2021-05-19 14:16:48 +00:00
|
|
|
ev.publicKey, err = client.BytesFromStackItem(params[2])
|
2020-08-11 11:46:31 +00:00
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not get public key: %w", err)
|
2020-08-11 11:46:31 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 15:52:55 +00:00
|
|
|
// parse session token
|
|
|
|
ev.token, err = client.BytesFromStackItem(params[3])
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not get sesison token: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-08-11 11:46:31 +00:00
|
|
|
return ev, nil
|
|
|
|
}
|