forked from TrueCloudLab/frostfs-node
6f50fefbea
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
41 lines
961 B
Go
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
|
|
}
|