Skip to content

Commit

Permalink
another major overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
girishramnani authored and antstalepresh committed May 27, 2020
1 parent 92870e3 commit 8f2921a
Show file tree
Hide file tree
Showing 34 changed files with 338 additions and 75 deletions.
2 changes: 1 addition & 1 deletion cmd/test/tx_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func GenTxWithMsg(messages []sdk.Msg) (auth.StdTx, error) {
cdc := GetAminoCdc()
cliCtx := context.NewCLIContext().WithCodec(cdc).WithAccountDecoder(cdc)

txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc)).WithChainID("pylons")
txBldr := authtxb.NewTxBuilderFromCLI(&bytes.Buffer{}).WithTxEncoder(utils.GetTxEncoder(cdc)).WithChainID("pylons")
if txBldr.SimulateAndExecute() {
txBldr, err = utils.EnrichWithGas(txBldr, cliCtx, messages)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/google/cel-go v0.3.2
github.com/google/uuid v1.1.1
github.com/gorilla/mux v1.7.4
github.com/micro/go-micro v1.18.0
github.com/spf13/cobra v0.0.6
github.com/spf13/viper v1.6.2
github.com/stretchr/testify v1.5.1
Expand Down
262 changes: 262 additions & 0 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion x/pylons/client/cli/query/get_cookbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func GetCookbook(queryRoute string, cdc *codec.Codec) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/get_cookbook/%s", queryRoute, args[0]), nil)
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/get_cookbook/%s", queryRoute, args[0]), nil)
if err != nil {
return fmt.Errorf(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion x/pylons/client/cli/query/get_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func GetExecution(queryRoute string, cdc *codec.Codec) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/get_execution/%s", queryRoute, args[0]), nil)
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/get_execution/%s", queryRoute, args[0]), nil)
if err != nil {
return fmt.Errorf(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion x/pylons/client/cli/query/get_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func GetItem(queryRoute string, cdc *codec.Codec) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/get_item/%s", queryRoute, args[0]), nil)
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/get_item/%s", queryRoute, args[0]), nil)
if err != nil {
return fmt.Errorf(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion x/pylons/client/cli/query/get_pylons_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func GetPylonsBalance(queryRoute string, cdc *codec.Codec) *cobra.Command {
return errors.New(err.Error())
}

res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/balance/%s", queryRoute, info.GetAddress()), nil)
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/balance/%s", queryRoute, info.GetAddress()), nil)
if err != nil {
return fmt.Errorf(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion x/pylons/client/cli/query/get_recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func GetRecipe(queryRoute string, cdc *codec.Codec) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/get_recipe/%s", queryRoute, args[0]), nil)
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/get_recipe/%s", queryRoute, args[0]), nil)
if err != nil {
return fmt.Errorf(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion x/pylons/client/cli/query/list_cookbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func ListCookbook(queryRoute string, cdc *codec.Codec) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/list_cookbook/%s", queryRoute, accAddr), nil)
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/list_cookbook/%s", queryRoute, accAddr), nil)
if err != nil {
return fmt.Errorf(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion x/pylons/client/cli/query/list_executions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func ListExecutions(queryRoute string, cdc *codec.Codec) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/list_executions/%s", queryRoute, accAddr), nil)
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/list_executions/%s", queryRoute, accAddr), nil)
if err != nil {
return fmt.Errorf(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion x/pylons/client/cli/query/list_items.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func ItemsBySender(queryRoute string, cdc *codec.Codec) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/items_by_sender/%s", queryRoute, accAddr), nil)
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/items_by_sender/%s", queryRoute, accAddr), nil)
if err != nil {
return fmt.Errorf(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion x/pylons/client/cli/query/list_recipes.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func ListRecipes(queryRoute string, cdc *codec.Codec) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/list_recipe/%s", queryRoute, accAddr), nil)
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/list_recipe/%s", queryRoute, accAddr), nil)
if err != nil {
return fmt.Errorf(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion x/pylons/client/cli/query/list_trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func ListTrade(queryRoute string, cdc *codec.Codec) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/list_trade/%s", queryRoute, accAddr), nil)
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/list_trade/%s", queryRoute, accAddr), nil)
if err != nil {
return fmt.Errorf(err.Error())
}
Expand Down
28 changes: 6 additions & 22 deletions x/pylons/client/cli/tx/create_cookbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package tx
import (
// "strconv"

"bufio"

"github.com/spf13/cobra"

"github.com/Pylons-tech/pylons/x/pylons/msgs"
Expand All @@ -19,9 +21,6 @@ import (
func CreateCookbook(cdc *codec.Codec) *cobra.Command {

var msgCCB msgs.MsgCreateCookbook
// var tmpVersion string
// var tmpEmail string
// var tmpLevel string

ccb := &cobra.Command{
Use: "create-cookbook [args]",
Expand All @@ -32,17 +31,13 @@ func CreateCookbook(cdc *codec.Codec) *cobra.Command {
// If we set level, version, support_email, tmp_level name and description separately,
// it can be very complex, especially for other commands like create_recipe, fiat_item

cliCtx := context.NewCLIContext().WithCodec(cdc).WithAccountDecoder(cdc)

txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().WithCodec(cdc)
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))

if err := cliCtx.EnsureAccountExists(); err != nil {
return err
}
// lvl, err := strconv.Atoi(tmpLevel)
// if err != nil {
// return err
// }
byteValue, err := ReadFile(args[0])
if err != nil {
return err
Expand All @@ -52,9 +47,6 @@ func CreateCookbook(cdc *codec.Codec) *cobra.Command {
return err
}

// msgCCB.Level = types.Level(lvl)
// msgCCB.Version = types.SemVer(tmpVersion)
// msgCCB.SupportEmail = types.Email(tmpEmail)
msgCCB.Sender = cliCtx.GetFromAddress()

err = msgCCB.ValidateBasic()
Expand All @@ -64,17 +56,9 @@ func CreateCookbook(cdc *codec.Codec) *cobra.Command {

cliCtx.PrintResponse = true

return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msgCCB}, false)
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msgCCB})
},
}

// Keeping it as commented, in case we need this later
// ccb.PersistentFlags().StringVar(&msgCCB.Name, "name", "", "The name of the cookbook")
// ccb.PersistentFlags().StringVar(&msgCCB.Description, "desc", "", "The description for the cookbook")
// ccb.PersistentFlags().StringVar(&msgCCB.Developer, "developer", "", "The developer of the cookbook")
// ccb.PersistentFlags().StringVar(&tmpEmail, "email", "", "The support email")
// ccb.PersistentFlags().StringVar(&tmpVersion, "version", "", "The version of the cookbook")
// ccb.PersistentFlags().StringVar(&tmpLevel, "level", "", "The level of the cookbook")

return ccb
}
10 changes: 6 additions & 4 deletions x/pylons/client/cli/tx/fiat_item.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package tx

import (
"bufio"

"github.com/spf13/cobra"

"github.com/Pylons-tech/pylons/x/pylons/msgs"
Expand All @@ -21,9 +23,9 @@ func FiatItem(cdc *codec.Codec) *cobra.Command {
Short: "create item and assign it to sender",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc).WithAccountDecoder(cdc)

txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().WithCodec(cdc)
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))

if err := cliCtx.EnsureAccountExists(); err != nil {
return err
Expand All @@ -46,7 +48,7 @@ func FiatItem(cdc *codec.Codec) *cobra.Command {

cliCtx.PrintResponse = true

return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msgFI}, false)
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msgFI})
},
}

Expand Down
10 changes: 6 additions & 4 deletions x/pylons/client/cli/tx/get_pylons.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package tx

import (
"bufio"

"github.com/spf13/cobra"

"github.com/Pylons-tech/pylons/x/pylons/msgs"
Expand All @@ -24,9 +26,9 @@ func GetPylons(cdc *codec.Codec) *cobra.Command {
Short: "ask for pylons. 500 pylons per request",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc).WithAccountDecoder(cdc)

txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().WithCodec(cdc)
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))

if err := cliCtx.EnsureAccountExists(); err != nil {
return err
Expand All @@ -40,7 +42,7 @@ func GetPylons(cdc *codec.Codec) *cobra.Command {

cliCtx.PrintResponse = true

return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}, false)
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
}
8 changes: 5 additions & 3 deletions x/pylons/client/cli/tx/send_pylons.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tx

import (
"bufio"
"errors"

"github.com/spf13/cobra"
Expand All @@ -24,9 +25,10 @@ func SendPylons(cdc *codec.Codec) *cobra.Command {
Short: "send pylons of specific amount to the name provided",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc).WithAccountDecoder(cdc)
cliCtx := context.NewCLIContext().WithCodec(cdc)

txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))

if err := cliCtx.EnsureAccountExists(); err != nil {
return err
Expand Down Expand Up @@ -60,7 +62,7 @@ func SendPylons(cdc *codec.Codec) *cobra.Command {

cliCtx.PrintResponse = true

return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}, false)
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}
}
10 changes: 6 additions & 4 deletions x/pylons/client/cli/tx/update_cookbook.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package tx

import (
"bufio"

"github.com/spf13/cobra"

"github.com/Pylons-tech/pylons/x/pylons/msgs"
Expand All @@ -25,9 +27,9 @@ func UpdateCookbook(cdc *codec.Codec) *cobra.Command {
Short: "update cookbook by providing the args",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc).WithAccountDecoder(cdc)

txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().WithCodec(cdc)
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))

if err := cliCtx.EnsureAccountExists(); err != nil {
return err
Expand All @@ -43,7 +45,7 @@ func UpdateCookbook(cdc *codec.Codec) *cobra.Command {

cliCtx.PrintResponse = true

return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msgCCB}, false)
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msgCCB})
},
}

Expand Down
2 changes: 1 addition & 1 deletion x/pylons/client/rest/address_from_pub_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ func addrFromPubkeyHandler(cdc *codec.Codec, cliCtx context.CLIContext, storeNam
return
}

rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
2 changes: 1 addition & 1 deletion x/pylons/client/rest/items_by_cookbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ func itemsByCookbookHandler(cdc *codec.Codec, cliCtx context.CLIContext, storeNa
return
}

rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
2 changes: 1 addition & 1 deletion x/pylons/client/rest/items_by_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ func itemsBySenderHandler(cdc *codec.Codec, cliCtx context.CLIContext, storeName
return
}

rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
4 changes: 2 additions & 2 deletions x/pylons/client/rest/list_cookbooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ func listCookbooksHandler(cdc *codec.Codec, cliCtx context.CLIContext, storeName
vars := mux.Vars(r)
ownerKey := vars[ownerKeyName]

res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/list_cookbook/%s", storeName, ownerKey), nil)
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/list_cookbook/%s", storeName, ownerKey), nil)
if err != nil {
rest.WriteErrorResponse(w, http.StatusNotFound, err.Error())
return
}

rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
2 changes: 1 addition & 1 deletion x/pylons/client/rest/list_executions.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ func listExecutionsHandler(cdc *codec.Codec, cliCtx context.CLIContext, storeNam
return
}

rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
2 changes: 1 addition & 1 deletion x/pylons/client/rest/list_recipes.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ func listRecipesHandler(cdc *codec.Codec, cliCtx context.CLIContext, storeName s
return
}

rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
2 changes: 1 addition & 1 deletion x/pylons/client/rest/list_trades.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ func listTradesHandler(cdc *codec.Codec, cliCtx context.CLIContext, storeName st
return
}

rest.PostProcessResponse(w, cdc, res, cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, res)
}
}
5 changes: 3 additions & 2 deletions x/pylons/client/rest/txbuilder/create_cookbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package txbuilder
// this module provides the fixtures to build a transaction

import (
"bytes"
"net/http"

"github.com/Pylons-tech/pylons/x/pylons/msgs"
Expand All @@ -22,7 +23,7 @@ func CreateCookbookTxBuilder(cdc *codec.Codec, cliCtx context.CLIContext, storeN
// requester := vars[TxGPRequesterKey]
sender, err := sdk.AccAddressFromBech32("cosmos1y8vysg9hmvavkdxpvccv2ve3nssv5avm0kt337")

txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
txBldr := auth.NewTxBuilderFromCLI(&bytes.Buffer{}).WithTxEncoder(utils.GetTxEncoder(cdc))

msg := msgs.NewMsgCreateCookbook("name", "", "this has to meet character limits lol", "SketchyCo", "1.0.0", "[email protected]", 0, msgs.DefaultCostPerBlock, sender)

Expand All @@ -32,6 +33,6 @@ func CreateCookbookTxBuilder(cdc *codec.Codec, cliCtx context.CLIContext, storeN
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
}

rest.PostProcessResponse(w, cdc, signMsg.Bytes(), cliCtx.Indent)
rest.PostProcessResponse(w, cliCtx, signMsg.Bytes())
}
}
Loading

0 comments on commit 8f2921a

Please sign in to comment.