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

     1  package coin
     2  
     3  import (
     4  	"context"
     5  
     6  	coin1 "github.com/NpoolPlatform/chain-middleware/pkg/mw/coin"
     7  	"github.com/NpoolPlatform/go-service-framework/pkg/logger"
     8  	npool "github.com/NpoolPlatform/message/npool/chain/mw/v1/coin"
     9  
    10  	"google.golang.org/grpc/codes"
    11  	"google.golang.org/grpc/status"
    12  )
    13  
    14  func (s *Server) CreateCoin(ctx context.Context, in *npool.CreateCoinRequest) (*npool.CreateCoinResponse, error) {
    15  	req := in.GetInfo()
    16  	handler, err := coin1.NewHandler(
    17  		ctx,
    18  		coin1.WithName(req.Name, true),
    19  		coin1.WithUnit(req.Unit, true),
    20  		coin1.WithENV(req.ENV, true),
    21  		coin1.WithChainType(req.ChainType, true),
    22  		coin1.WithChainNativeUnit(req.ChainNativeUnit, true),
    23  		coin1.WithChainAtomicUnit(req.ChainAtomicUnit, true),
    24  		coin1.WithChainUnitExp(req.ChainUnitExp, true),
    25  		coin1.WithGasType(req.GasType, true),
    26  		coin1.WithChainID(req.ChainID, true),
    27  		coin1.WithChainNickname(req.ChainNickname, true),
    28  		coin1.WithChainNativeCoinName(req.ChainNativeCoinName, true),
    29  	)
    30  	if err != nil {
    31  		logger.Sugar().Errorw(
    32  			"CreateCoin",
    33  			"In", in,
    34  			"Error", err,
    35  		)
    36  		return &npool.CreateCoinResponse{}, status.Error(codes.InvalidArgument, err.Error())
    37  	}
    38  
    39  	info, err := handler.CreateCoin(ctx)
    40  	if err != nil {
    41  		logger.Sugar().Errorw(
    42  			"CreateCoin",
    43  			"In", in,
    44  			"Error", err,
    45  		)
    46  		return &npool.CreateCoinResponse{}, status.Error(codes.Internal, err.Error())
    47  	}
    48  
    49  	return &npool.CreateCoinResponse{
    50  		Info: info,
    51  	}, nil
    52  }