forked from TrueCloudLab/frostfs-node
[#505] ir: Process set eACL notifications from Container contract
Add `setEACL` notification event parser (handler) to the return of the `ListenerParsers` (`ListenerHandlers`) method. Read address of NeoFS ID contract from `contracts.neofsid` config. Implement `NewNeoFSIDClient` constructor in `invoke` package and use it in IR application. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
4949f4b064
commit
a306eb9ce7
3 changed files with 48 additions and 9 deletions
|
@ -27,6 +27,7 @@ import (
|
||||||
auditWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/audit/wrapper"
|
auditWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/audit/wrapper"
|
||||||
balanceWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/balance/wrapper"
|
balanceWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/balance/wrapper"
|
||||||
cntWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
cntWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
||||||
|
neofsid "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid/wrapper"
|
||||||
nmWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
|
nmWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
|
||||||
repWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation/wrapper"
|
repWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation/wrapper"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||||
|
@ -101,6 +102,7 @@ type (
|
||||||
proxy util.Uint160 // in morph
|
proxy util.Uint160 // in morph
|
||||||
processing util.Uint160 // in mainnet
|
processing util.Uint160 // in mainnet
|
||||||
reputation util.Uint160 // in morph
|
reputation util.Uint160 // in morph
|
||||||
|
neofsID util.Uint160 // in morph
|
||||||
|
|
||||||
alphabet alphabetContracts // in morph
|
alphabet alphabetContracts // in morph
|
||||||
}
|
}
|
||||||
|
@ -375,6 +377,11 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
neofsIDClient, err := neofsid.NewFromMorph(server.morphClient, server.contracts.neofsID, fee)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// create global runtime config reader
|
// create global runtime config reader
|
||||||
globalConfig := config.NewGlobalConfigReader(cfg, nmClient)
|
globalConfig := config.NewGlobalConfigReader(cfg, nmClient)
|
||||||
|
|
||||||
|
@ -545,6 +552,8 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
MorphClient: server.morphClient,
|
MorphClient: server.morphClient,
|
||||||
AlphabetState: server,
|
AlphabetState: server,
|
||||||
FeeProvider: server.feeConfig,
|
FeeProvider: server.feeConfig,
|
||||||
|
ContainerClient: cnrClient,
|
||||||
|
NeoFSIDClient: neofsIDClient,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -744,6 +753,7 @@ func parseContracts(cfg *viper.Viper) (*contracts, error) {
|
||||||
proxyContractStr := cfg.GetString("contracts.proxy")
|
proxyContractStr := cfg.GetString("contracts.proxy")
|
||||||
processingContractStr := cfg.GetString("contracts.processing")
|
processingContractStr := cfg.GetString("contracts.processing")
|
||||||
reputationContractStr := cfg.GetString("contracts.reputation")
|
reputationContractStr := cfg.GetString("contracts.reputation")
|
||||||
|
neofsIDContractStr := cfg.GetString("contracts.neofsid")
|
||||||
|
|
||||||
result.netmap, err = util.Uint160DecodeStringLE(netmapContractStr)
|
result.netmap, err = util.Uint160DecodeStringLE(netmapContractStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -785,6 +795,11 @@ func parseContracts(cfg *viper.Viper) (*contracts, error) {
|
||||||
return nil, fmt.Errorf("ir: can't read reputation script-hash: %w", err)
|
return nil, fmt.Errorf("ir: can't read reputation script-hash: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.neofsID, err = util.Uint160DecodeStringLE(neofsIDContractStr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("ir: can't read NeoFS ID script-hash: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
result.alphabet, err = parseAlphabetContracts(cfg)
|
result.alphabet, err = parseAlphabetContracts(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -41,12 +41,16 @@ type (
|
||||||
MorphClient *client.Client
|
MorphClient *client.Client
|
||||||
AlphabetState AlphabetState
|
AlphabetState AlphabetState
|
||||||
FeeProvider *config.FeeConfig
|
FeeProvider *config.FeeConfig
|
||||||
|
ContainerClient *wrapper.Wrapper
|
||||||
|
NeoFSIDClient *neofsid.ClientWrapper
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
putNotification = "containerPut"
|
putNotification = "containerPut"
|
||||||
deleteNotification = "containerDelete"
|
deleteNotification = "containerDelete"
|
||||||
|
|
||||||
|
setEACLNotification = "setEACL"
|
||||||
)
|
)
|
||||||
|
|
||||||
// New creates container contract processor instance.
|
// New creates container contract processor instance.
|
||||||
|
@ -60,6 +64,10 @@ func New(p *Params) (*Processor, error) {
|
||||||
return nil, errors.New("ir/container: global state is not set")
|
return nil, errors.New("ir/container: global state is not set")
|
||||||
case p.FeeProvider == nil:
|
case p.FeeProvider == nil:
|
||||||
return nil, errors.New("ir/container: fee provider is not set")
|
return nil, errors.New("ir/container: fee provider is not set")
|
||||||
|
case p.ContainerClient == nil:
|
||||||
|
return nil, errors.New("ir/container: Container client is not set")
|
||||||
|
case p.NeoFSIDClient == nil:
|
||||||
|
return nil, errors.New("ir/container: NeoFS ID client is not set")
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Log.Debug("container worker pool", zap.Int("size", p.PoolSize))
|
p.Log.Debug("container worker pool", zap.Int("size", p.PoolSize))
|
||||||
|
@ -76,13 +84,15 @@ func New(p *Params) (*Processor, error) {
|
||||||
morphClient: p.MorphClient,
|
morphClient: p.MorphClient,
|
||||||
alphabetState: p.AlphabetState,
|
alphabetState: p.AlphabetState,
|
||||||
feeProvider: p.FeeProvider,
|
feeProvider: p.FeeProvider,
|
||||||
|
cnrClient: p.ContainerClient,
|
||||||
|
idClient: p.NeoFSIDClient,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenerParsers for the 'event.Listener' event producer.
|
// ListenerParsers for the 'event.Listener' event producer.
|
||||||
func (cp *Processor) ListenerParsers() []event.ParserInfo {
|
func (cp *Processor) ListenerParsers() []event.ParserInfo {
|
||||||
var (
|
var (
|
||||||
parsers = make([]event.ParserInfo, 0, 2)
|
parsers = make([]event.ParserInfo, 0, 3)
|
||||||
|
|
||||||
p event.ParserInfo
|
p event.ParserInfo
|
||||||
)
|
)
|
||||||
|
@ -99,13 +109,18 @@ func (cp *Processor) ListenerParsers() []event.ParserInfo {
|
||||||
p.SetParser(containerEvent.ParseDelete)
|
p.SetParser(containerEvent.ParseDelete)
|
||||||
parsers = append(parsers, p)
|
parsers = append(parsers, p)
|
||||||
|
|
||||||
|
// set eACL
|
||||||
|
p.SetType(event.TypeFromString(setEACLNotification))
|
||||||
|
p.SetParser(containerEvent.ParseSetEACL)
|
||||||
|
parsers = append(parsers, p)
|
||||||
|
|
||||||
return parsers
|
return parsers
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenerHandlers for the 'event.Listener' event producer.
|
// ListenerHandlers for the 'event.Listener' event producer.
|
||||||
func (cp *Processor) ListenerHandlers() []event.HandlerInfo {
|
func (cp *Processor) ListenerHandlers() []event.HandlerInfo {
|
||||||
var (
|
var (
|
||||||
handlers = make([]event.HandlerInfo, 0, 2)
|
handlers = make([]event.HandlerInfo, 0, 3)
|
||||||
|
|
||||||
h event.HandlerInfo
|
h event.HandlerInfo
|
||||||
)
|
)
|
||||||
|
@ -122,6 +137,11 @@ func (cp *Processor) ListenerHandlers() []event.HandlerInfo {
|
||||||
h.SetHandler(cp.handleDelete)
|
h.SetHandler(cp.handleDelete)
|
||||||
handlers = append(handlers, h)
|
handlers = append(handlers, h)
|
||||||
|
|
||||||
|
// set eACL
|
||||||
|
h.SetType(event.TypeFromString(setEACLNotification))
|
||||||
|
h.SetHandler(cp.handleSetEACL)
|
||||||
|
handlers = append(handlers, h)
|
||||||
|
|
||||||
return handlers
|
return handlers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
package neofsid
|
package neofsid
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,13 +16,12 @@ import (
|
||||||
// Working ClientWrapper must be created via Wrap.
|
// Working ClientWrapper must be created via Wrap.
|
||||||
type ClientWrapper neofsid.Client
|
type ClientWrapper neofsid.Client
|
||||||
|
|
||||||
// Wrap creates, initializes and returns the ClientWrapper instance.
|
// NewFromMorph wraps client to work with NeoFS ID contract.
|
||||||
//
|
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8) (*ClientWrapper, error) {
|
||||||
// If c is nil, panic occurs.
|
sc, err := client.NewStatic(cli, contract, fee)
|
||||||
func Wrap(c *neofsid.Client) *ClientWrapper {
|
if err != nil {
|
||||||
if c == nil {
|
return nil, fmt.Errorf("could not create client of NeoFS ID contract: %w", err)
|
||||||
panic("neofs ID client is nil")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (*ClientWrapper)(c)
|
return (*ClientWrapper)(neofsid.New(sc)), nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue