2020-08-22 10:18:50 +00:00
|
|
|
package accounting
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/accounting"
|
|
|
|
accountingGRPC "github.com/nspcc-dev/neofs-api-go/v2/accounting/grpc"
|
2021-03-15 10:53:08 +00:00
|
|
|
accountingsvc "github.com/nspcc-dev/neofs-node/pkg/services/accounting"
|
2020-08-22 10:18:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Server wraps NeoFS API Accounting service and
|
|
|
|
// provides gRPC Accounting service server interface.
|
|
|
|
type Server struct {
|
2021-03-15 10:53:08 +00:00
|
|
|
srv accountingsvc.Server
|
2020-08-22 10:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// New creates, initializes and returns Server instance.
|
2021-03-15 10:53:08 +00:00
|
|
|
func New(c accountingsvc.Server) *Server {
|
2020-08-22 10:18:50 +00:00
|
|
|
return &Server{
|
|
|
|
srv: c,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Balance converts gRPC BalanceRequest message and passes it to internal Accounting service.
|
|
|
|
func (s *Server) Balance(ctx context.Context, req *accountingGRPC.BalanceRequest) (*accountingGRPC.BalanceResponse, error) {
|
2021-03-15 10:59:28 +00:00
|
|
|
balReq := new(accounting.BalanceRequest)
|
|
|
|
if err := balReq.FromGRPCMessage(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.srv.Balance(ctx, balReq)
|
2020-08-22 10:18:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-03-15 10:59:28 +00:00
|
|
|
return resp.ToGRPCMessage().(*accountingGRPC.BalanceResponse), nil
|
2020-08-22 10:18:50 +00:00
|
|
|
}
|