forked from TrueCloudLab/frostfs-node
[#496] Use single contract wrapper constructor
There is no need in a separate `New()` or `WrapClient()` Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
b52751e992
commit
2b2b2c2c45
11 changed files with 12 additions and 121 deletions
|
@ -2,8 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
accountingGRPC "github.com/nspcc-dev/neofs-api-go/v2/accounting/grpc"
|
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"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance/wrapper"
|
||||||
accountingTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/accounting/grpc"
|
accountingTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/accounting/grpc"
|
||||||
accountingService "github.com/nspcc-dev/neofs-node/pkg/services/accounting"
|
accountingService "github.com/nspcc-dev/neofs-node/pkg/services/accounting"
|
||||||
|
@ -15,17 +13,7 @@ func initAccountingService(c *cfg) {
|
||||||
initMorphComponents(c)
|
initMorphComponents(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
staticClient, err := client.NewStatic(
|
balanceMorphWrapper, err := wrapper.NewFromMorph(c.cfgMorph.client, c.cfgAccounting.scriptHash, 0)
|
||||||
c.cfgMorph.client,
|
|
||||||
c.cfgAccounting.scriptHash,
|
|
||||||
0,
|
|
||||||
)
|
|
||||||
fatalOnErr(err)
|
|
||||||
|
|
||||||
balanceClient, err := balance.New(staticClient)
|
|
||||||
fatalOnErr(err)
|
|
||||||
|
|
||||||
balanceMorphWrapper, err := wrapper.New(balanceClient)
|
|
||||||
fatalOnErr(err)
|
fatalOnErr(err)
|
||||||
|
|
||||||
accountingGRPC.RegisterAccountingServiceServer(c.cfgGRPC.server,
|
accountingGRPC.RegisterAccountingServiceServer(c.cfgGRPC.server,
|
||||||
|
|
|
@ -17,8 +17,6 @@ import (
|
||||||
containerCore "github.com/nspcc-dev/neofs-node/pkg/core/container"
|
containerCore "github.com/nspcc-dev/neofs-node/pkg/core/container"
|
||||||
netmapCore "github.com/nspcc-dev/neofs-node/pkg/core/netmap"
|
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/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/client/container/wrapper"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||||
containerEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/container"
|
containerEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/container"
|
||||||
|
@ -41,17 +39,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func initContainerService(c *cfg) {
|
func initContainerService(c *cfg) {
|
||||||
staticClient, err := client.NewStatic(
|
wrap, err := wrapper.NewFromMorph(c.cfgMorph.client, c.cfgContainer.scriptHash, 0)
|
||||||
c.cfgMorph.client,
|
|
||||||
c.cfgContainer.scriptHash,
|
|
||||||
0,
|
|
||||||
)
|
|
||||||
fatalOnErr(err)
|
|
||||||
|
|
||||||
cnrClient, err := container.New(staticClient)
|
|
||||||
fatalOnErr(err)
|
|
||||||
|
|
||||||
wrap, err := wrapper.New(cnrClient)
|
|
||||||
fatalOnErr(err)
|
fatalOnErr(err)
|
||||||
|
|
||||||
c.cfgObject.cnrStorage = newCachedContainerStorage(wrap) // use RPC node as source of containers (with caching)
|
c.cfgObject.cnrStorage = newCachedContainerStorage(wrap) // use RPC node as source of containers (with caching)
|
||||||
|
@ -126,7 +114,7 @@ func initContainerService(c *cfg) {
|
||||||
c.key,
|
c.key,
|
||||||
containerService.NewResponseService(
|
containerService.NewResponseService(
|
||||||
&usedSpaceService{
|
&usedSpaceService{
|
||||||
Server: containerService.NewExecutionService(containerMorph.NewExecutor(cnrClient)),
|
Server: containerService.NewExecutionService(containerMorph.NewExecutor(wrap)),
|
||||||
loadWriterProvider: loadRouter,
|
loadWriterProvider: loadRouter,
|
||||||
loadPlacementBuilder: loadPlacementBuilder,
|
loadPlacementBuilder: loadPlacementBuilder,
|
||||||
routeBuilder: routeBuilder,
|
routeBuilder: routeBuilder,
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"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"
|
||||||
"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/client/netmap/wrapper"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||||
netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
|
netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
|
||||||
|
@ -74,17 +73,7 @@ func initMorphComponents(c *cfg) {
|
||||||
c.cfgMorph.client = cli
|
c.cfgMorph.client = cli
|
||||||
}, true)
|
}, true)
|
||||||
|
|
||||||
staticClient, err := client.NewStatic(
|
wrap, err := wrapper.NewFromMorph(c.cfgMorph.client, c.cfgNetmap.scriptHash, 0)
|
||||||
c.cfgMorph.client,
|
|
||||||
c.cfgNetmap.scriptHash,
|
|
||||||
0,
|
|
||||||
)
|
|
||||||
fatalOnErr(err)
|
|
||||||
|
|
||||||
cli, err := netmap.New(staticClient)
|
|
||||||
fatalOnErr(err)
|
|
||||||
|
|
||||||
wrap, err := wrapper.New(cli)
|
|
||||||
fatalOnErr(err)
|
fatalOnErr(err)
|
||||||
|
|
||||||
c.cfgObject.netMapStorage = newCachedNetmapStorage(c.cfgNetmap.state, wrap)
|
c.cfgObject.netMapStorage = newCachedNetmapStorage(c.cfgNetmap.state, wrap)
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
|
||||||
v2reputation "github.com/nspcc-dev/neofs-api-go/v2/reputation"
|
v2reputation "github.com/nspcc-dev/neofs-api-go/v2/reputation"
|
||||||
v2reputationgrpc "github.com/nspcc-dev/neofs-api-go/v2/reputation/grpc"
|
v2reputationgrpc "github.com/nspcc-dev/neofs-api-go/v2/reputation/grpc"
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
"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"
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/reputation/intermediate"
|
||||||
intermediatereputation "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"
|
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"
|
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"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
|
||||||
|
@ -38,17 +35,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func initReputationService(c *cfg) {
|
func initReputationService(c *cfg) {
|
||||||
staticClient, err := client.NewStatic(
|
wrap, err := rtpwrapper.NewFromMorph(c.cfgMorph.client, c.cfgReputation.scriptHash, 0)
|
||||||
c.cfgMorph.client,
|
|
||||||
c.cfgReputation.scriptHash,
|
|
||||||
fixedn.Fixed8(0),
|
|
||||||
)
|
|
||||||
fatalOnErr(err)
|
|
||||||
|
|
||||||
rptClient, err := rptclient.New(staticClient)
|
|
||||||
fatalOnErr(err)
|
|
||||||
|
|
||||||
wrap := rtpwrapper.WrapClient(rptClient)
|
|
||||||
fatalOnErr(err)
|
fatalOnErr(err)
|
||||||
|
|
||||||
localKey := crypto.MarshalPublicKey(&c.key.PublicKey)
|
localKey := crypto.MarshalPublicKey(&c.key.PublicKey)
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||||
crypto "github.com/nspcc-dev/neofs-crypto"
|
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"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/audit"
|
|
||||||
auditWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/audit/wrapper"
|
auditWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/audit/wrapper"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -34,13 +33,9 @@ func TestAuditResults(t *testing.T) {
|
||||||
morphClient, err := client.New(key, endpoint)
|
morphClient, err := client.New(key, endpoint)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
auditContractClient, err := client.NewStatic(morphClient, auditHash, 0)
|
auditClientWrapper, err := auditWrapper.NewFromMorph(morphClient, auditHash, 0)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
auditClient := audit.New(auditContractClient)
|
|
||||||
|
|
||||||
auditClientWrapper := auditWrapper.WrapClient(auditClient)
|
|
||||||
|
|
||||||
cid := container.NewID()
|
cid := container.NewID()
|
||||||
cid.SetSHA256([sha256.Size]byte{1, 2, 3})
|
cid.SetSHA256([sha256.Size]byte{1, 2, 3})
|
||||||
|
|
||||||
|
|
|
@ -11,11 +11,6 @@ import (
|
||||||
// client which implements storage of audit results.
|
// client which implements storage of audit results.
|
||||||
type ClientWrapper audit.Client
|
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.
|
// NewFromMorph returns the wrapper instance from the raw morph client.
|
||||||
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8) (*ClientWrapper, error) {
|
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8) (*ClientWrapper, error) {
|
||||||
staticClient, err := client.NewStatic(cli, contract, fee)
|
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 nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return WrapClient(audit.New(staticClient)), nil
|
return (*ClientWrapper)(audit.New(staticClient)), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,19 +33,6 @@ type Wrapper struct {
|
||||||
// a non-nil Wrapper pointer, but received nil.
|
// a non-nil Wrapper pointer, but received nil.
|
||||||
var ErrNilWrapper = errors.New("balance contract client wrapper is 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.
|
// NewFromMorph returns the wrapper instance from the raw morph client.
|
||||||
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8) (*Wrapper, error) {
|
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8) (*Wrapper, error) {
|
||||||
staticClient, err := client.NewStatic(cli, contract, fee)
|
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 nil, fmt.Errorf("could not create Balance contract client: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return New(enhancedBalanceClient)
|
return &Wrapper{client: enhancedBalanceClient}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,19 +27,6 @@ type Wrapper struct {
|
||||||
client *Client
|
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.
|
// NewFromMorph returns the wrapper instance from the raw morph client.
|
||||||
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8) (*Wrapper, error) {
|
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8) (*Wrapper, error) {
|
||||||
staticClient, err := client.NewStatic(cli, contract, fee)
|
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 nil, fmt.Errorf("can't create container morph client: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return New(enhancedContainerClient)
|
return &Wrapper{client: enhancedContainerClient}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,19 +33,6 @@ type Wrapper struct {
|
||||||
// a non-nil Wrapper pointer, but received nil.
|
// a non-nil Wrapper pointer, but received nil.
|
||||||
var ErrNilWrapper = errors.New("netmap contract client wrapper is 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.
|
// NewFromMorph returns the wrapper instance from the raw morph client.
|
||||||
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8) (*Wrapper, error) {
|
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8) (*Wrapper, error) {
|
||||||
staticClient, err := client.NewStatic(cli, contract, fee)
|
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 nil, fmt.Errorf("can't create netmap morph client: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return New(enhancedNetmapClient)
|
return &Wrapper{client: enhancedNetmapClient}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,11 +13,6 @@ import (
|
||||||
// client which implements storage of reputation values.
|
// client which implements storage of reputation values.
|
||||||
type ClientWrapper reputation.Client
|
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.
|
// NewFromMorph returns the wrapper instance from the raw morph client.
|
||||||
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8) (*ClientWrapper, error) {
|
func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8) (*ClientWrapper, error) {
|
||||||
staticClient, err := client.NewStatic(cli, contract, fee)
|
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 nil, fmt.Errorf("could not create reputation contract client: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return WrapClient(enhancedRepurationClient), nil
|
return (*ClientWrapper)(enhancedRepurationClient), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
"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/container"
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
"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"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
||||||
containerSvc "github.com/nspcc-dev/neofs-node/pkg/services/container"
|
containerSvc "github.com/nspcc-dev/neofs-node/pkg/services/container"
|
||||||
)
|
)
|
||||||
|
@ -18,13 +17,7 @@ type morphExecutor struct {
|
||||||
wrapper *wrapper.Wrapper
|
wrapper *wrapper.Wrapper
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExecutor(client *containerMorph.Client) containerSvc.ServiceExecutor {
|
func NewExecutor(w *wrapper.Wrapper) containerSvc.ServiceExecutor {
|
||||||
w, err := wrapper.New(client)
|
|
||||||
if err != nil {
|
|
||||||
// log there, maybe panic?
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return &morphExecutor{
|
return &morphExecutor{
|
||||||
wrapper: w,
|
wrapper: w,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue