2020-08-14 16:00:16 +00:00
|
|
|
package accounting
|
|
|
|
|
|
|
|
import (
|
|
|
|
accounting "github.com/nspcc-dev/neofs-api-go/v2/accounting/grpc"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
2021-03-12 12:57:23 +00:00
|
|
|
refsGRPC "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc"
|
2021-11-16 17:30:55 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/rpc/grpc"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/rpc/message"
|
2020-08-14 16:00:16 +00:00
|
|
|
)
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (b *BalanceRequestBody) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *accounting.BalanceRequest_Body
|
2020-08-14 16:00:16 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if b != nil {
|
|
|
|
m = new(accounting.BalanceRequest_Body)
|
2020-08-14 16:00:16 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetOwnerId(b.ownerID.ToGRPCMessage().(*refsGRPC.OwnerID))
|
|
|
|
}
|
2020-08-14 16:00:16 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (b *BalanceRequestBody) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*accounting.BalanceRequest_Body)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-14 16:00:16 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2020-08-14 16:00:16 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
ownerID := v.GetOwnerId()
|
|
|
|
if ownerID == nil {
|
|
|
|
b.ownerID = nil
|
|
|
|
} else {
|
|
|
|
if b.ownerID == nil {
|
|
|
|
b.ownerID = new(refs.OwnerID)
|
|
|
|
}
|
2020-08-14 16:00:16 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = b.ownerID.FromGRPCMessage(ownerID)
|
2020-08-14 16:00:16 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *BalanceRequest) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *accounting.BalanceRequest
|
2020-08-14 16:00:16 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if b != nil {
|
|
|
|
m = new(accounting.BalanceRequest)
|
2020-08-14 16:00:16 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetBody(b.body.ToGRPCMessage().(*accounting.BalanceRequest_Body))
|
|
|
|
b.RequestHeaders.ToMessage(m)
|
|
|
|
}
|
2020-08-14 16:00:16 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (b *BalanceRequest) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*accounting.BalanceRequest)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-14 16:00:16 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2020-08-14 16:00:16 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
body := v.GetBody()
|
|
|
|
if body == nil {
|
|
|
|
b.body = nil
|
|
|
|
} else {
|
|
|
|
if b.body == nil {
|
|
|
|
b.body = new(BalanceRequestBody)
|
|
|
|
}
|
2020-08-14 16:00:16 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = b.body.FromGRPCMessage(body)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-14 16:00:16 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return b.RequestHeaders.FromMessage(v)
|
2020-08-14 16:00:16 +00:00
|
|
|
}
|
2020-08-17 10:29:21 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (d *Decimal) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *accounting.Decimal
|
2020-08-17 10:29:21 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if d != nil {
|
|
|
|
m = new(accounting.Decimal)
|
2020-08-17 10:29:21 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetValue(d.val)
|
|
|
|
m.SetPrecision(d.prec)
|
|
|
|
}
|
2020-08-17 10:29:21 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (d *Decimal) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*accounting.Decimal)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-17 10:29:21 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
d.val = v.GetValue()
|
|
|
|
d.prec = v.GetPrecision()
|
2020-08-17 10:29:21 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
2020-08-17 10:29:21 +00:00
|
|
|
}
|
2020-08-17 10:39:46 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (br *BalanceResponseBody) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *accounting.BalanceResponse_Body
|
2020-08-17 10:39:46 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if br != nil {
|
|
|
|
m = new(accounting.BalanceResponse_Body)
|
2020-08-17 10:39:46 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetBalance(br.bal.ToGRPCMessage().(*accounting.Decimal))
|
|
|
|
}
|
2020-08-17 10:39:46 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (br *BalanceResponseBody) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*accounting.BalanceResponse_Body)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-17 10:39:46 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2020-08-17 10:39:46 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
bal := v.GetBalance()
|
|
|
|
if bal == nil {
|
|
|
|
br.bal = nil
|
|
|
|
} else {
|
|
|
|
if br.bal == nil {
|
|
|
|
br.bal = new(Decimal)
|
|
|
|
}
|
2020-08-17 10:39:46 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = br.bal.FromGRPCMessage(bal)
|
2020-08-17 10:39:46 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (br *BalanceResponse) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *accounting.BalanceResponse
|
2020-08-17 10:39:46 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if br != nil {
|
|
|
|
m = new(accounting.BalanceResponse)
|
2020-08-17 10:39:46 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetBody(br.body.ToGRPCMessage().(*accounting.BalanceResponse_Body))
|
|
|
|
br.ResponseHeaders.ToMessage(m)
|
|
|
|
}
|
2020-08-17 10:39:46 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (br *BalanceResponse) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*accounting.BalanceResponse)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-17 10:39:46 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2020-08-17 10:39:46 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
body := v.GetBody()
|
|
|
|
if body == nil {
|
|
|
|
br.body = nil
|
|
|
|
} else {
|
|
|
|
if br.body == nil {
|
|
|
|
br.body = new(BalanceResponseBody)
|
|
|
|
}
|
2020-08-17 10:39:46 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = br.body.FromGRPCMessage(body)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-17 10:39:46 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return br.ResponseHeaders.FromMessage(v)
|
2020-08-17 10:39:46 +00:00
|
|
|
}
|