/
getReputation.go
executable file
·43 lines (34 loc) · 1.07 KB
/
getReputation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package rest
import (
"fmt"
"net/http"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/gorilla/mux"
"github.com/commitHub/commitBlockchain/modules/reputation/internal/types"
)
func QueryReputationRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
vars := mux.Vars(r)
cliCtx := cliCtx
bech32addr := vars["address"]
if bech32addr == "" {
w.WriteHeader(http.StatusBadRequest)
return
}
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s/%s", types.QuerierRoute, "reputationQuery", bech32addr), nil)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError,
fmt.Sprintf("couldn't query account. Error: %s", err.Error()))
return
}
if len(res) == 0 {
w.WriteHeader(http.StatusNoContent)
return
}
var reputation types.AccountReputation
cliCtx.Codec.MustUnmarshalJSON(res, &reputation)
rest.PostProcessResponse(w, cliCtx, reputation)
}
}