[#496] Use single contract wrapper constructor

There is no need in a separate `New()` or `WrapClient()`

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
remotes/KirillovDenis/release/v0.21.1
Evgenii Stratonikov 2021-05-21 14:02:46 +03:00 committed by Alex Vanin
parent b52751e992
commit 2b2b2c2c45
11 changed files with 12 additions and 121 deletions

View File

@ -2,8 +2,6 @@ package main
import (
accountingGRPC "github.com/nspcc-dev/neofs-api-go/v2/accounting/grpc"
"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/balance/wrapper"
accountingTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/accounting/grpc"
accountingService "github.com/nspcc-dev/neofs-node/pkg/services/accounting"
@ -15,17 +13,7 @@ func initAccountingService(c *cfg) {
initMorphComponents(c)
}
staticClient, err := client.NewStatic(
c.cfgMorph.client,
c.cfgAccounting.scriptHash,
0,
)
fatalOnErr(err)
balanceClient, err := balance.New(staticClient)
fatalOnErr(err)
balanceMorphWrapper, err := wrapper.New(balanceClient)
balanceMorphWrapper, err := wrapper.NewFromMorph(c.cfgMorph.client, c.cfgAccounting.scriptHash, 0)
fatalOnErr(err)
accountingGRPC.RegisterAccountingServiceServer(c.cfgGRPC.server,

View File

@ -17,8 +17,6 @@ import (
containerCore "github.com/nspcc-dev/neofs-node/pkg/core/container"
netmapCore "github.com/nspcc-dev/neofs-node/pkg/core/netmap"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
"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/container/wrapper"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
containerEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/container"
@ -41,17 +39,7 @@ const (
)
func initContainerService(c *cfg) {
staticClient, err := client.NewStatic(
c.cfgMorph.client,
c.cfgContainer.scriptHash,
0,
)
fatalOnErr(err)
cnrClient, err := container.New(staticClient)
fatalOnErr(err)
wrap, err := wrapper.New(cnrClient)
wrap, err := wrapper.NewFromMorph(c.cfgMorph.client, c.cfgContainer.scriptHash, 0)
fatalOnErr(err)
c.cfgObject.cnrStorage = newCachedContainerStorage(wrap) // use RPC node as source of containers (with caching)
@ -126,7 +114,7 @@ func initContainerService(c *cfg) {
c.key,
containerService.NewResponseService(
&usedSpaceService{
Server: containerService.NewExecutionService(containerMorph.NewExecutor(cnrClient)),
Server: containerService.NewExecutionService(containerMorph.NewExecutor(wrap)),
loadWriterProvider: loadRouter,
loadPlacementBuilder: loadPlacementBuilder,
routeBuilder: routeBuilder,

View File

@ -9,7 +9,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/block"
"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/netmap"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
@ -74,17 +73,7 @@ func initMorphComponents(c *cfg) {
c.cfgMorph.client = cli
}, true)
staticClient, err := client.NewStatic(
c.cfgMorph.client,
c.cfgNetmap.scriptHash,
0,
)
fatalOnErr(err)
cli, err := netmap.New(staticClient)
fatalOnErr(err)
wrap, err := wrapper.New(cli)
wrap, err := wrapper.NewFromMorph(c.cfgMorph.client, c.cfgNetmap.scriptHash, 0)
fatalOnErr(err)
c.cfgObject.netMapStorage = newCachedNetmapStorage(c.cfgNetmap.state, wrap)

View File

@ -4,7 +4,6 @@ import (
"context"
"fmt"
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
v2reputation "github.com/nspcc-dev/neofs-api-go/v2/reputation"
v2reputationgrpc "github.com/nspcc-dev/neofs-api-go/v2/reputation/grpc"
"github.com/nspcc-dev/neofs-api-go/v2/session"
@ -13,8 +12,6 @@ import (
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/intermediate"
intermediatereputation "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/intermediate"
localreputation "github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/local"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
rptclient "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation"
rtpwrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation/wrapper"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
@ -38,17 +35,7 @@ import (
)
func initReputationService(c *cfg) {
staticClient, err := client.NewStatic(
c.cfgMorph.client,
c.cfgReputation.scriptHash,
fixedn.Fixed8(0),
)
fatalOnErr(err)
rptClient, err := rptclient.New(staticClient)
fatalOnErr(err)
wrap := rtpwrapper.WrapClient(rptClient)
wrap, err := rtpwrapper.NewFromMorph(c.cfgMorph.client, c.cfgReputation.scriptHash, 0)
fatalOnErr(err)
localKey := crypto.MarshalPublicKey(&c.key.PublicKey)

View File

@ -10,7 +10,6 @@ import (
"github.com/nspcc-dev/neofs-api-go/pkg/container"
crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/audit"
auditWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/audit/wrapper"
"github.com/stretchr/testify/require"
)
@ -34,13 +33,9 @@ func TestAuditResults(t *testing.T) {
morphClient, err := client.New(key, endpoint)
require.NoError(t, err)
auditContractClient, err := client.NewStatic(morphClient, auditHash, 0)
auditClientWrapper, err := auditWrapper.NewFromMorph(morphClient, auditHash, 0)
require.NoError(t, err)
auditClient := audit.New(auditContractClient)
auditClientWrapper := auditWrapper.WrapClient(auditClient)
cid := container.NewID()
cid.SetSHA256([sha256.Size]byte{1, 2, 3})

View File

@ -11,11 +11,6 @@ import (
// client which implements storage of audit results.
type ClientWrapper audit.Client
// WrapClient wraps Audit contract client and returns ClientWrapper instance.
func WrapClient(c *audit.Client) *ClientWrapper {
return (*ClientWrapper)(c)
}
// NewFromMorph returns the wrapper instance from the raw morph client.
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8) (*ClientWrapper, error) {
staticClient, err := client.NewStatic(cli, contract, fee)
@ -23,5 +18,5 @@ func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8)
return nil, err
}
return WrapClient(audit.New(staticClient)), nil
return (*ClientWrapper)(audit.New(staticClient)), nil
}

View File

@ -33,19 +33,6 @@ type Wrapper struct {
// a non-nil Wrapper pointer, but received nil.
var ErrNilWrapper = errors.New("balance contract client wrapper is nil")
// New creates, initializes and returns the Wrapper instance.
//
// If Client is nil, balance.ErrNilClient is returned.
func New(c *Client) (*Wrapper, error) {
if c == nil {
return nil, balance.ErrNilClient
}
return &Wrapper{
client: c,
}, nil
}
// NewFromMorph returns the wrapper instance from the raw morph client.
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8) (*Wrapper, error) {
staticClient, err := client.NewStatic(cli, contract, fee)
@ -58,5 +45,5 @@ func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8)
return nil, fmt.Errorf("could not create Balance contract client: %w", err)
}
return New(enhancedBalanceClient)
return &Wrapper{client: enhancedBalanceClient}, nil
}

View File

@ -27,19 +27,6 @@ type Wrapper struct {
client *Client
}
// New creates, initializes and returns the Wrapper instance.
//
// If Client is nil, container.ErrNilClient is returned.
func New(c *Client) (*Wrapper, error) {
if c == nil {
return nil, container.ErrNilClient
}
return &Wrapper{
client: c,
}, nil
}
// NewFromMorph returns the wrapper instance from the raw morph client.
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8) (*Wrapper, error) {
staticClient, err := client.NewStatic(cli, contract, fee)
@ -52,5 +39,5 @@ func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8)
return nil, fmt.Errorf("can't create container morph client: %w", err)
}
return New(enhancedContainerClient)
return &Wrapper{client: enhancedContainerClient}, nil
}

View File

@ -33,19 +33,6 @@ type Wrapper struct {
// a non-nil Wrapper pointer, but received nil.
var ErrNilWrapper = errors.New("netmap contract client wrapper is nil")
// New creates, initializes and returns the Wrapper instance.
//
// If Client is nil, netmap.ErrNilClient is returned.
func New(c *Client) (*Wrapper, error) {
if c == nil {
return nil, netmap.ErrNilClient
}
return &Wrapper{
client: c,
}, nil
}
// NewFromMorph returns the wrapper instance from the raw morph client.
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8) (*Wrapper, error) {
staticClient, err := client.NewStatic(cli, contract, fee)
@ -58,5 +45,5 @@ func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8)
return nil, fmt.Errorf("can't create netmap morph client: %w", err)
}
return New(enhancedNetmapClient)
return &Wrapper{client: enhancedNetmapClient}, nil
}

View File

@ -13,11 +13,6 @@ import (
// client which implements storage of reputation values.
type ClientWrapper reputation.Client
// WrapClient wraps reputation contract client and returns ClientWrapper instance.
func WrapClient(c *reputation.Client) *ClientWrapper {
return (*ClientWrapper)(c)
}
// NewFromMorph returns the wrapper instance from the raw morph client.
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8) (*ClientWrapper, error) {
staticClient, err := client.NewStatic(cli, contract, fee)
@ -30,5 +25,5 @@ func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8)
return nil, fmt.Errorf("could not create reputation contract client: %w", err)
}
return WrapClient(enhancedRepurationClient), nil
return (*ClientWrapper)(enhancedRepurationClient), nil
}

View File

@ -9,7 +9,6 @@ import (
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
"github.com/nspcc-dev/neofs-api-go/v2/container"
"github.com/nspcc-dev/neofs-api-go/v2/refs"
containerMorph "github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
containerSvc "github.com/nspcc-dev/neofs-node/pkg/services/container"
)
@ -18,13 +17,7 @@ type morphExecutor struct {
wrapper *wrapper.Wrapper
}
func NewExecutor(client *containerMorph.Client) containerSvc.ServiceExecutor {
w, err := wrapper.New(client)
if err != nil {
// log there, maybe panic?
return nil
}
func NewExecutor(w *wrapper.Wrapper) containerSvc.ServiceExecutor {
return &morphExecutor{
wrapper: w,
}