frostfs-node/pkg/services/accounting/morph/executor.go
Alex Vanin 80f10dab7b [#16] Fix balanceOf wrapper for api request
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
2020-10-02 11:25:35 +03:00

46 lines
1,004 B
Go

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