-
Notifications
You must be signed in to change notification settings - Fork 2
/
tx.go
37 lines (34 loc) · 1.17 KB
/
tx.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
package rest
import (
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
"github.com/csmuller/up-voting-system/crypto"
"github.com/csmuller/up-voting-system/pbb/internal/types"
"net/http"
)
type putVoterCredentialsReq struct {
BaseReq rest.BaseReq `json:"base_req"`
Name string `json:"tx_name"` // name of the tx
Credential crypto.Int `json:"credential"`
}
func putVoterCredentialsHandler(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req putVoterCredentialsReq
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
rest.WriteErrorResponse(w, http.StatusBadRequest, "failed to parse request")
return
}
baseReq := req.BaseReq.Sanitize()
if !baseReq.ValidateBasic(w) {
return
}
msg := types.NewMsgPutVoterCredential(req.Credential, cliCtx.GetFromAddress())
if err := msg.ValidateBasic(); err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
utils.WriteGenerateStdTxResponse(w, cliCtx, baseReq, []sdk.Msg{msg})
}
}