From 9df86935f5c9a1281e21d65074b0c36481159ea0 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 17 Aug 2020 13:29:21 +0300 Subject: [PATCH] v2/accounting: Implement Decimal uni-structure Signed-off-by: Leonard Lyubich --- v2/accounting/accounting.go | 34 ++++++++++++++++++++++++++++++++++ v2/accounting/convert.go | 26 ++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/v2/accounting/accounting.go b/v2/accounting/accounting.go index a49f79b..3aa2410 100644 --- a/v2/accounting/accounting.go +++ b/v2/accounting/accounting.go @@ -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 + } +} diff --git a/v2/accounting/convert.go b/v2/accounting/convert.go index 74d96c5..8cc2936 100644 --- a/v2/accounting/convert.go +++ b/v2/accounting/convert.go @@ -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 +}