From 822d73fb0288c66f8d5a18c5e52ffb039b9ef2a0 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Thu, 11 Nov 2021 11:59:14 +0300 Subject: [PATCH] [#971] *: Add notification TX hash to neofsid morph client calls Add hash of the TX that generated notification to neofsid event structures. Adapt all neofsid wrapper calls to new structures. Signed-off-by: Pavel Karpy --- pkg/innerring/processors/container/common.go | 6 +++++- .../processors/container/process_container.go | 6 +++++- pkg/innerring/processors/neofs/process_bind.go | 12 +++++++++++- pkg/morph/event/neofs/bind.go | 14 ++++++++++++++ pkg/morph/event/neofs/unbind.go | 2 ++ 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/pkg/innerring/processors/container/common.go b/pkg/innerring/processors/container/common.go index 228746d35..33e0aee44 100644 --- a/pkg/innerring/processors/container/common.go +++ b/pkg/innerring/processors/container/common.go @@ -8,6 +8,7 @@ import ( "fmt" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" + neofsid "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid/wrapper" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/owner" "github.com/nspcc-dev/neofs-sdk-go/session" @@ -65,7 +66,10 @@ func (cp *Processor) checkKeyOwnership(ownerIDSrc ownerIDSource, key *keys.Publi return nil } - ownerKeys, err := cp.idClient.AccountKeys(ownerIDSrc.OwnerID()) + prm := neofsid.AccountKeysPrm{} + prm.SetID(ownerIDSrc.OwnerID()) + + ownerKeys, err := cp.idClient.AccountKeys(prm) if err != nil { return fmt.Errorf("could not received owner keys %s: %w", ownerIDSrc.OwnerID(), err) } diff --git a/pkg/innerring/processors/container/process_container.go b/pkg/innerring/processors/container/process_container.go index 2d3fe1f38..df6f06383 100644 --- a/pkg/innerring/processors/container/process_container.go +++ b/pkg/innerring/processors/container/process_container.go @@ -10,6 +10,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/network/payload" "github.com/nspcc-dev/neofs-api-go/v2/refs" "github.com/nspcc-dev/neofs-node/pkg/core/container" + neofsid "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid/wrapper" "github.com/nspcc-dev/neofs-node/pkg/morph/event" containerEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/container" containerSDK "github.com/nspcc-dev/neofs-sdk-go/container" @@ -198,8 +199,11 @@ func (cp *Processor) checkDeleteContainer(e *containerEvent.Delete) error { checkKeys = keys.PublicKeys{key} } else { + prm := neofsid.AccountKeysPrm{} + prm.SetID(cnr.OwnerID()) + // receive all owner keys from NeoFS ID contract - checkKeys, err = cp.idClient.AccountKeys(cnr.OwnerID()) + checkKeys, err = cp.idClient.AccountKeys(prm) if err != nil { return fmt.Errorf("could not received owner keys %s: %w", cnr.OwnerID(), err) } diff --git a/pkg/innerring/processors/neofs/process_bind.go b/pkg/innerring/processors/neofs/process_bind.go index a05d64369..0932c70b0 100644 --- a/pkg/innerring/processors/neofs/process_bind.go +++ b/pkg/innerring/processors/neofs/process_bind.go @@ -4,6 +4,8 @@ import ( "crypto/elliptic" "fmt" + neofsid "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid/wrapper" + "github.com/mr-tron/base58" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/encoding/address" @@ -15,6 +17,7 @@ import ( type bindCommon interface { User() []byte Keys() [][]byte + TxHash() util.Uint256 } func (np *Processor) processBind(e bindCommon) { @@ -93,7 +96,14 @@ func (np *Processor) approveBindCommon(e *bindCommonContext) { return } - err = np.neofsIDClient.ManageKeys(wallet, e.Keys(), e.bind) + prm := neofsid.ManageKeysPrm{} + + prm.SetOwnerID(wallet) + prm.SetKeys(e.Keys()) + prm.SetAdd(e.bind) + prm.SetHash(e.bindCommon.TxHash()) + + err = np.neofsIDClient.ManageKeys(prm) if err != nil { var typ string diff --git a/pkg/morph/event/neofs/bind.go b/pkg/morph/event/neofs/bind.go index c5c4674e7..8e154c933 100644 --- a/pkg/morph/event/neofs/bind.go +++ b/pkg/morph/event/neofs/bind.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions" + "github.com/nspcc-dev/neo-go/pkg/util" "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/event" @@ -16,6 +17,17 @@ type Bind struct { type bindCommon struct { user []byte keys [][]byte + + // txHash is used in notary environmental + // for calculating unique but same for + // all notification receivers values. + txHash util.Uint256 +} + +// TxHash returns hash of the TX with new epoch +// notification. +func (b bindCommon) TxHash() util.Uint256 { + return b.txHash } // MorphEvent implements Neo:Morph Event interface. @@ -41,6 +53,8 @@ func ParseBind(e *subscriptions.NotificationEvent) (event.Event, error) { return nil, err } + ev.txHash = e.Container + return ev, nil } diff --git a/pkg/morph/event/neofs/unbind.go b/pkg/morph/event/neofs/unbind.go index 8f7bb6c19..5f870e3f8 100644 --- a/pkg/morph/event/neofs/unbind.go +++ b/pkg/morph/event/neofs/unbind.go @@ -27,5 +27,7 @@ func ParseUnbind(e *subscriptions.NotificationEvent) (event.Event, error) { return nil, err } + ev.txHash = e.Container + return ev, nil }