github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/x/mint/client/rest/query.go (about)

     1  package rest
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  
     7  	"github.com/gorilla/mux"
     8  
     9  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/context"
    10  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/rest"
    11  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/mint/internal/types"
    12  )
    13  
    14  func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) {
    15  	r.HandleFunc(
    16  		"/minting/parameters",
    17  		queryParamsHandlerFn(cliCtx),
    18  	).Methods("GET")
    19  
    20  	r.HandleFunc(
    21  		"/minting/inflation",
    22  		queryInflationHandlerFn(cliCtx),
    23  	).Methods("GET")
    24  
    25  	r.HandleFunc(
    26  		"/minting/annual-provisions",
    27  		queryAnnualProvisionsHandlerFn(cliCtx),
    28  	).Methods("GET")
    29  
    30  	r.HandleFunc(
    31  		"/minting/block-rewards",
    32  		queryBlockRewardsHandlerFn(cliCtx))
    33  }
    34  
    35  func queryParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
    36  	return func(w http.ResponseWriter, r *http.Request) {
    37  		route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParameters)
    38  
    39  		cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
    40  		if !ok {
    41  			return
    42  		}
    43  
    44  		res, height, err := cliCtx.QueryWithData(route, nil)
    45  		if err != nil {
    46  			rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
    47  			return
    48  		}
    49  
    50  		cliCtx = cliCtx.WithHeight(height)
    51  		rest.PostProcessResponse(w, cliCtx, res)
    52  	}
    53  }
    54  
    55  func queryInflationHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
    56  	return func(w http.ResponseWriter, r *http.Request) {
    57  		route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryInflation)
    58  
    59  		cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
    60  		if !ok {
    61  			return
    62  		}
    63  
    64  		res, height, err := cliCtx.QueryWithData(route, nil)
    65  		if err != nil {
    66  			rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
    67  			return
    68  		}
    69  
    70  		cliCtx = cliCtx.WithHeight(height)
    71  		rest.PostProcessResponse(w, cliCtx, res)
    72  	}
    73  }
    74  
    75  func queryAnnualProvisionsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
    76  	return func(w http.ResponseWriter, r *http.Request) {
    77  		route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryAnnualProvisions)
    78  
    79  		cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
    80  		if !ok {
    81  			return
    82  		}
    83  
    84  		res, height, err := cliCtx.QueryWithData(route, nil)
    85  		if err != nil {
    86  			rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
    87  			return
    88  		}
    89  
    90  		cliCtx = cliCtx.WithHeight(height)
    91  		rest.PostProcessResponse(w, cliCtx, res)
    92  	}
    93  }
    94  
    95  func queryBlockRewardsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
    96  	return func(w http.ResponseWriter, r *http.Request) {
    97  		route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryBlockRewards)
    98  
    99  		cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
   100  		if !ok {
   101  			return
   102  		}
   103  
   104  		res, height, err := cliCtx.QueryWithData(route, nil)
   105  		if err != nil {
   106  			rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
   107  			return
   108  		}
   109  
   110  		cliCtx = cliCtx.WithHeight(height)
   111  		rest.PostProcessResponse(w, cliCtx, res)
   112  	}
   113  }