v2/accounting: Implement Decimal uni-structure

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-08-17 13:29:21 +03:00 committed by Stanislav Bogatyrev
parent 890d8291e7
commit 9df86935f5
2 changed files with 60 additions and 0 deletions

View file

@ -17,6 +17,12 @@ type BalanceRequest struct {
verifyHeader *service.RequestVerificationHeader
}
type Decimal struct {
val int64
prec uint32
}
func (b *BalanceRequestBody) GetOwnerID() *refs.OwnerID {
if b != nil {
return b.ownerID
@ -88,3 +94,31 @@ func (b *BalanceRequest) SetRequestVerificationHeader(v *service.RequestVerifica
b.verifyHeader = v
}
}
func (d *Decimal) GetValue() int64 {
if d != nil {
return d.val
}
return 0
}
func (d *Decimal) SetValue(v int64) {
if d != nil {
d.val = v
}
}
func (d *Decimal) GetPrecision() uint32 {
if d != nil {
return d.prec
}
return 0
}
func (d *Decimal) SetPrecision(v uint32) {
if d != nil {
d.prec = v
}
}

View file

@ -65,3 +65,29 @@ func BalanceRequestFromGRPCMessage(m *accounting.BalanceRequest) *BalanceRequest
return b
}
func DecimalToGRPCMessage(d *Decimal) *accounting.Decimal {
if d == nil {
return nil
}
m := new(accounting.Decimal)
m.SetValue(d.GetValue())
m.SetPrecision(d.GetPrecision())
return m
}
func DecimalFromGRPCMessage(m *accounting.Decimal) *Decimal {
if m == nil {
return nil
}
d := new(Decimal)
d.SetValue(m.GetValue())
d.SetPrecision(m.GetPrecision())
return d
}