forked from TrueCloudLab/frostfs-node
[#496] morph/client: add wrapper for neofs contract
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
458fc4f5ae
commit
16e9e726ff
8 changed files with 66 additions and 45 deletions
|
@ -27,6 +27,7 @@ import (
|
|||
auditWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/audit/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"
|
||||
neofsWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs/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"
|
||||
repWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation/wrapper"
|
||||
|
@ -417,6 +418,12 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
|||
return nil, err
|
||||
}
|
||||
|
||||
neofsClient, err := neofsWrapper.NewFromMorph(server.mainnetClient, server.contracts.neofs,
|
||||
server.feeConfig.MainChainFee())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// create global runtime config reader
|
||||
globalConfig := config.NewGlobalConfigReader(cfg, server.netmapClient)
|
||||
|
||||
|
@ -517,7 +524,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
|||
// create governance processor
|
||||
governanceProcessor, err := governance.New(&governance.Params{
|
||||
Log: log,
|
||||
NeoFSContract: server.contracts.neofs,
|
||||
NeoFSClient: neofsClient,
|
||||
NetmapClient: server.netmapClient,
|
||||
AlphabetState: server,
|
||||
EpochState: server,
|
||||
|
@ -525,7 +532,6 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
|||
MorphClient: server.morphClient,
|
||||
MainnetClient: server.mainnetClient,
|
||||
NotaryDisabled: server.sideNotaryConfig.disabled,
|
||||
FeeProvider: server.feeConfig,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -598,12 +604,10 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
|||
balanceProcessor, err := balance.New(&balance.Params{
|
||||
Log: log,
|
||||
PoolSize: cfg.GetInt("workers.balance"),
|
||||
NeoFSContract: server.contracts.neofs,
|
||||
NeoFSClient: neofsClient,
|
||||
BalanceContract: server.contracts.balance,
|
||||
MainnetClient: server.mainnetClient,
|
||||
AlphabetState: server,
|
||||
Converter: &server.precision,
|
||||
FeeProvider: server.feeConfig,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -5,8 +5,6 @@ import (
|
|||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const chequeMethod = "cheque"
|
||||
|
||||
// Process lock event by invoking Cheque method in main net to send assets
|
||||
// back to the withdraw issuer.
|
||||
func (bp *Processor) processLock(lock *balanceEvent.Lock) {
|
||||
|
@ -15,7 +13,7 @@ func (bp *Processor) processLock(lock *balanceEvent.Lock) {
|
|||
return
|
||||
}
|
||||
|
||||
err := bp.mainnetClient.NotaryInvoke(bp.neofsContract, bp.feeProvider.MainChainFee(), chequeMethod,
|
||||
err := bp.neofsClient.Cheque(
|
||||
lock.ID(),
|
||||
lock.User(),
|
||||
bp.converter.ToFixed8(lock.Amount()),
|
||||
|
|
|
@ -5,8 +5,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/config"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
neofscontract "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs/wrapper"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||
balanceEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/balance"
|
||||
"github.com/panjf2000/ants/v2"
|
||||
|
@ -28,24 +27,20 @@ type (
|
|||
Processor struct {
|
||||
log *zap.Logger
|
||||
pool *ants.Pool
|
||||
neofsContract util.Uint160
|
||||
neofsClient *neofscontract.ClientWrapper
|
||||
balanceContract util.Uint160
|
||||
mainnetClient *client.Client
|
||||
alphabetState AlphabetState
|
||||
converter PrecisionConverter
|
||||
feeProvider *config.FeeConfig
|
||||
}
|
||||
|
||||
// Params of the processor constructor.
|
||||
Params struct {
|
||||
Log *zap.Logger
|
||||
PoolSize int
|
||||
NeoFSContract util.Uint160
|
||||
NeoFSClient *neofscontract.ClientWrapper
|
||||
BalanceContract util.Uint160
|
||||
MainnetClient *client.Client
|
||||
AlphabetState AlphabetState
|
||||
Converter PrecisionConverter
|
||||
FeeProvider *config.FeeConfig
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -58,14 +53,10 @@ func New(p *Params) (*Processor, error) {
|
|||
switch {
|
||||
case p.Log == nil:
|
||||
return nil, errors.New("ir/balance: logger is not set")
|
||||
case p.MainnetClient == nil:
|
||||
return nil, errors.New("ir/balance: neo:mainnet client is not set")
|
||||
case p.AlphabetState == nil:
|
||||
return nil, errors.New("ir/balance: global state is not set")
|
||||
case p.Converter == nil:
|
||||
return nil, errors.New("ir/balance: balance precision converter is not set")
|
||||
case p.FeeProvider == nil:
|
||||
return nil, errors.New("ir/balance: fee provider is not set")
|
||||
}
|
||||
|
||||
p.Log.Debug("balance worker pool", zap.Int("size", p.PoolSize))
|
||||
|
@ -78,12 +69,10 @@ func New(p *Params) (*Processor, error) {
|
|||
return &Processor{
|
||||
log: p.Log,
|
||||
pool: pool,
|
||||
neofsContract: p.NeoFSContract,
|
||||
neofsClient: p.NeoFSClient,
|
||||
balanceContract: p.BalanceContract,
|
||||
mainnetClient: p.MainnetClient,
|
||||
alphabetState: p.AlphabetState,
|
||||
converter: p.Converter,
|
||||
feeProvider: p.FeeProvider,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -9,8 +9,6 @@ import (
|
|||
|
||||
const (
|
||||
alphabetUpdateIDPrefix = "AlphabetUpdate"
|
||||
|
||||
alphabetUpdateMethod = "alphabetUpdate"
|
||||
)
|
||||
|
||||
func (gp *Processor) processAlphabetSync() {
|
||||
|
@ -98,8 +96,7 @@ func (gp *Processor) processAlphabetSync() {
|
|||
|
||||
id := append([]byte(alphabetUpdateIDPrefix), buf...)
|
||||
|
||||
err = gp.mainnetClient.NotaryInvoke(gp.neofsContract, gp.feeProvider.MainChainFee(), alphabetUpdateMethod,
|
||||
id, newAlphabet)
|
||||
err = gp.neofsClient.AlphabetUpdate(id, newAlphabet)
|
||||
if err != nil {
|
||||
gp.log.Error("can't update list of alphabet nodes in neofs contract",
|
||||
zap.String("error", err.Error()))
|
||||
|
|
|
@ -6,9 +6,8 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/config"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
neofscontract "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs/wrapper"
|
||||
nmWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event/rolemanagement"
|
||||
|
@ -39,10 +38,10 @@ type (
|
|||
|
||||
// Processor of events related to governance in the network.
|
||||
Processor struct {
|
||||
log *zap.Logger
|
||||
pool *ants.Pool
|
||||
neofsContract util.Uint160
|
||||
netmapClient *nmWrapper.Wrapper
|
||||
log *zap.Logger
|
||||
pool *ants.Pool
|
||||
neofsClient *neofscontract.ClientWrapper
|
||||
netmapClient *nmWrapper.Wrapper
|
||||
|
||||
alphabetState AlphabetState
|
||||
epochState EpochState
|
||||
|
@ -52,13 +51,11 @@ type (
|
|||
morphClient *client.Client
|
||||
|
||||
notaryDisabled bool
|
||||
feeProvider *config.FeeConfig
|
||||
}
|
||||
|
||||
// Params of the processor constructor.
|
||||
Params struct {
|
||||
Log *zap.Logger
|
||||
NeoFSContract util.Uint160
|
||||
Log *zap.Logger
|
||||
|
||||
AlphabetState AlphabetState
|
||||
EpochState EpochState
|
||||
|
@ -66,10 +63,10 @@ type (
|
|||
|
||||
MorphClient *client.Client
|
||||
MainnetClient *client.Client
|
||||
NeoFSClient *neofscontract.ClientWrapper
|
||||
NetmapClient *nmWrapper.Wrapper
|
||||
|
||||
NotaryDisabled bool
|
||||
FeeProvider *config.FeeConfig
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -88,8 +85,6 @@ func New(p *Params) (*Processor, error) {
|
|||
return nil, errors.New("ir/governance: global state is not set")
|
||||
case p.Voter == nil:
|
||||
return nil, errors.New("ir/governance: global state is not set")
|
||||
case p.FeeProvider == nil:
|
||||
return nil, errors.New("ir/governance: fee provider is not set")
|
||||
}
|
||||
|
||||
pool, err := ants.NewPool(ProcessorPoolSize, ants.WithNonblocking(true))
|
||||
|
@ -100,7 +95,7 @@ func New(p *Params) (*Processor, error) {
|
|||
return &Processor{
|
||||
log: p.Log,
|
||||
pool: pool,
|
||||
neofsContract: p.NeoFSContract,
|
||||
neofsClient: p.NeoFSClient,
|
||||
netmapClient: p.NetmapClient,
|
||||
alphabetState: p.AlphabetState,
|
||||
epochState: p.EpochState,
|
||||
|
@ -108,7 +103,6 @@ func New(p *Params) (*Processor, error) {
|
|||
mainnetClient: p.MainnetClient,
|
||||
morphClient: p.MorphClient,
|
||||
notaryDisabled: p.NotaryDisabled,
|
||||
feeProvider: p.FeeProvider,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
16
pkg/morph/client/neofs/cheque.go
Normal file
16
pkg/morph/client/neofs/cheque.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package neofscontract
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
)
|
||||
|
||||
// Cheque invokes `cheque` method of NeoFS contract.
|
||||
func (x *Client) Cheque(id []byte, user util.Uint160, amount int64, lock util.Uint160) error {
|
||||
return x.client.Invoke(x.chequeMethod, id, user.BytesBE(), amount, lock.BytesBE())
|
||||
}
|
||||
|
||||
// AlphabetUpdate update list of alphabet nodes.
|
||||
func (x *Client) AlphabetUpdate(id []byte, pubs keys.PublicKeys) error {
|
||||
return x.client.Invoke(x.alphabetUpdateMethod, id, pubs)
|
||||
}
|
|
@ -22,19 +22,25 @@ type Client struct {
|
|||
type Option func(*cfg)
|
||||
|
||||
type cfg struct {
|
||||
alphabetUpdateMethod,
|
||||
chequeMethod,
|
||||
bindKeysMethod,
|
||||
unbindKeysMethod string
|
||||
}
|
||||
|
||||
func defaultConfig() *cfg {
|
||||
const (
|
||||
defaultBindKeysMethod = "bind"
|
||||
defaultUnbindKeysMethod = "unbind"
|
||||
defaultBindKeysMethod = "bind"
|
||||
defaultUnbindKeysMethod = "unbind"
|
||||
defaultAlphabetUpdateMethod = "alphabetUpdate"
|
||||
defaultChequeMethod = "cheque"
|
||||
)
|
||||
|
||||
return &cfg{
|
||||
bindKeysMethod: defaultBindKeysMethod,
|
||||
unbindKeysMethod: defaultUnbindKeysMethod,
|
||||
alphabetUpdateMethod: defaultAlphabetUpdateMethod,
|
||||
chequeMethod: defaultChequeMethod,
|
||||
bindKeysMethod: defaultBindKeysMethod,
|
||||
unbindKeysMethod: defaultUnbindKeysMethod,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
17
pkg/morph/client/neofs/wrapper/cheque.go
Normal file
17
pkg/morph/client/neofs/wrapper/cheque.go
Normal file
|
@ -0,0 +1,17 @@
|
|||
package neofscontract
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
neofscontract "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs"
|
||||
)
|
||||
|
||||
// Cheque invokes `cheque` method of NeoFS contract.
|
||||
func (x *ClientWrapper) Cheque(id []byte, user util.Uint160, amount int64, lock util.Uint160) error {
|
||||
return (*neofscontract.Client)(x).Cheque(id, user, amount, lock)
|
||||
}
|
||||
|
||||
// AlphabetUpdate update list of alphabet nodes.
|
||||
func (x *ClientWrapper) AlphabetUpdate(id []byte, pubs keys.PublicKeys) error {
|
||||
return (*neofscontract.Client)(x).AlphabetUpdate(id, pubs)
|
||||
}
|
Loading…
Reference in a new issue