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"
|
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"
|
||||||
|
neofsWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs/wrapper"
|
||||||
neofsid "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid/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"
|
||||||
|
@ -417,6 +418,12 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
return nil, err
|
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
|
// create global runtime config reader
|
||||||
globalConfig := config.NewGlobalConfigReader(cfg, server.netmapClient)
|
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
|
// create governance processor
|
||||||
governanceProcessor, err := governance.New(&governance.Params{
|
governanceProcessor, err := governance.New(&governance.Params{
|
||||||
Log: log,
|
Log: log,
|
||||||
NeoFSContract: server.contracts.neofs,
|
NeoFSClient: neofsClient,
|
||||||
NetmapClient: server.netmapClient,
|
NetmapClient: server.netmapClient,
|
||||||
AlphabetState: server,
|
AlphabetState: server,
|
||||||
EpochState: server,
|
EpochState: server,
|
||||||
|
@ -525,7 +532,6 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
MorphClient: server.morphClient,
|
MorphClient: server.morphClient,
|
||||||
MainnetClient: server.mainnetClient,
|
MainnetClient: server.mainnetClient,
|
||||||
NotaryDisabled: server.sideNotaryConfig.disabled,
|
NotaryDisabled: server.sideNotaryConfig.disabled,
|
||||||
FeeProvider: server.feeConfig,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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{
|
balanceProcessor, err := balance.New(&balance.Params{
|
||||||
Log: log,
|
Log: log,
|
||||||
PoolSize: cfg.GetInt("workers.balance"),
|
PoolSize: cfg.GetInt("workers.balance"),
|
||||||
NeoFSContract: server.contracts.neofs,
|
NeoFSClient: neofsClient,
|
||||||
BalanceContract: server.contracts.balance,
|
BalanceContract: server.contracts.balance,
|
||||||
MainnetClient: server.mainnetClient,
|
|
||||||
AlphabetState: server,
|
AlphabetState: server,
|
||||||
Converter: &server.precision,
|
Converter: &server.precision,
|
||||||
FeeProvider: server.feeConfig,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -5,8 +5,6 @@ import (
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
const chequeMethod = "cheque"
|
|
||||||
|
|
||||||
// Process lock event by invoking Cheque method in main net to send assets
|
// Process lock event by invoking Cheque method in main net to send assets
|
||||||
// back to the withdraw issuer.
|
// back to the withdraw issuer.
|
||||||
func (bp *Processor) processLock(lock *balanceEvent.Lock) {
|
func (bp *Processor) processLock(lock *balanceEvent.Lock) {
|
||||||
|
@ -15,7 +13,7 @@ func (bp *Processor) processLock(lock *balanceEvent.Lock) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := bp.mainnetClient.NotaryInvoke(bp.neofsContract, bp.feeProvider.MainChainFee(), chequeMethod,
|
err := bp.neofsClient.Cheque(
|
||||||
lock.ID(),
|
lock.ID(),
|
||||||
lock.User(),
|
lock.User(),
|
||||||
bp.converter.ToFixed8(lock.Amount()),
|
bp.converter.ToFixed8(lock.Amount()),
|
||||||
|
|
|
@ -5,8 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/config"
|
neofscontract "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs/wrapper"
|
||||||
"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"
|
||||||
balanceEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/balance"
|
balanceEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/balance"
|
||||||
"github.com/panjf2000/ants/v2"
|
"github.com/panjf2000/ants/v2"
|
||||||
|
@ -28,24 +27,20 @@ type (
|
||||||
Processor struct {
|
Processor struct {
|
||||||
log *zap.Logger
|
log *zap.Logger
|
||||||
pool *ants.Pool
|
pool *ants.Pool
|
||||||
neofsContract util.Uint160
|
neofsClient *neofscontract.ClientWrapper
|
||||||
balanceContract util.Uint160
|
balanceContract util.Uint160
|
||||||
mainnetClient *client.Client
|
|
||||||
alphabetState AlphabetState
|
alphabetState AlphabetState
|
||||||
converter PrecisionConverter
|
converter PrecisionConverter
|
||||||
feeProvider *config.FeeConfig
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Params of the processor constructor.
|
// Params of the processor constructor.
|
||||||
Params struct {
|
Params struct {
|
||||||
Log *zap.Logger
|
Log *zap.Logger
|
||||||
PoolSize int
|
PoolSize int
|
||||||
NeoFSContract util.Uint160
|
NeoFSClient *neofscontract.ClientWrapper
|
||||||
BalanceContract util.Uint160
|
BalanceContract util.Uint160
|
||||||
MainnetClient *client.Client
|
|
||||||
AlphabetState AlphabetState
|
AlphabetState AlphabetState
|
||||||
Converter PrecisionConverter
|
Converter PrecisionConverter
|
||||||
FeeProvider *config.FeeConfig
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -58,14 +53,10 @@ func New(p *Params) (*Processor, error) {
|
||||||
switch {
|
switch {
|
||||||
case p.Log == nil:
|
case p.Log == nil:
|
||||||
return nil, errors.New("ir/balance: logger is not set")
|
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:
|
case p.AlphabetState == nil:
|
||||||
return nil, errors.New("ir/balance: global state is not set")
|
return nil, errors.New("ir/balance: global state is not set")
|
||||||
case p.Converter == nil:
|
case p.Converter == nil:
|
||||||
return nil, errors.New("ir/balance: balance precision converter is not set")
|
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))
|
p.Log.Debug("balance worker pool", zap.Int("size", p.PoolSize))
|
||||||
|
@ -78,12 +69,10 @@ func New(p *Params) (*Processor, error) {
|
||||||
return &Processor{
|
return &Processor{
|
||||||
log: p.Log,
|
log: p.Log,
|
||||||
pool: pool,
|
pool: pool,
|
||||||
neofsContract: p.NeoFSContract,
|
neofsClient: p.NeoFSClient,
|
||||||
balanceContract: p.BalanceContract,
|
balanceContract: p.BalanceContract,
|
||||||
mainnetClient: p.MainnetClient,
|
|
||||||
alphabetState: p.AlphabetState,
|
alphabetState: p.AlphabetState,
|
||||||
converter: p.Converter,
|
converter: p.Converter,
|
||||||
feeProvider: p.FeeProvider,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,6 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
alphabetUpdateIDPrefix = "AlphabetUpdate"
|
alphabetUpdateIDPrefix = "AlphabetUpdate"
|
||||||
|
|
||||||
alphabetUpdateMethod = "alphabetUpdate"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (gp *Processor) processAlphabetSync() {
|
func (gp *Processor) processAlphabetSync() {
|
||||||
|
@ -98,8 +96,7 @@ func (gp *Processor) processAlphabetSync() {
|
||||||
|
|
||||||
id := append([]byte(alphabetUpdateIDPrefix), buf...)
|
id := append([]byte(alphabetUpdateIDPrefix), buf...)
|
||||||
|
|
||||||
err = gp.mainnetClient.NotaryInvoke(gp.neofsContract, gp.feeProvider.MainChainFee(), alphabetUpdateMethod,
|
err = gp.neofsClient.AlphabetUpdate(id, newAlphabet)
|
||||||
id, newAlphabet)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gp.log.Error("can't update list of alphabet nodes in neofs contract",
|
gp.log.Error("can't update list of alphabet nodes in neofs contract",
|
||||||
zap.String("error", err.Error()))
|
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/core/native"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"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"
|
"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"
|
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"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event/rolemanagement"
|
"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 of events related to governance in the network.
|
||||||
Processor struct {
|
Processor struct {
|
||||||
log *zap.Logger
|
log *zap.Logger
|
||||||
pool *ants.Pool
|
pool *ants.Pool
|
||||||
neofsContract util.Uint160
|
neofsClient *neofscontract.ClientWrapper
|
||||||
netmapClient *nmWrapper.Wrapper
|
netmapClient *nmWrapper.Wrapper
|
||||||
|
|
||||||
alphabetState AlphabetState
|
alphabetState AlphabetState
|
||||||
epochState EpochState
|
epochState EpochState
|
||||||
|
@ -52,13 +51,11 @@ type (
|
||||||
morphClient *client.Client
|
morphClient *client.Client
|
||||||
|
|
||||||
notaryDisabled bool
|
notaryDisabled bool
|
||||||
feeProvider *config.FeeConfig
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Params of the processor constructor.
|
// Params of the processor constructor.
|
||||||
Params struct {
|
Params struct {
|
||||||
Log *zap.Logger
|
Log *zap.Logger
|
||||||
NeoFSContract util.Uint160
|
|
||||||
|
|
||||||
AlphabetState AlphabetState
|
AlphabetState AlphabetState
|
||||||
EpochState EpochState
|
EpochState EpochState
|
||||||
|
@ -66,10 +63,10 @@ type (
|
||||||
|
|
||||||
MorphClient *client.Client
|
MorphClient *client.Client
|
||||||
MainnetClient *client.Client
|
MainnetClient *client.Client
|
||||||
|
NeoFSClient *neofscontract.ClientWrapper
|
||||||
NetmapClient *nmWrapper.Wrapper
|
NetmapClient *nmWrapper.Wrapper
|
||||||
|
|
||||||
NotaryDisabled bool
|
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")
|
return nil, errors.New("ir/governance: global state is not set")
|
||||||
case p.Voter == nil:
|
case p.Voter == nil:
|
||||||
return nil, errors.New("ir/governance: global state is not set")
|
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))
|
pool, err := ants.NewPool(ProcessorPoolSize, ants.WithNonblocking(true))
|
||||||
|
@ -100,7 +95,7 @@ func New(p *Params) (*Processor, error) {
|
||||||
return &Processor{
|
return &Processor{
|
||||||
log: p.Log,
|
log: p.Log,
|
||||||
pool: pool,
|
pool: pool,
|
||||||
neofsContract: p.NeoFSContract,
|
neofsClient: p.NeoFSClient,
|
||||||
netmapClient: p.NetmapClient,
|
netmapClient: p.NetmapClient,
|
||||||
alphabetState: p.AlphabetState,
|
alphabetState: p.AlphabetState,
|
||||||
epochState: p.EpochState,
|
epochState: p.EpochState,
|
||||||
|
@ -108,7 +103,6 @@ func New(p *Params) (*Processor, error) {
|
||||||
mainnetClient: p.MainnetClient,
|
mainnetClient: p.MainnetClient,
|
||||||
morphClient: p.MorphClient,
|
morphClient: p.MorphClient,
|
||||||
notaryDisabled: p.NotaryDisabled,
|
notaryDisabled: p.NotaryDisabled,
|
||||||
feeProvider: p.FeeProvider,
|
|
||||||
}, nil
|
}, 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 Option func(*cfg)
|
||||||
|
|
||||||
type cfg struct {
|
type cfg struct {
|
||||||
|
alphabetUpdateMethod,
|
||||||
|
chequeMethod,
|
||||||
bindKeysMethod,
|
bindKeysMethod,
|
||||||
unbindKeysMethod string
|
unbindKeysMethod string
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultConfig() *cfg {
|
func defaultConfig() *cfg {
|
||||||
const (
|
const (
|
||||||
defaultBindKeysMethod = "bind"
|
defaultBindKeysMethod = "bind"
|
||||||
defaultUnbindKeysMethod = "unbind"
|
defaultUnbindKeysMethod = "unbind"
|
||||||
|
defaultAlphabetUpdateMethod = "alphabetUpdate"
|
||||||
|
defaultChequeMethod = "cheque"
|
||||||
)
|
)
|
||||||
|
|
||||||
return &cfg{
|
return &cfg{
|
||||||
bindKeysMethod: defaultBindKeysMethod,
|
alphabetUpdateMethod: defaultAlphabetUpdateMethod,
|
||||||
unbindKeysMethod: defaultUnbindKeysMethod,
|
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