2020-07-10 14:17:51 +00:00
|
|
|
package morph
|
|
|
|
|
|
|
|
import (
|
2020-07-24 13:54:03 +00:00
|
|
|
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"
|
2020-07-10 14:17:51 +00:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"go.uber.org/dig"
|
|
|
|
)
|
|
|
|
|
|
|
|
type balanceContractResult struct {
|
|
|
|
dig.Out
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
Client *clientWrapper.Wrapper
|
2020-07-10 14:17:51 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
var (
|
|
|
|
balanceOfMethod = p.Viper.GetString(BalanceContractBalanceOfOptPath())
|
|
|
|
decimalsMethod = p.Viper.GetString(BalanceContractDecimalsOfOptPath())
|
2020-07-10 14:17:51 +00:00
|
|
|
)
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-07-10 14:17:51 +00:00
|
|
|
if res.AccountingService, err = accounting.New(accounting.Params{
|
2020-07-24 13:54:03 +00:00
|
|
|
ContractClient: res.Client,
|
2020-07-10 14:17:51 +00:00
|
|
|
}); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|