forked from TrueCloudLab/frostfs-node
[#1084] accounting: Keep balance precision from contract
Do not convert balance response of Balance contract to Fixed8. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
dbb04d78b9
commit
87a45983a1
1 changed files with 2 additions and 12 deletions
|
@ -6,7 +6,6 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/accounting"
|
"github.com/nspcc-dev/neofs-api-go/v2/accounting"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance/wrapper"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance/wrapper"
|
||||||
accountingSvc "github.com/nspcc-dev/neofs-node/pkg/services/accounting"
|
accountingSvc "github.com/nspcc-dev/neofs-node/pkg/services/accounting"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/util/precision"
|
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,8 +13,6 @@ type morphExecutor struct {
|
||||||
client *wrapper.Wrapper
|
client *wrapper.Wrapper
|
||||||
}
|
}
|
||||||
|
|
||||||
const fixed8Precision = 8
|
|
||||||
|
|
||||||
func NewExecutor(client *wrapper.Wrapper) accountingSvc.ServiceExecutor {
|
func NewExecutor(client *wrapper.Wrapper) accountingSvc.ServiceExecutor {
|
||||||
return &morphExecutor{
|
return &morphExecutor{
|
||||||
client: client,
|
client: client,
|
||||||
|
@ -33,16 +30,9 @@ func (s *morphExecutor) Balance(ctx context.Context, body *accounting.BalanceReq
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert amount to Fixed8 precision. This way it will definitely fit
|
|
||||||
// int64 value.
|
|
||||||
// Max Fixed8 decimal integer value that fit into int64: 92 233 720 368.
|
|
||||||
// Max Fixed12 decimal integer value that fit into int64: 9 223 372.
|
|
||||||
// Max Fixed16 decimal integer value that fit into int64: 922.
|
|
||||||
fixed8Amount := precision.Convert(balancePrecision, fixed8Precision, amount)
|
|
||||||
|
|
||||||
dec := new(accounting.Decimal)
|
dec := new(accounting.Decimal)
|
||||||
dec.SetValue(fixed8Amount.Int64())
|
dec.SetValue(amount.Int64())
|
||||||
dec.SetPrecision(fixed8Precision)
|
dec.SetPrecision(balancePrecision)
|
||||||
|
|
||||||
res := new(accounting.BalanceResponseBody)
|
res := new(accounting.BalanceResponseBody)
|
||||||
res.SetBalance(dec)
|
res.SetBalance(dec)
|
||||||
|
|
Loading…
Reference in a new issue