frostfs-node/cmd/neofs-node/modules/morph/balance.go
Stanislav Bogatyrev b7b5079934 Add Inner Ring code
2020-07-24 17:07:37 +03:00

69 lines
1.8 KiB
Go

package morph
import (
contract "github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
clientWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/balance/wrapper"
accounting "github.com/nspcc-dev/neofs-node/pkg/network/transport/accounting/grpc"
"github.com/pkg/errors"
"go.uber.org/dig"
)
type balanceContractResult struct {
dig.Out
Client *clientWrapper.Wrapper
AccountingService accounting.Service
}
// BalanceContractName is a name of Balance contract config sub-section.
const BalanceContractName = "balance"
const (
balanceContractBalanceOfOpt = "balance_of_method"
balanceContractDecimalsOfOpt = "decimals_method"
)
// BalanceContractBalanceOfOptPath is a path to balanceOf method name option.
func BalanceContractBalanceOfOptPath() string {
return optPath(prefix, BalanceContractName, balanceContractBalanceOfOpt)
}
// BalanceContractDecimalsOfOptPath is a path to decimals method name option.
func BalanceContractDecimalsOfOptPath() string {
return optPath(prefix, BalanceContractName, balanceContractDecimalsOfOpt)
}
func newBalanceContract(p contractParams) (res balanceContractResult, err error) {
client, ok := p.MorphContracts[BalanceContractName]
if !ok {
err = errors.Errorf("missing %s contract client", BalanceContractName)
return
}
var (
balanceOfMethod = p.Viper.GetString(BalanceContractBalanceOfOptPath())
decimalsMethod = p.Viper.GetString(BalanceContractDecimalsOfOptPath())
)
var c *contract.Client
if c, err = contract.New(client,
contract.WithBalanceOfMethod(balanceOfMethod),
contract.WithDecimalsMethod(decimalsMethod),
); err != nil {
return
}
if res.Client, err = clientWrapper.New(c); err != nil {
return
}
if res.AccountingService, err = accounting.New(accounting.Params{
ContractClient: res.Client,
}); err != nil {
return
}
return
}