forked from TrueCloudLab/frostfs-node
[#496] innerring/invoke: move wrapper structs to separate packages
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
ca0e3211be
commit
b52751e992
9 changed files with 104 additions and 116 deletions
|
@ -13,7 +13,6 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
crypto "github.com/nspcc-dev/neofs-crypto"
|
crypto "github.com/nspcc-dev/neofs-crypto"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/config"
|
"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/alphabet"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/audit"
|
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/audit"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/balance"
|
"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"
|
auditSettlement "github.com/nspcc-dev/neofs-node/pkg/innerring/processors/settlement/audit"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||||
auditWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/audit/wrapper"
|
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/event"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/subscriber"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/subscriber"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/timer"
|
"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
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
||||||
)
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
SDKClient "github.com/nspcc-dev/neofs-api-go/pkg/client"
|
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/config"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/invoke"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||||
wrapContainer "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
wrapContainer "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
||||||
wrapNetmap "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/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
|
// 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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// creating enhanced client for getting containers
|
// 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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package audit
|
package audit
|
||||||
|
|
||||||
import (
|
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"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/audit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,3 +15,13 @@ type ClientWrapper audit.Client
|
||||||
func WrapClient(c *audit.Client) *ClientWrapper {
|
func WrapClient(c *audit.Client) *ClientWrapper {
|
||||||
return (*ClientWrapper)(c)
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,11 @@ package wrapper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"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"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -41,3 +45,18 @@ func New(c *Client) (*Wrapper, error) {
|
||||||
client: c,
|
client: c,
|
||||||
}, nil
|
}, 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)
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
package wrapper
|
package wrapper
|
||||||
|
|
||||||
import (
|
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"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -34,3 +39,18 @@ func New(c *Client) (*Wrapper, error) {
|
||||||
client: c,
|
client: c,
|
||||||
}, nil
|
}, 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)
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,11 @@ package wrapper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"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"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -41,3 +45,18 @@ func New(c *Client) (*Wrapper, error) {
|
||||||
client: c,
|
client: c,
|
||||||
}, nil
|
}, 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)
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
package wrapper
|
package wrapper
|
||||||
|
|
||||||
import (
|
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"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,3 +17,18 @@ type ClientWrapper reputation.Client
|
||||||
func WrapClient(c *reputation.Client) *ClientWrapper {
|
func WrapClient(c *reputation.Client) *ClientWrapper {
|
||||||
return (*ClientWrapper)(c)
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue