diff --git a/go.mod b/go.mod index 48ee1f4..b1c7920 100644 --- a/go.mod +++ b/go.mod @@ -1,20 +1,32 @@ module github.com/changtong1996/djzh -go 1.13 + +go 1.14 require ( + github.com/99designs/keyring v1.1.4 // indirect github.com/btcsuite/btcd v0.0.0-20190807005414-4063feeff79a // indirect - github.com/cosmos/cosmos-sdk v0.38.0 - github.com/golang/mock v1.3.1 // indirect + github.com/cosmos/cosmos-sdk v0.38.3 + github.com/gibson042/canonicaljson-go v1.0.3 // indirect + github.com/golang/mock v1.4.3 // indirect + github.com/gorilla/handlers v1.4.2 // indirect + github.com/gorilla/mux v1.7.4 github.com/onsi/ginkgo v1.8.0 // indirect github.com/onsi/gomega v1.5.0 // indirect - github.com/prometheus/client_golang v1.1.0 // indirect + github.com/otiai10/copy v1.1.1 + github.com/pelletier/go-toml v1.7.0 // indirect + github.com/pkg/errors v0.9.1 + github.com/rakyll/statik v0.1.7 // indirect github.com/rcrowley/go-metrics v0.0.0-20190706150252-9beb055b7962 // indirect + github.com/regen-network/cosmos-proto v0.1.1-0.20200213154359-02baa11ea7c2 // indirect + github.com/snikch/goodman v0.0.0-20171125024755-10e37e294daa github.com/spf13/afero v1.2.2 // indirect - github.com/spf13/cobra v0.0.5 - github.com/spf13/viper v1.6.2 + github.com/spf13/cobra v0.0.7 + github.com/spf13/viper v1.6.3 + github.com/stretchr/testify v1.5.1 github.com/tendermint/go-amino v0.15.1 - github.com/tendermint/tendermint v0.33.0 - github.com/tendermint/tm-db v0.4.0 + github.com/tendermint/iavl v0.13.3 // indirect + github.com/tendermint/tendermint v0.33.3 + github.com/tendermint/tm-db v0.5.1 golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 // indirect - golang.org/x/text v0.3.2 // indirect + google.golang.org/protobuf v1.20.1 // indirect ) \ No newline at end of file diff --git a/x/djzh/client/rest/tx.go b/x/djzh/client/rest/tx.go index c187745..9ac5cd8 100644 --- a/x/djzh/client/rest/tx.go +++ b/x/djzh/client/rest/tx.go @@ -26,7 +26,7 @@ type CreateArticleReq struct { Tid string `json:"tid"` Uid string `json:"uid"` A_timestamp string `json:"a_timestamp"` - Reward sdk.Coins `json:"reward"` // reward of the article + Reward string `json:"reward"` // reward of the article } func CreateArticleHandler(cliCtx context.CLIContext) http.HandlerFunc{ @@ -49,8 +49,13 @@ func CreateArticleHandler(cliCtx context.CLIContext) http.HandlerFunc{ return } + coins, err := sdk.ParseCoins(req.Reward) + if err != nil { + rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) + return + } // create the message - msg := types.NewMsgCreateArticle(addr, req.A_text, req.A_title, req.Tag, req.Article_id, req.Tid, req.Uid, req.A_timestamp, req.Reward) + msg := types.NewMsgCreateArticle(addr, req.A_text, req.A_title, req.Tag, req.Article_id, req.Tid, req.Uid, req.A_timestamp, coins) err = msg.ValidateBasic() if err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) @@ -72,7 +77,7 @@ type CreateCommentReq struct { Uid string `json:"uid"` // id of the user C_timestamp string `json:"c_timestamp"` // timestamp of the comment C_text string `json:"c_text"` // context of the comment - Reward sdk.Coins `json:"reward"` + Reward string `json:"reward"` } func CreateCommentHandler(cliCtx context.CLIContext) http.HandlerFunc { @@ -95,8 +100,14 @@ func CreateCommentHandler(cliCtx context.CLIContext) http.HandlerFunc { return } + coins, err := sdk.ParseCoins(req.Reward) + if err != nil { + rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) + return + } + // create the message - msg := types.NewMsgCreateComment(addr, req.Comment_id, req.Article_id, req.Tid, req.Uid, req.C_timestamp, req.C_text, req.Reward) + msg := types.NewMsgCreateComment(addr, req.Comment_id, req.Article_id, req.Tid, req.Uid, req.C_timestamp, req.C_text, coins) err = msg.ValidateBasic() if err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) @@ -119,8 +130,7 @@ type CreateReturnVisitReq struct { Rv_timestamp string `json:"rv_timestamp"` Rv_text string `json:"rv_text"` Flag string `json:"flag"` - Reward sdk.Coins `json:"reward"` // reward of the article - + Reward string `json:"reward"` // reward of the article } @@ -144,8 +154,14 @@ func CreateReturnVisitHandler(cliCtx context.CLIContext) http.HandlerFunc { return } + coins, err := sdk.ParseCoins(req.Reward) + if err != nil { + rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) + return + } + // create the message - msg := types.NewMsgCreateReturnVisit(addr, req.Return_visit_id, req.Article_id, req.Tid, req.Uid, req.Rv_timestamp, req.Rv_text, req.Flag, req.Reward) + msg := types.NewMsgCreateReturnVisit(addr, req.Return_visit_id, req.Article_id, req.Tid, req.Uid, req.Rv_timestamp, req.Rv_text, req.Flag, coins) err = msg.ValidateBasic() if err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) diff --git a/x/djzh/handler.go b/x/djzh/handler.go index d1c2113..2a805a0 100644 --- a/x/djzh/handler.go +++ b/x/djzh/handler.go @@ -100,6 +100,7 @@ func handleMsgCreateComment(ctx sdk.Context, k Keeper, msg MsgCreateComment) (*s if err == nil { return nil, sdkerrors.Wrap(err, "Comment with that id already exists") } + //need to modify moduleAcct := sdk.AccAddress(crypto.AddressHash([]byte(types.ModuleName))) sdkError := k.CoinKeeper.SendCoins(ctx, comment.Creator, moduleAcct, comment.Reward) if sdkError != nil {