[#496] innerring/invoke: move wrapper structs to separate packages

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-05-21 13:39:01 +03:00 committed by Alex Vanin
parent ca0e3211be
commit b52751e992
9 changed files with 104 additions and 116 deletions

View file

@ -13,7 +13,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/util"
crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-node/pkg/innerring/config"
"github.com/nspcc-dev/neofs-node/pkg/innerring/invoke"
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/alphabet"
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/audit"
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/balance"
@ -26,6 +25,10 @@ import (
auditSettlement "github.com/nspcc-dev/neofs-node/pkg/innerring/processors/settlement/audit"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
auditWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/audit/wrapper"
balanceWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/balance/wrapper"
cntWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/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"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/nspcc-dev/neofs-node/pkg/morph/subscriber"
"github.com/nspcc-dev/neofs-node/pkg/morph/timer"
@ -345,27 +348,29 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
return nil, err
}
server.auditClient, err = invoke.NewAuditClient(server.morphClient, server.contracts.audit, server.feeConfig)
fee := server.feeConfig.SideChainFee()
server.auditClient, err = auditWrapper.NewFromMorph(server.morphClient, server.contracts.audit, fee)
if err != nil {
return nil, err
}
cnrClient, err := invoke.NewContainerClient(server.morphClient, server.contracts.container, server.feeConfig)
cnrClient, err := cntWrapper.NewFromMorph(server.morphClient, server.contracts.container, fee)
if err != nil {
return nil, err
}
nmClient, err := invoke.NewNetmapClient(server.morphClient, server.contracts.netmap, server.feeConfig)
nmClient, err := nmWrapper.NewFromMorph(server.morphClient, server.contracts.netmap, fee)
if err != nil {
return nil, err
}
balClient, err := invoke.NewBalanceClient(server.morphClient, server.contracts.balance, server.feeConfig)
balClient, err := balanceWrapper.NewFromMorph(server.morphClient, server.contracts.balance, fee)
if err != nil {
return nil, err
}
repClient, err := invoke.NewReputationClient(server.morphClient, server.contracts.reputation, server.feeConfig)
repClient, err := repWrapper.NewFromMorph(server.morphClient, server.contracts.reputation, fee)
if err != nil {
return nil, err
}

View file

@ -1,19 +0,0 @@
package invoke
import (
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
)
type (
// SideFeeProvider is an interface that used by invoker package method to
// get extra fee for all non notary smart contract invocations in side chain.
SideFeeProvider interface {
SideChainFee() fixedn.Fixed8
}
// MainFeeProvider is an interface that used by invoker package method to
// get extra fee for all non notary smart contract invocations in main chain.
MainFeeProvider interface {
MainChainFee() fixedn.Fixed8
}
)

View file

@ -1,88 +0,0 @@
package invoke
import (
"fmt"
"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"
auditWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/audit/wrapper"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
balanceWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/balance/wrapper"
morphContainer "github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
wrapContainer "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
morphNetmap "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
wrapNetmap "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation"
reputationWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation/wrapper"
)
// NewContainerClient creates wrapper to access data from container contract.
func NewContainerClient(cli *client.Client, contract util.Uint160, fee SideFeeProvider) (*wrapContainer.Wrapper, error) {
staticClient, err := client.NewStatic(cli, contract, fee.SideChainFee())
if err != nil {
return nil, fmt.Errorf("can't create container static client: %w", err)
}
enhancedContainerClient, err := morphContainer.New(staticClient)
if err != nil {
return nil, fmt.Errorf("can't create container morph client: %w", err)
}
return wrapContainer.New(enhancedContainerClient)
}
// NewNetmapClient creates wrapper to access data from netmap contract.
func NewNetmapClient(cli *client.Client, contract util.Uint160, fee SideFeeProvider) (*wrapNetmap.Wrapper, error) {
staticClient, err := client.NewStatic(cli, contract, fee.SideChainFee())
if err != nil {
return nil, fmt.Errorf("can't create netmap static client: %w", err)
}
enhancedNetmapClient, err := morphNetmap.New(staticClient)
if err != nil {
return nil, fmt.Errorf("can't create netmap morph client: %w", err)
}
return wrapNetmap.New(enhancedNetmapClient)
}
// NewAuditClient creates wrapper to work with Audit contract.
func NewAuditClient(cli *client.Client, contract util.Uint160, fee SideFeeProvider) (*auditWrapper.ClientWrapper, error) {
staticClient, err := client.NewStatic(cli, contract, fee.SideChainFee())
if err != nil {
return nil, err
}
return auditWrapper.WrapClient(audit.New(staticClient)), nil
}
// NewBalanceClient creates wrapper to work with Balance contract.
func NewBalanceClient(cli *client.Client, contract util.Uint160, fee SideFeeProvider) (*balanceWrapper.Wrapper, error) {
staticClient, err := client.NewStatic(cli, contract, fee.SideChainFee())
if err != nil {
return nil, fmt.Errorf("could not create static client of Balance contract: %w", err)
}
enhancedBalanceClient, err := balance.New(staticClient)
if err != nil {
return nil, fmt.Errorf("could not create Balance contract client: %w", err)
}
return balanceWrapper.New(enhancedBalanceClient)
}
// NewReputationClient creates wrapper to work with reputation contract.
func NewReputationClient(cli *client.Client, contract util.Uint160, fee SideFeeProvider) (*reputationWrapper.ClientWrapper, error) {
staticClient, err := client.NewStatic(cli, contract, fee.SideChainFee())
if err != nil {
return nil, fmt.Errorf("could not create static client of reputation contract: %w", err)
}
enhancedRepurationClient, err := reputation.New(staticClient)
if err != nil {
return nil, fmt.Errorf("could not create reputation contract client: %w", err)
}
return reputationWrapper.WrapClient(enhancedRepurationClient), nil
}

View file

@ -10,7 +10,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/util"
SDKClient "github.com/nspcc-dev/neofs-api-go/pkg/client"
"github.com/nspcc-dev/neofs-node/pkg/innerring/config"
"github.com/nspcc-dev/neofs-node/pkg/innerring/invoke"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
wrapContainer "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
wrapNetmap "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
@ -115,13 +114,13 @@ func New(p *Params) (*Processor, error) {
}
// creating enhanced client for getting network map
netmapClient, err := invoke.NewNetmapClient(p.MorphClient, p.NetmapContract, p.FeeProvider)
netmapClient, err := wrapNetmap.NewFromMorph(p.MorphClient, p.NetmapContract, p.FeeProvider.SideChainFee())
if err != nil {
return nil, err
}
// creating enhanced client for getting containers
containerClient, err := invoke.NewContainerClient(p.MorphClient, p.ContainerContract, p.FeeProvider)
containerClient, err := wrapContainer.NewFromMorph(p.MorphClient, p.ContainerContract, p.FeeProvider.SideChainFee())
if err != nil {
return nil, err
}

View file

@ -1,6 +1,9 @@
package audit
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/audit"
)
@ -12,3 +15,13 @@ type ClientWrapper audit.Client
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)
if err != nil {
return nil, err
}
return WrapClient(audit.New(staticClient)), nil
}

View file

@ -2,7 +2,11 @@ package wrapper
import (
"errors"
"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/balance"
)
@ -41,3 +45,18 @@ func New(c *Client) (*Wrapper, error) {
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)
if err != nil {
return nil, fmt.Errorf("could not create static client of Balance contract: %w", err)
}
enhancedBalanceClient, err := balance.New(staticClient)
if err != nil {
return nil, fmt.Errorf("could not create Balance contract client: %w", err)
}
return New(enhancedBalanceClient)
}

View file

@ -1,6 +1,11 @@
package wrapper
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/container"
)
@ -34,3 +39,18 @@ func New(c *Client) (*Wrapper, error) {
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)
if err != nil {
return nil, fmt.Errorf("can't create container static client: %w", err)
}
enhancedContainerClient, err := container.New(staticClient)
if err != nil {
return nil, fmt.Errorf("can't create container morph client: %w", err)
}
return New(enhancedContainerClient)
}

View file

@ -2,7 +2,11 @@ package wrapper
import (
"errors"
"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/netmap"
)
@ -41,3 +45,18 @@ func New(c *Client) (*Wrapper, error) {
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)
if err != nil {
return nil, fmt.Errorf("can't create netmap static client: %w", err)
}
enhancedNetmapClient, err := netmap.New(staticClient)
if err != nil {
return nil, fmt.Errorf("can't create netmap morph client: %w", err)
}
return New(enhancedNetmapClient)
}

View file

@ -1,6 +1,11 @@
package wrapper
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/reputation"
)
@ -12,3 +17,18 @@ type ClientWrapper reputation.Client
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)
if err != nil {
return nil, fmt.Errorf("could not create static client of reputation contract: %w", err)
}
enhancedRepurationClient, err := reputation.New(staticClient)
if err != nil {
return nil, fmt.Errorf("could not create reputation contract client: %w", err)
}
return WrapClient(enhancedRepurationClient), nil
}