From d6c03074310c95e351a55926410d69db88c97330 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 15 Sep 2021 13:48:00 +0300 Subject: [PATCH] [#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 --- pkg/morph/client/audit/wrapper/result.go | 12 ++++++------ pkg/morph/client/audit/wrapper/wrapper.go | 12 ++++++++++-- pkg/morph/client/balance/wrapper/wrapper.go | 8 +++++++- pkg/morph/client/container/wrapper/wrapper.go | 8 +++++++- pkg/morph/client/neofs/wrapper/bind.go | 4 ++-- pkg/morph/client/neofs/wrapper/cheque.go | 5 ++--- pkg/morph/client/neofs/wrapper/client.go | 12 ++++++++++-- pkg/morph/client/neofsid/wrapper/client.go | 12 ++++++++++-- pkg/morph/client/neofsid/wrapper/keys.go | 6 +++--- pkg/morph/client/netmap/wrapper/wrapper.go | 8 +++++++- pkg/morph/client/reputation/wrapper/get.go | 4 ++-- pkg/morph/client/reputation/wrapper/list.go | 2 +- pkg/morph/client/reputation/wrapper/put.go | 2 +- pkg/morph/client/reputation/wrapper/wrapper.go | 14 +++++++++++--- 14 files changed, 79 insertions(+), 30 deletions(-) diff --git a/pkg/morph/client/audit/wrapper/result.go b/pkg/morph/client/audit/wrapper/result.go index 3d891c687..57c610977 100644 --- a/pkg/morph/client/audit/wrapper/result.go +++ b/pkg/morph/client/audit/wrapper/result.go @@ -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 } diff --git a/pkg/morph/client/audit/wrapper/wrapper.go b/pkg/morph/client/audit/wrapper/wrapper.go index c46a85912..2ef66491c 100644 --- a/pkg/morph/client/audit/wrapper/wrapper.go +++ b/pkg/morph/client/audit/wrapper/wrapper.go @@ -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 } diff --git a/pkg/morph/client/balance/wrapper/wrapper.go b/pkg/morph/client/balance/wrapper/wrapper.go index 0599626ff..695387030 100644 --- a/pkg/morph/client/balance/wrapper/wrapper.go +++ b/pkg/morph/client/balance/wrapper/wrapper.go @@ -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 } diff --git a/pkg/morph/client/container/wrapper/wrapper.go b/pkg/morph/client/container/wrapper/wrapper.go index 0036a6a5a..de762fa8e 100644 --- a/pkg/morph/client/container/wrapper/wrapper.go +++ b/pkg/morph/client/container/wrapper/wrapper.go @@ -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 } diff --git a/pkg/morph/client/neofs/wrapper/bind.go b/pkg/morph/client/neofs/wrapper/bind.go index 3d29ab4c2..df793cad5 100644 --- a/pkg/morph/client/neofs/wrapper/bind.go +++ b/pkg/morph/client/neofs/wrapper/bind.go @@ -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)) } } diff --git a/pkg/morph/client/neofs/wrapper/cheque.go b/pkg/morph/client/neofs/wrapper/cheque.go index c03b8f7da..955449d64 100644 --- a/pkg/morph/client/neofs/wrapper/cheque.go +++ b/pkg/morph/client/neofs/wrapper/cheque.go @@ -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) } diff --git a/pkg/morph/client/neofs/wrapper/client.go b/pkg/morph/client/neofs/wrapper/client.go index 90c495385..bbd0fe61f 100644 --- a/pkg/morph/client/neofs/wrapper/client.go +++ b/pkg/morph/client/neofs/wrapper/client.go @@ -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 } diff --git a/pkg/morph/client/neofsid/wrapper/client.go b/pkg/morph/client/neofsid/wrapper/client.go index 9bc28c31c..35aa33a95 100644 --- a/pkg/morph/client/neofsid/wrapper/client.go +++ b/pkg/morph/client/neofsid/wrapper/client.go @@ -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 } diff --git a/pkg/morph/client/neofsid/wrapper/keys.go b/pkg/morph/client/neofsid/wrapper/keys.go index 5748b01ac..12005015e 100644 --- a/pkg/morph/client/neofsid/wrapper/keys.go +++ b/pkg/morph/client/neofsid/wrapper/keys.go @@ -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)) } } diff --git a/pkg/morph/client/netmap/wrapper/wrapper.go b/pkg/morph/client/netmap/wrapper/wrapper.go index c9ae33756..05ad7f92d 100644 --- a/pkg/morph/client/netmap/wrapper/wrapper.go +++ b/pkg/morph/client/netmap/wrapper/wrapper.go @@ -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. diff --git a/pkg/morph/client/reputation/wrapper/get.go b/pkg/morph/client/reputation/wrapper/get.go index a99cdef50..cb7ae949d 100644 --- a/pkg/morph/client/reputation/wrapper/get.go +++ b/pkg/morph/client/reputation/wrapper/get.go @@ -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 } diff --git a/pkg/morph/client/reputation/wrapper/list.go b/pkg/morph/client/reputation/wrapper/list.go index 1392de2e0..0b18c040f 100644 --- a/pkg/morph/client/reputation/wrapper/list.go +++ b/pkg/morph/client/reputation/wrapper/list.go @@ -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 } diff --git a/pkg/morph/client/reputation/wrapper/put.go b/pkg/morph/client/reputation/wrapper/put.go index 7b2c92d09..22fc1f863 100644 --- a/pkg/morph/client/reputation/wrapper/put.go +++ b/pkg/morph/client/reputation/wrapper/put.go @@ -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) { diff --git a/pkg/morph/client/reputation/wrapper/wrapper.go b/pkg/morph/client/reputation/wrapper/wrapper.go index e7ded7f2b..6f5015bb4 100644 --- a/pkg/morph/client/reputation/wrapper/wrapper.go +++ b/pkg/morph/client/reputation/wrapper/wrapper.go @@ -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 }