github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/api/coin/exist.go (about)

     1  //nolint:nolintlint,dupl
     2  package coin
     3  
     4  import (
     5  	"context"
     6  
     7  	coin1 "github.com/NpoolPlatform/chain-middleware/pkg/mw/coin"
     8  	"github.com/NpoolPlatform/go-service-framework/pkg/logger"
     9  	npool "github.com/NpoolPlatform/message/npool/chain/mw/v1/coin"
    10  
    11  	"google.golang.org/grpc/codes"
    12  	"google.golang.org/grpc/status"
    13  )
    14  
    15  func (s *Server) ExistCoin(ctx context.Context, in *npool.ExistCoinRequest) (*npool.ExistCoinResponse, error) {
    16  	handler, err := coin1.NewHandler(
    17  		ctx,
    18  		coin1.WithEntID(&in.EntID, true),
    19  	)
    20  	if err != nil {
    21  		logger.Sugar().Errorw(
    22  			"ExistCoin",
    23  			"In", in,
    24  			"Error", err,
    25  		)
    26  		return &npool.ExistCoinResponse{}, status.Error(codes.InvalidArgument, err.Error())
    27  	}
    28  
    29  	info, err := handler.ExistCoin(ctx)
    30  	if err != nil {
    31  		logger.Sugar().Errorw(
    32  			"ExistCoin",
    33  			"In", in,
    34  			"Error", err,
    35  		)
    36  		return &npool.ExistCoinResponse{}, status.Error(codes.Internal, err.Error())
    37  	}
    38  
    39  	return &npool.ExistCoinResponse{
    40  		Info: info,
    41  	}, nil
    42  }
    43  
    44  func (s *Server) ExistCoinConds(ctx context.Context, in *npool.ExistCoinCondsRequest) (*npool.ExistCoinCondsResponse, error) {
    45  	handler, err := coin1.NewHandler(
    46  		ctx,
    47  		coin1.WithConds(in.GetConds()),
    48  	)
    49  	if err != nil {
    50  		logger.Sugar().Errorw(
    51  			"ExistCoinConds",
    52  			"In", in,
    53  			"Error", err,
    54  		)
    55  		return &npool.ExistCoinCondsResponse{}, status.Error(codes.InvalidArgument, err.Error())
    56  	}
    57  
    58  	info, err := handler.ExistCoinConds(ctx)
    59  	if err != nil {
    60  		logger.Sugar().Errorw(
    61  			"ExistCoinConds",
    62  			"In", in,
    63  			"Error", err,
    64  		)
    65  		return &npool.ExistCoinCondsResponse{}, status.Error(codes.Internal, err.Error())
    66  	}
    67  
    68  	return &npool.ExistCoinCondsResponse{
    69  		Info: info,
    70  	}, nil
    71  }