frostfs-node/pkg/services/accounting/morph/executor.go
Evgenii Stratonikov 6f50fefbea [#625] client/balance: remove intermediate wrapper
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2022-02-08 09:43:54 +03:00

41 lines
961 B
Go

package accounting
import (
"context"
"github.com/nspcc-dev/neofs-api-go/v2/accounting"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
accountingSvc "github.com/nspcc-dev/neofs-node/pkg/services/accounting"
"github.com/nspcc-dev/neofs-sdk-go/owner"
)
type morphExecutor struct {
client *balance.Client
}
func NewExecutor(client *balance.Client) accountingSvc.ServiceExecutor {
return &morphExecutor{
client: client,
}
}
func (s *morphExecutor) Balance(ctx context.Context, body *accounting.BalanceRequestBody) (*accounting.BalanceResponseBody, error) {
amount, err := s.client.BalanceOf(owner.NewIDFromV2(body.GetOwnerID()))
if err != nil {
return nil, err
}
balancePrecision, err := s.client.Decimals()
if err != nil {
return nil, err
}
dec := new(accounting.Decimal)
dec.SetValue(amount.Int64())
dec.SetPrecision(balancePrecision)
res := new(accounting.BalanceResponseBody)
res.SetBalance(dec)
return res, nil
}