forked from TrueCloudLab/frostfs-node
[#625] client/neofs: remove intermediate wrapper
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
6f50fefbea
commit
8474abb911
11 changed files with 88 additions and 259 deletions
|
@ -32,7 +32,7 @@ import (
|
|||
auditWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/audit/wrapper"
|
||||
balanceClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
|
||||
cntWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
||||
neofsWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs/wrapper"
|
||||
neofsClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs"
|
||||
neofsidWrapper "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"
|
||||
|
@ -508,8 +508,8 @@ 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(), neofsWrapper.TryNotary(), neofsWrapper.AsAlphabet())
|
||||
neofsCli, err := neofsClient.NewFromMorph(server.mainnetClient, server.contracts.neofs,
|
||||
server.feeConfig.MainChainFee(), neofsClient.TryNotary(), neofsClient.AsAlphabet())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -665,7 +665,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,
|
||||
NeoFSClient: neofsClient,
|
||||
NeoFSClient: neofsCli,
|
||||
NetmapClient: server.netmapClient,
|
||||
AlphabetState: server,
|
||||
EpochState: server,
|
||||
|
@ -748,7 +748,7 @@ 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"),
|
||||
NeoFSClient: neofsClient,
|
||||
NeoFSClient: neofsCli,
|
||||
AlphabetState: server,
|
||||
Converter: &server.precision,
|
||||
})
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package balance
|
||||
|
||||
import (
|
||||
neofscontract "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs/wrapper"
|
||||
neofscontract "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs"
|
||||
balanceEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/balance"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
|
||||
neofscontract "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs/wrapper"
|
||||
neofscontract "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs"
|
||||
"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"
|
||||
|
@ -26,7 +26,7 @@ type (
|
|||
Processor struct {
|
||||
log *zap.Logger
|
||||
pool *ants.Pool
|
||||
neofsClient *neofscontract.ClientWrapper
|
||||
neofsClient *neofscontract.Client
|
||||
alphabetState AlphabetState
|
||||
converter PrecisionConverter
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ type (
|
|||
Params struct {
|
||||
Log *zap.Logger
|
||||
PoolSize int
|
||||
NeoFSClient *neofscontract.ClientWrapper
|
||||
NeoFSClient *neofscontract.Client
|
||||
AlphabetState AlphabetState
|
||||
Converter PrecisionConverter
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
neofscontract "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs/wrapper"
|
||||
neofscontract "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
neofscontract "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs/wrapper"
|
||||
neofscontract "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs"
|
||||
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"
|
||||
|
@ -57,7 +57,7 @@ type (
|
|||
Processor struct {
|
||||
log *zap.Logger
|
||||
pool *ants.Pool
|
||||
neofsClient *neofscontract.ClientWrapper
|
||||
neofsClient *neofscontract.Client
|
||||
netmapClient *nmWrapper.Wrapper
|
||||
|
||||
alphabetState AlphabetState
|
||||
|
@ -84,7 +84,7 @@ type (
|
|||
|
||||
MorphClient *client.Client
|
||||
MainnetClient *client.Client
|
||||
NeoFSClient *neofscontract.ClientWrapper
|
||||
NeoFSClient *neofscontract.Client
|
||||
NetmapClient *nmWrapper.Wrapper
|
||||
|
||||
NotaryDisabled bool
|
||||
|
|
|
@ -6,18 +6,6 @@ import (
|
|||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
)
|
||||
|
||||
// BindKeysArgs groups the arguments
|
||||
// of key binding call.
|
||||
type BindKeysArgs struct {
|
||||
commonBindArgs
|
||||
}
|
||||
|
||||
// UnbindKeysArgs groups the arguments
|
||||
// of key unbinding call.
|
||||
type UnbindKeysArgs struct {
|
||||
commonBindArgs
|
||||
}
|
||||
|
||||
type commonBindArgs struct {
|
||||
scriptHash []byte // script hash of account identifier
|
||||
|
||||
|
@ -41,14 +29,17 @@ func (x *commonBindArgs) SetKeys(v [][]byte) {
|
|||
x.keys = v
|
||||
}
|
||||
|
||||
// BindKeys invokes the call of key binding method
|
||||
// of NeoFS contract.
|
||||
func (x *Client) BindKeys(args BindKeysArgs) error {
|
||||
prm := client.InvokePrm{}
|
||||
// BindKeysPrm groups parameters of BindKeys operation.
|
||||
type BindKeysPrm struct {
|
||||
commonBindArgs
|
||||
}
|
||||
|
||||
// BindKeys binds list of public keys from NeoFS account by script hash.
|
||||
func (x *Client) BindKeys(p BindKeysPrm) error {
|
||||
prm := client.InvokePrm{}
|
||||
prm.SetMethod(bindKeysMethod)
|
||||
prm.SetArgs(args.scriptHash, args.keys)
|
||||
prm.InvokePrmOptional = args.InvokePrmOptional
|
||||
prm.SetArgs(p.scriptHash, p.keys)
|
||||
prm.InvokePrmOptional = p.InvokePrmOptional
|
||||
|
||||
err := x.client.Invoke(prm)
|
||||
if err != nil {
|
||||
|
@ -58,11 +49,15 @@ func (x *Client) BindKeys(args BindKeysArgs) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// UnbindKeysPrm groups parameters of UnbindKeys operation.
|
||||
type UnbindKeysPrm struct {
|
||||
commonBindArgs
|
||||
}
|
||||
|
||||
// UnbindKeys invokes the call of key unbinding method
|
||||
// of NeoFS contract.
|
||||
func (x *Client) UnbindKeys(args UnbindKeysArgs) error {
|
||||
func (x *Client) UnbindKeys(args UnbindKeysPrm) error {
|
||||
prm := client.InvokePrm{}
|
||||
|
||||
prm.SetMethod(unbindKeysMethod)
|
||||
prm.SetArgs(args.scriptHash, args.keys)
|
||||
prm.InvokePrmOptional = args.InvokePrmOptional
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
)
|
||||
|
||||
// ChequePrm groups the arguments of Cheque operation.
|
||||
// ChequePrm groups parameters of Cheque operation.
|
||||
type ChequePrm struct {
|
||||
id []byte
|
||||
user util.Uint160
|
||||
|
@ -37,18 +37,16 @@ func (c *ChequePrm) SetLock(lock util.Uint160) {
|
|||
}
|
||||
|
||||
// Cheque invokes `cheque` method of NeoFS contract.
|
||||
func (x *Client) Cheque(args ChequePrm) error {
|
||||
func (x *Client) Cheque(p ChequePrm) error {
|
||||
prm := client.InvokePrm{}
|
||||
|
||||
prm.SetMethod(chequeMethod)
|
||||
prm.SetArgs(args.id, args.user.BytesBE(), args.amount, args.lock.BytesBE())
|
||||
prm.InvokePrmOptional = args.InvokePrmOptional
|
||||
prm.SetArgs(p.id, p.user.BytesBE(), p.amount, p.lock.BytesBE())
|
||||
prm.InvokePrmOptional = p.InvokePrmOptional
|
||||
|
||||
return x.client.Invoke(prm)
|
||||
}
|
||||
|
||||
// AlphabetUpdatePrm groups the arguments
|
||||
// of alphabet nodes update invocation call.
|
||||
// AlphabetUpdatePrm groups parameters of AlphabetUpdate operation.
|
||||
type AlphabetUpdatePrm struct {
|
||||
id []byte
|
||||
pubs keys.PublicKeys
|
||||
|
@ -67,12 +65,11 @@ func (a *AlphabetUpdatePrm) SetPubs(pubs keys.PublicKeys) {
|
|||
}
|
||||
|
||||
// AlphabetUpdate update list of alphabet nodes.
|
||||
func (x *Client) AlphabetUpdate(args AlphabetUpdatePrm) error {
|
||||
func (x *Client) AlphabetUpdate(p AlphabetUpdatePrm) error {
|
||||
prm := client.InvokePrm{}
|
||||
|
||||
prm.SetMethod(alphabetUpdateMethod)
|
||||
prm.SetArgs(args.id, args.pubs)
|
||||
prm.InvokePrmOptional = args.InvokePrmOptional
|
||||
prm.SetArgs(p.id, p.pubs)
|
||||
prm.InvokePrmOptional = p.InvokePrmOptional
|
||||
|
||||
return x.client.Invoke(prm)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package neofscontract
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
|
@ -23,7 +27,52 @@ const (
|
|||
chequeMethod = "cheque"
|
||||
)
|
||||
|
||||
// New creates, initializes and returns the Client instance.
|
||||
func New(c *client.StaticClient) *Client {
|
||||
return &Client{client: c}
|
||||
// NewFromMorph wraps client to work with NeoFS contract.
|
||||
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*Client, error) {
|
||||
o := defaultOpts()
|
||||
|
||||
for i := range opts {
|
||||
opts[i](o)
|
||||
}
|
||||
|
||||
sc, err := client.NewStatic(cli, contract, fee, ([]client.StaticClientOption)(*o)...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not create client of NeoFS contract: %w", err)
|
||||
}
|
||||
|
||||
return &Client{client: sc}, nil
|
||||
}
|
||||
|
||||
// ContractAddress returns the address of the associated contract.
|
||||
func (x *Client) ContractAddress() util.Uint160 {
|
||||
return x.client.ContractAddress()
|
||||
}
|
||||
|
||||
// Option allows to set an optional
|
||||
// parameter of ClientWrapper.
|
||||
type Option func(*opts)
|
||||
|
||||
type opts []client.StaticClientOption
|
||||
|
||||
func defaultOpts() *opts {
|
||||
return new(opts)
|
||||
}
|
||||
|
||||
// TryNotary returns option to enable
|
||||
// notary invocation tries.
|
||||
func TryNotary() Option {
|
||||
return func(o *opts) {
|
||||
*o = append(*o, client.TryNotary())
|
||||
}
|
||||
}
|
||||
|
||||
// AsAlphabet returns option to sign main TX
|
||||
// of notary requests with client's private
|
||||
// key.
|
||||
//
|
||||
// Considered to be used by IR nodes only.
|
||||
func AsAlphabet() Option {
|
||||
return func(o *opts) {
|
||||
*o = append(*o, client.AsAlphabet())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
package neofscontract
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
neofscontract "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs"
|
||||
)
|
||||
|
||||
// ManageKeysPrm groups parameters of ManageKeys operation.
|
||||
type ManageKeysPrm struct {
|
||||
scriptHash []byte
|
||||
ks [][]byte
|
||||
bind bool
|
||||
|
||||
client.InvokePrmOptional
|
||||
}
|
||||
|
||||
// SetScriptHash sets script hash.
|
||||
func (m *ManageKeysPrm) SetScriptHash(scriptHash []byte) {
|
||||
m.scriptHash = scriptHash
|
||||
}
|
||||
|
||||
// SetKeys sets keys.
|
||||
func (m *ManageKeysPrm) SetKeys(ks [][]byte) {
|
||||
m.ks = ks
|
||||
}
|
||||
|
||||
// SetBind sets operation type: bind/unbind.
|
||||
func (m *ManageKeysPrm) SetBind(bind bool) {
|
||||
m.bind = bind
|
||||
}
|
||||
|
||||
// ManageKeys binds/unbinds list of public keys from NeoFS account by script hash.
|
||||
func (x *ClientWrapper) ManageKeys(prm ManageKeysPrm) error {
|
||||
type args interface {
|
||||
SetScriptHash([]byte)
|
||||
SetKeys([][]byte)
|
||||
SetOptionalPrm(optional client.InvokePrmOptional)
|
||||
}
|
||||
|
||||
var (
|
||||
a args
|
||||
call func(args) error
|
||||
)
|
||||
|
||||
if prm.bind {
|
||||
a = new(neofscontract.BindKeysArgs)
|
||||
call = func(a args) error {
|
||||
return x.client.BindKeys(*a.(*neofscontract.BindKeysArgs))
|
||||
}
|
||||
} else {
|
||||
a = new(neofscontract.UnbindKeysArgs)
|
||||
call = func(a args) error {
|
||||
return x.client.UnbindKeys(*a.(*neofscontract.UnbindKeysArgs))
|
||||
}
|
||||
}
|
||||
|
||||
a.SetScriptHash(prm.scriptHash)
|
||||
a.SetKeys(prm.ks)
|
||||
a.SetOptionalPrm(prm.InvokePrmOptional)
|
||||
|
||||
return call(a)
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
package neofscontract
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
neofscontract "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs"
|
||||
)
|
||||
|
||||
// ChequePrm groups parameters of AlphabetUpdate operation.
|
||||
type ChequePrm struct {
|
||||
id []byte
|
||||
user util.Uint160
|
||||
amount int64
|
||||
lock util.Uint160
|
||||
|
||||
client.InvokePrmOptional
|
||||
}
|
||||
|
||||
// SetID sets ID of the cheque.
|
||||
func (c *ChequePrm) SetID(id []byte) {
|
||||
c.id = id
|
||||
}
|
||||
|
||||
// SetUser sets user.
|
||||
func (c *ChequePrm) SetUser(user util.Uint160) {
|
||||
c.user = user
|
||||
}
|
||||
|
||||
// SetAmount sets amount.
|
||||
func (c *ChequePrm) SetAmount(amount int64) {
|
||||
c.amount = amount
|
||||
}
|
||||
|
||||
// SetLock sets lock.
|
||||
func (c *ChequePrm) SetLock(lock util.Uint160) {
|
||||
c.lock = lock
|
||||
}
|
||||
|
||||
// Cheque invokes `cheque` method of NeoFS contract.
|
||||
func (x *ClientWrapper) Cheque(prm ChequePrm) error {
|
||||
args := neofscontract.ChequePrm{}
|
||||
|
||||
args.SetID(prm.id)
|
||||
args.SetUser(prm.user)
|
||||
args.SetAmount(prm.amount)
|
||||
args.SetLock(prm.lock)
|
||||
args.InvokePrmOptional = prm.InvokePrmOptional
|
||||
|
||||
return x.client.Cheque(args)
|
||||
}
|
||||
|
||||
// AlphabetUpdatePrm groups parameters of AlphabetUpdate operation.
|
||||
type AlphabetUpdatePrm struct {
|
||||
id []byte
|
||||
pubs keys.PublicKeys
|
||||
|
||||
client.InvokePrmOptional
|
||||
}
|
||||
|
||||
// SetID sets update ID.
|
||||
func (a *AlphabetUpdatePrm) SetID(id []byte) {
|
||||
a.id = id
|
||||
}
|
||||
|
||||
// SetPubs sets new alphabet public keys.
|
||||
func (a *AlphabetUpdatePrm) SetPubs(pubs keys.PublicKeys) {
|
||||
a.pubs = pubs
|
||||
}
|
||||
|
||||
// AlphabetUpdate update list of alphabet nodes.
|
||||
func (x *ClientWrapper) AlphabetUpdate(prm AlphabetUpdatePrm) error {
|
||||
args := neofscontract.AlphabetUpdatePrm{}
|
||||
|
||||
args.SetID(prm.id)
|
||||
args.SetPubs(prm.pubs)
|
||||
args.InvokePrmOptional = prm.InvokePrmOptional
|
||||
|
||||
return x.client.AlphabetUpdate(args)
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
package neofscontract
|
||||
|
||||
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/internal"
|
||||
neofscontract "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs"
|
||||
)
|
||||
|
||||
// ClientWrapper is a wrapper over NeoFS contract
|
||||
// client which provides convenient methods for
|
||||
// working with a contract.
|
||||
//
|
||||
// Working ClientWrapper must be created via NewFromMorph.
|
||||
type ClientWrapper struct {
|
||||
internal.StaticClient
|
||||
|
||||
client *neofscontract.Client
|
||||
}
|
||||
|
||||
// Option allows to set an optional
|
||||
// parameter of ClientWrapper.
|
||||
type Option func(*opts)
|
||||
|
||||
type opts []client.StaticClientOption
|
||||
|
||||
func defaultOpts() *opts {
|
||||
return new(opts)
|
||||
}
|
||||
|
||||
// TryNotary returns option to enable
|
||||
// notary invocation tries.
|
||||
func TryNotary() Option {
|
||||
return func(o *opts) {
|
||||
*o = append(*o, client.TryNotary())
|
||||
}
|
||||
}
|
||||
|
||||
// AsAlphabet returns option to sign main TX
|
||||
// of notary requests with client's private
|
||||
// key.
|
||||
//
|
||||
// Considered to be used by IR nodes only.
|
||||
func AsAlphabet() Option {
|
||||
return func(o *opts) {
|
||||
*o = append(*o, client.AsAlphabet())
|
||||
}
|
||||
}
|
||||
|
||||
// NewFromMorph wraps client to work with NeoFS contract.
|
||||
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...Option) (*ClientWrapper, error) {
|
||||
o := defaultOpts()
|
||||
|
||||
for i := range opts {
|
||||
opts[i](o)
|
||||
}
|
||||
|
||||
sc, err := client.NewStatic(cli, contract, fee, ([]client.StaticClientOption)(*o)...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not create client of NeoFS contract: %w", err)
|
||||
}
|
||||
|
||||
return &ClientWrapper{
|
||||
StaticClient: sc,
|
||||
client: neofscontract.New(sc),
|
||||
}, nil
|
||||
}
|
Loading…
Reference in a new issue