forked from TrueCloudLab/frostfs-node
[#16] Fix balanceOf wrapper for api request
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
58cb90966a
commit
80f10dab7b
4 changed files with 36 additions and 27 deletions
|
@ -3,49 +3,41 @@ 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"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance/wrapper"
|
||||
accountingSvc "github.com/nspcc-dev/neofs-node/pkg/services/accounting"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type morphExecutor struct {
|
||||
// TODO: use client wrapper
|
||||
client *balance.Client
|
||||
client *wrapper.Wrapper
|
||||
}
|
||||
|
||||
func NewExecutor(client *balance.Client) accountingSvc.ServiceExecutor {
|
||||
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 := body.GetOwnerID()
|
||||
|
||||
idBytes, err := id.StableMarshal(nil)
|
||||
id, err := owner.IDFromV2(body.GetOwnerID())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not marshal wallet owner ID")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
argsBalance := balance.GetBalanceOfArgs{}
|
||||
argsBalance.SetWallet(idBytes)
|
||||
|
||||
vBalance, err := s.client.BalanceOf(argsBalance)
|
||||
amount, err := s.client.BalanceOf(id)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not call BalanceOf method")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
argsDecimals := balance.DecimalsArgs{}
|
||||
|
||||
vDecimals, err := s.client.Decimals(argsDecimals)
|
||||
precision, err := s.client.Decimals()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not call decimals method")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dec := new(accounting.Decimal)
|
||||
dec.SetValue(vBalance.Amount())
|
||||
dec.SetPrecision(uint32(vDecimals.Decimals()))
|
||||
dec.SetValue(amount)
|
||||
dec.SetPrecision(precision)
|
||||
|
||||
res := new(accounting.BalanceResponseBody)
|
||||
res.SetBalance(dec)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue