Skip to content

Commit 6929767

Browse files
committed
Added the REST and CLI txs
1 parent d2569c7 commit 6929767

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

x/distribution/client/cli/tx.go

+33
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func GetTxCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
4646
GetCmdWithdrawRewards(cdc),
4747
GetCmdSetWithdrawAddr(cdc),
4848
GetCmdWithdrawAllRewards(cdc, storeKey),
49+
GetCmdFundCommunityPool(cdc),
4950
)...)
5051

5152
return distTxCmd
@@ -254,3 +255,35 @@ Where proposal.json contains:
254255

255256
return cmd
256257
}
258+
259+
// command to fund the community pool
260+
func GetCmdFundCommunityPool(cdc *codec.Codec) *cobra.Command {
261+
return &cobra.Command{
262+
Use: "fund-community-pool [amount]",
263+
Short: "funds the community pool with the specified amount",
264+
Long: strings.TrimSpace(
265+
fmt.Sprintf(`Funds the community pool with the specified amount
266+
267+
Example:
268+
$ %s tx fund-community-pool 100uatom --from mykey
269+
`,
270+
version.ClientName,
271+
),
272+
),
273+
Args: cobra.ExactArgs(1),
274+
RunE: func(cmd *cobra.Command, args []string) error {
275+
276+
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
277+
cliCtx := context.NewCLIContext().WithCodec(cdc)
278+
279+
depositorAddr := cliCtx.GetFromAddress()
280+
amount, err := sdk.ParseCoins(args[0])
281+
if err != nil {
282+
return err
283+
}
284+
285+
msg := types.NewMsgDepositIntoCommunityPool(amount, depositorAddr)
286+
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
287+
},
288+
}
289+
}

x/distribution/client/rest/tx.go

+35
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router, queryRoute strin
3939
withdrawValidatorRewardsHandlerFn(cliCtx),
4040
).Methods("POST")
4141

42+
// Fund the community pool
43+
r.HandleFunc(
44+
"/distribution/community_pool",
45+
withdrawValidatorRewardsHandlerFn(cliCtx),
46+
).Methods("POST")
47+
4248
}
4349

4450
type (
@@ -50,6 +56,11 @@ type (
5056
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
5157
WithdrawAddress sdk.AccAddress `json:"withdraw_address" yaml:"withdraw_address"`
5258
}
59+
60+
fundCommunityPoolReq struct {
61+
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
62+
Amount sdk.Coins `json:"amount" yaml:"amount"`
63+
}
5364
)
5465

5566
// Withdraw delegator rewards
@@ -177,6 +188,30 @@ func withdrawValidatorRewardsHandlerFn(cliCtx context.CLIContext) http.HandlerFu
177188
}
178189
}
179190

191+
// Fund the community pool
192+
func fundCommunityPoolHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
193+
return func(w http.ResponseWriter, r *http.Request) {
194+
var req fundCommunityPoolReq
195+
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
196+
return
197+
}
198+
199+
req.BaseReq = req.BaseReq.Sanitize()
200+
if !req.BaseReq.ValidateBasic(w) {
201+
return
202+
}
203+
204+
fromAddr, err := sdk.AccAddressFromBech32(req.BaseReq.From)
205+
if err != nil {
206+
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
207+
return
208+
}
209+
210+
msg := types.NewMsgDepositIntoCommunityPool(req.Amount, fromAddr)
211+
utils.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
212+
}
213+
}
214+
180215
// Auxiliary
181216

182217
func checkDelegatorAddressVar(w http.ResponseWriter, r *http.Request) (sdk.AccAddress, bool) {

0 commit comments

Comments
 (0)