github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/api/coin/update.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) UpdateCoin(ctx context.Context, in *npool.UpdateCoinRequest) (*npool.UpdateCoinResponse, error) { 15 req := in.GetInfo() 16 handler, err := coin1.NewHandler( 17 ctx, 18 coin1.WithID(req.ID, true), 19 coin1.WithName(req.Name, false), 20 coin1.WithUnit(req.Unit, false), 21 coin1.WithLogo(req.Logo, false), 22 coin1.WithReservedAmount(req.ReservedAmount, false), 23 coin1.WithHomePage(req.HomePage, false), 24 coin1.WithSpecs(req.Specs, false), 25 // TODO: this should be get from chain type 26 coin1.WithFeeCoinTypeID(req.FeeCoinTypeID, false), 27 coin1.WithWithdrawFeeByStableUSD(req.WithdrawFeeByStableUSD, false), 28 coin1.WithWithdrawFeeAmount(req.WithdrawFeeAmount, false), 29 coin1.WithCollectFeeAmount(req.CollectFeeAmount, false), 30 coin1.WithHotWalletFeeAmount(req.HotWalletFeeAmount, false), 31 coin1.WithLowFeeAmount(req.LowFeeAmount, false), 32 coin1.WithHotLowFeeAmount(req.HotLowFeeAmount, false), 33 coin1.WithHotWalletFeeAmount(req.HotWalletFeeAmount, false), 34 coin1.WithHotWalletAccountAmount(req.HotWalletAccountAmount, false), 35 coin1.WithPaymentAccountCollectAmount(req.PaymentAccountCollectAmount, false), 36 coin1.WithLeastTransferAmount(req.LeastTransferAmount, false), 37 coin1.WithPresale(req.Presale, false), 38 coin1.WithForPay(req.ForPay, false), 39 coin1.WithDisabled(req.Disabled, false), 40 // TODO: this should be in create from register coin 41 coin1.WithStableUSD(req.StableUSD, false), 42 // TODO: this should be in create from register coin 43 coin1.WithNeedMemo(req.NeedMemo, false), 44 coin1.WithRefreshCurrency(req.RefreshCurrency, false), 45 coin1.WithCheckNewAddressBalance(req.CheckNewAddressBalance, false), 46 ) 47 if err != nil { 48 logger.Sugar().Errorw( 49 "UpdateCoin", 50 "In", in, 51 "Error", err, 52 ) 53 return &npool.UpdateCoinResponse{}, status.Error(codes.InvalidArgument, err.Error()) 54 } 55 56 info, err := handler.UpdateCoin(ctx) 57 if err != nil { 58 logger.Sugar().Errorw( 59 "UpdateCoin", 60 "In", in, 61 "Error", err, 62 ) 63 return &npool.UpdateCoinResponse{}, status.Error(codes.Internal, err.Error()) 64 } 65 66 return &npool.UpdateCoinResponse{ 67 Info: info, 68 }, nil 69 }