2020-12-21 08:40:30 +00:00
|
|
|
package invoke
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
2020-12-22 11:33:39 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/audit"
|
|
|
|
auditWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/audit/wrapper"
|
2021-01-26 10:33:28 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
|
|
|
|
balanceWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/balance/wrapper"
|
2020-12-21 08:40:30 +00:00
|
|
|
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"
|
2021-03-31 15:41:47 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation"
|
|
|
|
reputationWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation/wrapper"
|
2020-12-21 08:40:30 +00:00
|
|
|
)
|
|
|
|
|
2021-01-29 07:04:03 +00:00
|
|
|
// NewContainerClient creates wrapper to access data from container contract.
|
2021-04-29 13:39:09 +00:00
|
|
|
func NewContainerClient(cli *client.Client, contract util.Uint160, fee SideFeeProvider) (*wrapContainer.Wrapper, error) {
|
|
|
|
staticClient, err := client.NewStatic(cli, contract, fee.SideChainFee())
|
2020-12-21 08:40:30 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2021-01-29 07:04:03 +00:00
|
|
|
// NewNetmapClient creates wrapper to access data from netmap contract.
|
2021-04-29 13:39:09 +00:00
|
|
|
func NewNetmapClient(cli *client.Client, contract util.Uint160, fee SideFeeProvider) (*wrapNetmap.Wrapper, error) {
|
|
|
|
staticClient, err := client.NewStatic(cli, contract, fee.SideChainFee())
|
2020-12-21 08:40:30 +00:00
|
|
|
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)
|
|
|
|
}
|
2020-12-22 11:33:39 +00:00
|
|
|
|
2021-01-29 07:04:03 +00:00
|
|
|
// NewAuditClient creates wrapper to work with Audit contract.
|
2021-04-29 13:39:09 +00:00
|
|
|
func NewAuditClient(cli *client.Client, contract util.Uint160, fee SideFeeProvider) (*auditWrapper.ClientWrapper, error) {
|
|
|
|
staticClient, err := client.NewStatic(cli, contract, fee.SideChainFee())
|
2020-12-22 11:33:39 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return auditWrapper.WrapClient(audit.New(staticClient)), nil
|
|
|
|
}
|
2021-01-26 10:33:28 +00:00
|
|
|
|
2021-01-28 17:17:25 +00:00
|
|
|
// NewBalanceClient creates wrapper to work with Balance contract.
|
2021-04-29 13:39:09 +00:00
|
|
|
func NewBalanceClient(cli *client.Client, contract util.Uint160, fee SideFeeProvider) (*balanceWrapper.Wrapper, error) {
|
|
|
|
staticClient, err := client.NewStatic(cli, contract, fee.SideChainFee())
|
2021-01-26 10:33:28 +00:00
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not create static client of Balance contract: %w", err)
|
2021-01-26 10:33:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enhancedBalanceClient, err := balance.New(staticClient)
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not create Balance contract client: %w", err)
|
2021-01-26 10:33:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return balanceWrapper.New(enhancedBalanceClient)
|
|
|
|
}
|
2021-03-31 15:41:47 +00:00
|
|
|
|
|
|
|
// NewReputationClient creates wrapper to work with reputation contract.
|
2021-04-29 13:39:09 +00:00
|
|
|
func NewReputationClient(cli *client.Client, contract util.Uint160, fee SideFeeProvider) (*reputationWrapper.ClientWrapper, error) {
|
|
|
|
staticClient, err := client.NewStatic(cli, contract, fee.SideChainFee())
|
2021-03-31 15:41:47 +00:00
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not create static client of reputation contract: %w", err)
|
2021-03-31 15:41:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enhancedRepurationClient, err := reputation.New(staticClient)
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not create reputation contract client: %w", err)
|
2021-03-31 15:41:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return reputationWrapper.WrapClient(enhancedRepurationClient), nil
|
|
|
|
}
|