github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/api/app/coin/create.go (about) 1 package appcoin 2 3 import ( 4 "context" 5 6 appcoin1 "github.com/NpoolPlatform/chain-middleware/pkg/mw/app/coin" 7 npool "github.com/NpoolPlatform/message/npool/chain/mw/v1/app/coin" 8 9 "github.com/NpoolPlatform/go-service-framework/pkg/logger" 10 11 "google.golang.org/grpc/codes" 12 "google.golang.org/grpc/status" 13 ) 14 15 func (s *Server) CreateCoin(ctx context.Context, in *npool.CreateCoinRequest) (*npool.CreateCoinResponse, error) { 16 req := in.GetInfo() 17 if req == nil { 18 logger.Sugar().Errorw( 19 "CreateCoin", 20 "In", in, 21 ) 22 return &npool.CreateCoinResponse{}, status.Error(codes.InvalidArgument, "Info is empty") 23 } 24 handler, err := appcoin1.NewHandler( 25 ctx, 26 appcoin1.WithID(req.ID, false), 27 appcoin1.WithEntID(req.EntID, false), 28 appcoin1.WithAppID(req.AppID, true), 29 appcoin1.WithCoinTypeID(req.CoinTypeID, true), 30 appcoin1.WithName(req.Name, false), 31 appcoin1.WithDisplayNames(req.DisplayNames, false), 32 appcoin1.WithLogo(req.Logo, false), 33 appcoin1.WithForPay(req.ForPay, false), 34 appcoin1.WithProductPage(req.ProductPage, false), 35 appcoin1.WithWithdrawAutoReviewAmount(req.WithdrawAutoReviewAmount, false), 36 appcoin1.WithDailyRewardAmount(req.DailyRewardAmount, false), 37 appcoin1.WithDisplay(req.Display, false), 38 appcoin1.WithDisplayIndex(req.DisplayIndex, false), 39 appcoin1.WithMaxAmountPerWithdraw(req.MaxAmountPerWithdraw, false), 40 appcoin1.WithMarketValue(req.MarketValue, false), 41 appcoin1.WithSettlePercent(req.SettlePercent, false), 42 appcoin1.WithSettleTips(req.SettleTips, false), 43 appcoin1.WithSetter(req.Setter, false), 44 ) 45 if err != nil { 46 logger.Sugar().Errorw( 47 "CreateCoin", 48 "In", in, 49 "Error", err, 50 ) 51 return &npool.CreateCoinResponse{}, status.Error(codes.InvalidArgument, err.Error()) 52 } 53 54 info, err := handler.CreateCoin(ctx) 55 if err != nil { 56 logger.Sugar().Errorw( 57 "CreateCoin", 58 "In", in, 59 "Error", err, 60 ) 61 return &npool.CreateCoinResponse{}, status.Error(codes.Internal, err.Error()) 62 } 63 64 return &npool.CreateCoinResponse{ 65 Info: info, 66 }, nil 67 }