github.com/Finschia/finschia-sdk@v0.48.1/x/distribution/keeper/msg_server.go (about) 1 package keeper 2 3 import ( 4 "context" 5 6 "github.com/armon/go-metrics" 7 8 "github.com/Finschia/finschia-sdk/telemetry" 9 sdk "github.com/Finschia/finschia-sdk/types" 10 "github.com/Finschia/finschia-sdk/x/distribution/types" 11 ) 12 13 type msgServer struct { 14 Keeper 15 } 16 17 // NewMsgServerImpl returns an implementation of the distribution MsgServer interface 18 // for the provided Keeper. 19 func NewMsgServerImpl(keeper Keeper) types.MsgServer { 20 return &msgServer{Keeper: keeper} 21 } 22 23 var _ types.MsgServer = msgServer{} 24 25 func (k msgServer) SetWithdrawAddress(goCtx context.Context, msg *types.MsgSetWithdrawAddress) (*types.MsgSetWithdrawAddressResponse, error) { 26 ctx := sdk.UnwrapSDKContext(goCtx) 27 28 delegatorAddress, err := sdk.AccAddressFromBech32(msg.DelegatorAddress) 29 if err != nil { 30 return nil, err 31 } 32 withdrawAddress, err := sdk.AccAddressFromBech32(msg.WithdrawAddress) 33 if err != nil { 34 return nil, err 35 } 36 err = k.SetWithdrawAddr(ctx, delegatorAddress, withdrawAddress) 37 if err != nil { 38 return nil, err 39 } 40 41 return &types.MsgSetWithdrawAddressResponse{}, nil 42 } 43 44 func (k msgServer) WithdrawDelegatorReward(goCtx context.Context, msg *types.MsgWithdrawDelegatorReward) (*types.MsgWithdrawDelegatorRewardResponse, error) { 45 ctx := sdk.UnwrapSDKContext(goCtx) 46 47 valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) 48 if err != nil { 49 return nil, err 50 } 51 delegatorAddress, err := sdk.AccAddressFromBech32(msg.DelegatorAddress) 52 if err != nil { 53 return nil, err 54 } 55 amount, err := k.WithdrawDelegationRewards(ctx, delegatorAddress, valAddr) 56 if err != nil { 57 return nil, err 58 } 59 60 defer func() { 61 for _, a := range amount { 62 if a.Amount.IsInt64() { 63 telemetry.SetGaugeWithLabels( 64 []string{"tx", "msg", "withdraw_reward"}, 65 float32(a.Amount.Int64()), 66 []metrics.Label{telemetry.NewLabel("denom", a.Denom)}, 67 ) 68 } 69 } 70 }() 71 72 return &types.MsgWithdrawDelegatorRewardResponse{}, nil 73 } 74 75 func (k msgServer) WithdrawValidatorCommission(goCtx context.Context, msg *types.MsgWithdrawValidatorCommission) (*types.MsgWithdrawValidatorCommissionResponse, error) { 76 ctx := sdk.UnwrapSDKContext(goCtx) 77 78 valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) 79 if err != nil { 80 return nil, err 81 } 82 amount, err := k.Keeper.WithdrawValidatorCommission(ctx, valAddr) 83 if err != nil { 84 return nil, err 85 } 86 87 defer func() { 88 for _, a := range amount { 89 if a.Amount.IsInt64() { 90 telemetry.SetGaugeWithLabels( 91 []string{"tx", "msg", "withdraw_commission"}, 92 float32(a.Amount.Int64()), 93 []metrics.Label{telemetry.NewLabel("denom", a.Denom)}, 94 ) 95 } 96 } 97 }() 98 99 return &types.MsgWithdrawValidatorCommissionResponse{}, nil 100 } 101 102 func (k msgServer) FundCommunityPool(goCtx context.Context, msg *types.MsgFundCommunityPool) (*types.MsgFundCommunityPoolResponse, error) { 103 ctx := sdk.UnwrapSDKContext(goCtx) 104 105 depositer, err := sdk.AccAddressFromBech32(msg.Depositor) 106 if err != nil { 107 return nil, err 108 } 109 if err := k.Keeper.FundCommunityPool(ctx, msg.Amount, depositer); err != nil { 110 return nil, err 111 } 112 113 return &types.MsgFundCommunityPoolResponse{}, nil 114 }