[#807] morph/event/container: Add setEACL
notary support
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
e03b44ffc1
commit
539da27ccb
4 changed files with 110 additions and 7 deletions
|
@ -83,7 +83,15 @@ func (cp *Processor) checkSetEACL(e container.SetEACL) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cp *Processor) approveSetEACL(e container.SetEACL) {
|
func (cp *Processor) approveSetEACL(e container.SetEACL) {
|
||||||
err := cp.cnrClient.PutEACL(e.Table(), e.PublicKey(), e.Signature(), e.SessionToken())
|
var err error
|
||||||
|
|
||||||
|
if nr := e.NotaryRequest(); nr != nil {
|
||||||
|
// setEACL event was received via Notary service
|
||||||
|
err = cp.cnrClient.Morph().NotarySignAndInvokeTX(nr.MainTransaction)
|
||||||
|
} else {
|
||||||
|
// setEACL event was received via notification service
|
||||||
|
err = cp.cnrClient.PutEACL(e.Table(), e.PublicKey(), e.Signature(), e.SessionToken())
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cp.log.Error("could not approve set EACL",
|
cp.log.Error("could not approve set EACL",
|
||||||
zap.String("error", err.Error()),
|
zap.String("error", err.Error()),
|
||||||
|
|
|
@ -181,6 +181,11 @@ func (cp *Processor) ListenerNotaryParsers() []event.NotaryParserInfo {
|
||||||
p.SetParser(containerEvent.ParseDeleteNotary)
|
p.SetParser(containerEvent.ParseDeleteNotary)
|
||||||
pp = append(pp, p)
|
pp = append(pp, p)
|
||||||
|
|
||||||
|
// set EACL
|
||||||
|
p.SetRequestType(containerEvent.SetEACLNotaryEvent)
|
||||||
|
p.SetParser(containerEvent.ParseSetEACLNotary)
|
||||||
|
pp = append(pp, p)
|
||||||
|
|
||||||
return pp
|
return pp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,6 +210,11 @@ func (cp *Processor) ListenerNotaryHandlers() []event.NotaryHandlerInfo {
|
||||||
h.SetHandler(cp.handleDelete)
|
h.SetHandler(cp.handleDelete)
|
||||||
hh = append(hh, h)
|
hh = append(hh, h)
|
||||||
|
|
||||||
|
// set eACL
|
||||||
|
h.SetRequestType(containerEvent.SetEACLNotaryEvent)
|
||||||
|
h.SetHandler(cp.handleSetEACL)
|
||||||
|
hh = append(hh, h)
|
||||||
|
|
||||||
return hh
|
return hh
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package container
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
"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/client"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||||
|
@ -12,12 +13,13 @@ import (
|
||||||
// modified eACL table coming from NeoFS Container contract.
|
// modified eACL table coming from NeoFS Container contract.
|
||||||
type SetEACL struct {
|
type SetEACL struct {
|
||||||
table []byte
|
table []byte
|
||||||
|
|
||||||
signature []byte
|
signature []byte
|
||||||
|
|
||||||
publicKey []byte
|
publicKey []byte
|
||||||
|
|
||||||
token []byte
|
token []byte
|
||||||
|
|
||||||
|
// For notary notifications only.
|
||||||
|
// Contains raw transactions of notary request.
|
||||||
|
notaryRequest *payload.P2PNotaryRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
// MorphEvent implements Neo:Morph Event interface.
|
// MorphEvent implements Neo:Morph Event interface.
|
||||||
|
@ -45,6 +47,14 @@ func (x SetEACL) SessionToken() []byte {
|
||||||
return x.token
|
return x.token
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NotaryRequest returns raw notary request if notification
|
||||||
|
// was received via notary service. Otherwise, returns nil.
|
||||||
|
func (x SetEACL) NotaryRequest() *payload.P2PNotaryRequest {
|
||||||
|
return x.notaryRequest
|
||||||
|
}
|
||||||
|
|
||||||
|
const expectedItemNumEACL = 4
|
||||||
|
|
||||||
// ParseSetEACL parses SetEACL notification event from list of stack items.
|
// ParseSetEACL parses SetEACL notification event from list of stack items.
|
||||||
//
|
//
|
||||||
// Expects 4 stack items.
|
// Expects 4 stack items.
|
||||||
|
@ -54,8 +64,6 @@ func ParseSetEACL(items []stackitem.Item) (event.Event, error) {
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
const expectedItemNumEACL = 4
|
|
||||||
|
|
||||||
if ln := len(items); ln != expectedItemNumEACL {
|
if ln := len(items); ln != expectedItemNumEACL {
|
||||||
return nil, event.WrongNumberOfParameters(expectedItemNumEACL, ln)
|
return nil, event.WrongNumberOfParameters(expectedItemNumEACL, ln)
|
||||||
}
|
}
|
||||||
|
|
77
pkg/morph/event/container/eacl_notary.go
Normal file
77
pkg/morph/event/container/eacl_notary.go
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
package container
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (x *SetEACL) setTable(v []byte) {
|
||||||
|
if v != nil {
|
||||||
|
x.table = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SetEACL) setSignature(v []byte) {
|
||||||
|
if v != nil {
|
||||||
|
x.signature = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SetEACL) setPublicKey(v []byte) {
|
||||||
|
if v != nil {
|
||||||
|
x.publicKey = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *SetEACL) setToken(v []byte) {
|
||||||
|
if v != nil {
|
||||||
|
x.token = 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++
|
||||||
|
case opcode.PUSH0 <= currentOp && currentOp <= opcode.PUSH16 || currentOp == opcode.PACK:
|
||||||
|
// array packing opcodes. do nothing with it
|
||||||
|
default:
|
||||||
|
return nil, event.UnexpectedOpcode(SetEACLNotaryEvent, op.Code())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ev.notaryRequest = ne.Raw()
|
||||||
|
|
||||||
|
return ev, nil
|
||||||
|
}
|
Loading…
Reference in a new issue