[#505] morph/container: Do not parse public key in Put event parser

Morph event structures defined in `pkg/morph/event`  should only carry
notification values without any additional interpretation. All logical work
should be concentrated on app-side.

Change data type of `Put.PublicKey` return to byte slice. `ParsePut` doesn't
unmarshal public key from now.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-19 17:16:48 +03:00 committed by Alex Vanin
parent a306eb9ce7
commit a3ac294902
3 changed files with 7 additions and 21 deletions

View file

@ -44,7 +44,7 @@ func (cp *Processor) processContainerPut(put *containerEvent.Put) {
err := cp.morphClient.NotaryInvoke(cp.containerContract, cp.feeProvider.SideChainFee(), putContainerMethod, err := cp.morphClient.NotaryInvoke(cp.containerContract, cp.feeProvider.SideChainFee(), putContainerMethod,
cnrData, cnrData,
put.Signature(), put.Signature(),
put.PublicKey().Bytes()) put.PublicKey())
if err != nil { if err != nil {
cp.log.Error("can't invoke new container", zap.Error(err)) cp.log.Error("can't invoke new container", zap.Error(err))
} }

View file

@ -1,10 +1,8 @@
package container package container
import ( import (
"crypto/elliptic"
"fmt" "fmt"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"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"
@ -14,7 +12,7 @@ import (
type Put struct { type Put struct {
rawContainer []byte rawContainer []byte
signature []byte signature []byte
publicKey *keys.PublicKey publicKey []byte
} }
// MorphEvent implements Neo:Morph Event interface. // MorphEvent implements Neo:Morph Event interface.
@ -27,7 +25,7 @@ func (p Put) Container() []byte { return p.rawContainer }
func (p Put) Signature() []byte { return p.signature } func (p Put) Signature() []byte { return p.signature }
// PublicKey of container owner. // PublicKey of container owner.
func (p Put) PublicKey() *keys.PublicKey { return p.publicKey } func (p Put) PublicKey() []byte { return p.publicKey }
// ParsePut from notification into container event structure. // ParsePut from notification into container event structure.
func ParsePut(params []stackitem.Item) (event.Event, error) { func ParsePut(params []stackitem.Item) (event.Event, error) {
@ -53,15 +51,10 @@ func ParsePut(params []stackitem.Item) (event.Event, error) {
} }
// parse public key // parse public key
key, err := client.BytesFromStackItem(params[2]) ev.publicKey, err = client.BytesFromStackItem(params[2])
if err != nil { if err != nil {
return nil, fmt.Errorf("could not get public key: %w", err) return nil, fmt.Errorf("could not get public key: %w", err)
} }
ev.publicKey, err = keys.NewPublicKeyFromBytes(key, elliptic.P256())
if err != nil {
return nil, fmt.Errorf("could not parse public key: %w", err)
}
return ev, nil return ev, nil
} }

View file

@ -1,14 +1,10 @@
package container package container
import ( import (
"crypto/elliptic"
"testing" "testing"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/nspcc-dev/neofs-node/pkg/util/test"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -16,7 +12,7 @@ func TestParsePut(t *testing.T) {
var ( var (
containerData = []byte("containerData") containerData = []byte("containerData")
signature = []byte("signature") signature = []byte("signature")
publicKey = &test.DecodeKey(-1).PublicKey publicKey = []byte("pubkey")
) )
t.Run("wrong number of parameters", func(t *testing.T) { t.Run("wrong number of parameters", func(t *testing.T) {
@ -60,17 +56,14 @@ func TestParsePut(t *testing.T) {
ev, err := ParsePut([]stackitem.Item{ ev, err := ParsePut([]stackitem.Item{
stackitem.NewByteArray(containerData), stackitem.NewByteArray(containerData),
stackitem.NewByteArray(signature), stackitem.NewByteArray(signature),
stackitem.NewByteArray(crypto.MarshalPublicKey(publicKey)), stackitem.NewByteArray(publicKey),
}) })
require.NoError(t, err) require.NoError(t, err)
expectedKey, err := keys.NewPublicKeyFromBytes(crypto.MarshalPublicKey(publicKey), elliptic.P256())
require.NoError(t, err)
require.Equal(t, Put{ require.Equal(t, Put{
rawContainer: containerData, rawContainer: containerData,
signature: signature, signature: signature,
publicKey: expectedKey, publicKey: publicKey,
}, ev) }, ev)
}) })
} }