[#627] morph: Inherit internal.StaticClient interface in all wrappers

There is a need to provide contract address getter from all contract client
wrappers.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-09-15 13:48:00 +03:00 committed by Alex Vanin
parent 1860f5040c
commit d6c0307431
14 changed files with 79 additions and 30 deletions

View file

@ -27,7 +27,7 @@ func (w *ClientWrapper) PutAuditResult(result *auditAPI.Result) error {
args := audit.PutAuditResultArgs{}
args.SetRawResult(rawResult)
return (*audit.Client)(w).
return w.client.
PutAuditResult(args)
}
@ -35,7 +35,7 @@ func (w *ClientWrapper) PutAuditResult(result *auditAPI.Result) error {
func (w *ClientWrapper) ListAllAuditResultID() ([]ResultID, error) {
args := audit.ListResultsArgs{}
values, err := (*audit.Client)(w).ListAuditResults(args)
values, err := w.client.ListAuditResults(args)
if err != nil {
return nil, err
}
@ -49,7 +49,7 @@ func (w *ClientWrapper) ListAuditResultIDByEpoch(epoch uint64) ([]ResultID, erro
args := audit.ListResultsByEpochArgs{}
args.SetEpoch(int64(epoch))
values, err := (*audit.Client)(w).ListAuditResultsByEpoch(args)
values, err := w.client.ListAuditResultsByEpoch(args)
if err != nil {
return nil, err
}
@ -70,7 +70,7 @@ func (w *ClientWrapper) ListAuditResultIDByCID(epoch uint64, cid *cid.ID) ([]Res
args.SetCID(v2.GetValue())
values, err := (*audit.Client)(w).ListAuditResultsByCID(args)
values, err := w.client.ListAuditResultsByCID(args)
if err != nil {
return nil, err
}
@ -92,7 +92,7 @@ func (w *ClientWrapper) ListAuditResultIDByNode(epoch uint64, cid *cid.ID, key [
args.SetCID(v2.GetValue())
values, err := (*audit.Client)(w).ListAuditResultsByNode(args)
values, err := w.client.ListAuditResultsByNode(args)
if err != nil {
return nil, err
}
@ -116,7 +116,7 @@ func (w *ClientWrapper) GetAuditResult(id ResultID) (*auditAPI.Result, error) {
args := audit.GetAuditResultArgs{}
args.SetID(id)
value, err := (*audit.Client)(w).GetAuditResult(args)
value, err := w.client.GetAuditResult(args)
if err != nil {
return nil, err
}

View file

@ -5,11 +5,16 @@ import (
"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/audit"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/internal"
)
// ClientWrapper is a wrapper over Audit contract
// client which implements storage of audit results.
type ClientWrapper audit.Client
type ClientWrapper struct {
internal.StaticClient
client *audit.Client
}
// NewFromMorph returns the wrapper instance from the raw morph client.
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8, opts ...client.StaticClientOption) (*ClientWrapper, error) {
@ -18,5 +23,8 @@ func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8,
return nil, err
}
return (*ClientWrapper)(audit.New(staticClient)), nil
return &ClientWrapper{
StaticClient: staticClient,
client: audit.New(staticClient),
}, nil
}

View file

@ -7,6 +7,7 @@ import (
"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/balance"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/internal"
)
// Wrapper is a wrapper over balance contract
@ -19,6 +20,8 @@ import (
// expression (or just declaring a Wrapper variable) is unsafe
// and can lead to panic.
type Wrapper struct {
internal.StaticClient
client *balance.Client
}
@ -69,5 +72,8 @@ func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8,
return nil, fmt.Errorf("could not create Balance contract client: %w", err)
}
return &Wrapper{client: enhancedBalanceClient}, nil
return &Wrapper{
StaticClient: staticClient,
client: enhancedBalanceClient,
}, nil
}

View file

@ -7,6 +7,7 @@ import (
"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/container"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/internal"
)
// Wrapper is a wrapper over container contract
@ -18,6 +19,8 @@ import (
// expression (or just declaring a Wrapper variable) is unsafe
// and can lead to panic.
type Wrapper struct {
internal.StaticClient
client *container.Client
}
@ -73,5 +76,8 @@ func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8,
return nil, fmt.Errorf("can't create container morph client: %w", err)
}
return &Wrapper{client: enhancedContainerClient}, nil
return &Wrapper{
StaticClient: staticClient,
client: enhancedContainerClient,
}, nil
}

View file

@ -19,12 +19,12 @@ func (x *ClientWrapper) ManageKeys(scriptHash []byte, ks [][]byte, bind bool) er
if bind {
a = new(neofscontract.BindKeysArgs)
call = func(a args) error {
return (*neofscontract.Client)(x).BindKeys(*a.(*neofscontract.BindKeysArgs))
return x.client.BindKeys(*a.(*neofscontract.BindKeysArgs))
}
} else {
a = new(neofscontract.UnbindKeysArgs)
call = func(a args) error {
return (*neofscontract.Client)(x).UnbindKeys(*a.(*neofscontract.UnbindKeysArgs))
return x.client.UnbindKeys(*a.(*neofscontract.UnbindKeysArgs))
}
}

View file

@ -3,15 +3,14 @@ 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)
return x.client.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)
return x.client.AlphabetUpdate(id, pubs)
}

View file

@ -6,6 +6,7 @@ import (
"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"
)
@ -14,7 +15,11 @@ import (
// working with a contract.
//
// Working ClientWrapper must be created via NewFromMorph.
type ClientWrapper neofscontract.Client
type ClientWrapper struct {
internal.StaticClient
client *neofscontract.Client
}
// Option allows to set an optional
// parameter of ClientWrapper.
@ -58,5 +63,8 @@ func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8,
return nil, fmt.Errorf("could not create client of NeoFS contract: %w", err)
}
return (*ClientWrapper)(neofscontract.New(sc)), nil
return &ClientWrapper{
StaticClient: sc,
client: neofscontract.New(sc),
}, nil
}

View file

@ -6,6 +6,7 @@ import (
"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"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid"
)
@ -14,7 +15,11 @@ import (
// working with a contract.
//
// Working ClientWrapper must be created via Wrap.
type ClientWrapper neofsid.Client
type ClientWrapper struct {
internal.StaticClient
client *neofsid.Client
}
// Option allows to set an optional
// parameter of ClientWrapper.
@ -58,5 +63,8 @@ func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8,
return nil, fmt.Errorf("could not create client of NeoFS ID contract: %w", err)
}
return (*ClientWrapper)(neofsid.New(sc)), nil
return &ClientWrapper{
StaticClient: sc,
client: neofsid.New(sc),
}, nil
}

View file

@ -15,7 +15,7 @@ func (x *ClientWrapper) AccountKeys(id *owner.ID) (keys.PublicKeys, error) {
args.SetOwnerID(id.ToV2().GetValue())
res, err := (*neofsid.Client)(x).AccountKeys(args)
res, err := x.client.AccountKeys(args)
if err != nil {
return nil, err
}
@ -52,12 +52,12 @@ func (x *ClientWrapper) ManageKeys(ownerID []byte, ks [][]byte, add bool) error
if add {
a = new(neofsid.AddKeysArgs)
call = func(a args) error {
return (*neofsid.Client)(x).AddKeys(*a.(*neofsid.AddKeysArgs))
return x.client.AddKeys(*a.(*neofsid.AddKeysArgs))
}
} else {
a = new(neofsid.RemoveKeysArgs)
call = func(a args) error {
return (*neofsid.Client)(x).RemoveKeys(*a.(*neofsid.RemoveKeysArgs))
return x.client.RemoveKeys(*a.(*neofsid.RemoveKeysArgs))
}
}

View file

@ -6,6 +6,7 @@ import (
"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"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
)
@ -19,6 +20,8 @@ import (
// expression (or just declaring a Wrapper variable) is unsafe
// and can lead to panic.
type Wrapper struct {
internal.StaticClient
client *netmap.Client
}
@ -50,7 +53,10 @@ func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8,
return nil, fmt.Errorf("can't create netmap morph client: %w", err)
}
return &Wrapper{client: enhancedNetmapClient}, nil
return &Wrapper{
StaticClient: staticClient,
client: enhancedNetmapClient,
}, nil
}
// Morph returns raw morph client.

View file

@ -53,7 +53,7 @@ func (w *ClientWrapper) Get(v GetArgs) (*GetResult, error) {
args.SetEpoch(v.epoch)
args.SetPeerID(v.peerID.ToV2().GetPublicKey())
data, err := (*reputationClient.Client)(w).Get(args)
data, err := w.client.Get(args)
if err != nil {
return nil, err
}
@ -67,7 +67,7 @@ func (w *ClientWrapper) GetByID(v GetByIDArgs) (*GetResult, error) {
args := reputationClient.GetByIDArgs{}
args.SetID(v.id)
data, err := (*reputationClient.Client)(w).GetByID(args)
data, err := w.client.GetByID(args)
if err != nil {
return nil, err
}

View file

@ -37,7 +37,7 @@ func (w *ClientWrapper) ListByEpoch(v ListByEpochArgs) (*ListByEpochResult, erro
args := reputationClient.ListByEpochArgs{}
args.SetEpoch(v.epoch)
data, err := (*reputationClient.Client)(w).ListByEpoch(args)
data, err := w.client.ListByEpoch(args)
if err != nil {
return nil, err
}

View file

@ -40,7 +40,7 @@ func (w *ClientWrapper) Put(v PutArgs) error {
return err
}
return (*reputationClient.Client)(w).Put(args)
return w.client.Put(args)
}
func preparePutArgs(v PutArgs) (reputationClient.PutArgs, error) {

View file

@ -6,12 +6,17 @@ import (
"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"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation"
)
// ClientWrapper is a wrapper over reputation contract
// client which implements storage of reputation values.
type ClientWrapper reputation.Client
type ClientWrapper struct {
internal.StaticClient
client *reputation.Client
}
// Option allows to set an optional
// parameter of ClientWrapper.
@ -25,7 +30,7 @@ func defaultOpts() *opts {
// Morph returns raw morph client.
func (w ClientWrapper) Morph() *client.Client {
return (reputation.Client)(w).Morph()
return w.client.Morph()
}
// TryNotary returns option to enable
@ -65,5 +70,8 @@ func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8,
return nil, fmt.Errorf("could not create reputation contract client: %w", err)
}
return (*ClientWrapper)(enhancedRepurationClient), nil
return &ClientWrapper{
StaticClient: staticClient,
client: enhancedRepurationClient,
}, nil
}