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

76 lines
1.5 KiB
Go
Raw Permalink 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 (x *SetEACL) setTable(v []byte) {
if v != nil {
x.TableValue = v
}
}
func (x *SetEACL) setSignature(v []byte) {
if v != nil {
x.SignatureValue = v
}
}
func (x *SetEACL) setPublicKey(v []byte) {
if v != nil {
x.PublicKeyValue = v
}
}
func (x *SetEACL) setToken(v []byte) {
if v != nil {
x.TokenValue = v
}
}
var setEACLFieldSetters = []func(*SetEACL, []byte){
// order on stack is reversed
(*SetEACL).setToken,
(*SetEACL).setPublicKey,
(*SetEACL).setSignature,
(*SetEACL).setTable,
}
const (
// SetEACLNotaryEvent is method name for container EACL operations
// in `Container` contract. Is used as identificator for notary
// EACL changing requests.
SetEACLNotaryEvent = "setEACL"
)
// ParseSetEACLNotary from NotaryEvent into container event structure.
func ParseSetEACLNotary(ne event.NotaryEvent) (event.Event, error) {
var (
ev SetEACL
currentOp opcode.Opcode
)
fieldNum := 0
for _, op := range ne.Params() {
currentOp = op.Code()
switch {
case opcode.PUSHDATA1 <= currentOp && currentOp <= opcode.PUSHDATA4:
if fieldNum == expectedItemNumEACL {
return nil, event.UnexpectedArgNumErr(SetEACLNotaryEvent)
}
setEACLFieldSetters[fieldNum](&ev, op.Param())
fieldNum++
default:
return nil, event.UnexpectedOpcode(SetEACLNotaryEvent, op.Code())
}
}
ev.NotaryRequestValue = ne.Raw()
return ev, nil
}