frostfs-node/pkg/morph/event/container/delete_notary.go

74 lines
1.5 KiB
Go
Raw Normal View History

package container
import (
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
)
func (d *Delete) setContainerID(v []byte) {
if v != nil {
d.ContainerIDValue = v
}
}
func (d *Delete) setSignature(v []byte) {
if v != nil {
d.SignatureValue = v
}
}
func (d *Delete) setPublicKey(v []byte) {
d.PublicKeyValue = v
}
func (d *Delete) setToken(v []byte) {
if v != nil {
d.TokenValue = v
}
}
var deleteFieldSetters = []func(*Delete, []byte){
// order on stack is reversed
(*Delete).setToken,
(*Delete).setPublicKey,
(*Delete).setSignature,
(*Delete).setContainerID,
}
const (
// DeleteNotaryEvent is method name for container delete operations
// in `Container` contract. Is used as identificator for notary
// delete container requests.
DeleteNotaryEvent = "delete"
)
// ParseDeleteNotary from NotaryEvent into container event structure.
func ParseDeleteNotary(ne event.NotaryEvent) (event.Event, error) {
var (
ev Delete
currentOp opcode.Opcode
)
fieldNum := 0
for _, op := range ne.Params() {
currentOp = op.Code()
switch {
case opcode.PUSHDATA1 <= currentOp && currentOp <= opcode.PUSHDATA4:
if fieldNum == expectedItemNumDelete {
return nil, event.UnexpectedArgNumErr(DeleteNotaryEvent)
}
deleteFieldSetters[fieldNum](&ev, op.Param())
fieldNum++
default:
return nil, event.UnexpectedOpcode(DeleteNotaryEvent, op.Code())
}
}
ev.NotaryRequestValue = ne.Raw()
return ev, nil
}