Complete tx command and wire to module
This commit is contained in:
@@ -1,11 +1,12 @@
|
|||||||
package client
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
// "strconv"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
"github.com/cosmos/cosmos-sdk/client/context"
|
"github.com/cosmos/cosmos-sdk/client/context"
|
||||||
@@ -31,11 +32,11 @@ func GetTxCmd(cdc *codec.Codec) *cobra.Command {
|
|||||||
SuggestionsMinimumDistance: 2,
|
SuggestionsMinimumDistance: 2,
|
||||||
RunE: client.ValidateCmd,
|
RunE: client.ValidateCmd,
|
||||||
}
|
}
|
||||||
txCmd.AddCommand(
|
txCmd.AddCommand(client.PostCommands(
|
||||||
StoreCodeCmd(cdc),
|
StoreCodeCmd(cdc),
|
||||||
// InstantiateContractCmd(cdc),
|
InstantiateContractCmd(cdc),
|
||||||
// ExecuteContractCmd(cdc),
|
ExecuteContractCmd(cdc),
|
||||||
)
|
)...)
|
||||||
return txCmd
|
return txCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,92 +65,85 @@ func StoreCodeCmd(cdc *codec.Codec) *cobra.Command {
|
|||||||
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
|
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = client.PostCommands(cmd)[0]
|
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// // InstantiateContractCmd will instantiate a contract from previously uploaded code.
|
// InstantiateContractCmd will instantiate a contract from previously uploaded code.
|
||||||
// func InstantiateContractCmd(cdc *codec.Codec) *cobra.Command {
|
func InstantiateContractCmd(cdc *codec.Codec) *cobra.Command {
|
||||||
// cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
// Use: "create [from_key_or_address] [code_id_int64] [coins] [json_encoded_init_args]",
|
Use: "create [from_key_or_address] [code_id_int64] [json_encoded_init_args]",
|
||||||
// Short: "Instantiate a wasm contract",
|
Short: "Instantiate a wasm contract",
|
||||||
// Args: cobra.ExactArgs(4),
|
Args: cobra.ExactArgs(3),
|
||||||
// RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
// txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
|
inBuf := bufio.NewReader(cmd.InOrStdin())
|
||||||
// cliCtx := context.NewCLIContextWithFrom(args[0]).
|
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
|
||||||
// WithCodec(cdc).
|
cliCtx := context.NewCLIContextWithInputAndFrom(inBuf, args[0]).WithCodec(cdc)
|
||||||
// WithAccountDecoder(cdc)
|
|
||||||
|
|
||||||
// // get the id of the code to instantiate
|
// get the id of the code to instantiate
|
||||||
// codeID, err := strconv.Atoi(args[1])
|
codeID, err := strconv.ParseUint(args[1], 10, 64)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return err
|
return err
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // parse coins trying to be sent
|
amounstStr := viper.GetString(flagAmount)
|
||||||
// coins, err := sdk.ParseCoins(args[2])
|
amount, err := sdk.ParseCoins(amounstStr)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return err
|
return err
|
||||||
// }
|
}
|
||||||
|
|
||||||
// initMsg := args[3]
|
initMsg := args[2]
|
||||||
|
|
||||||
// // build and sign the transaction, then broadcast to Tendermint
|
// build and sign the transaction, then broadcast to Tendermint
|
||||||
// msg := MsgCreateContract{
|
msg := types.MsgInstantiateContract{
|
||||||
// Sender: cliCtx.GetFromAddress(),
|
Sender: cliCtx.GetFromAddress(),
|
||||||
// Code: CodeID(codeID),
|
Code: codeID,
|
||||||
// InitFunds: coins,
|
InitFunds: amount,
|
||||||
// InitMsg: []byte(initMsg),
|
InitMsg: []byte(initMsg),
|
||||||
// }
|
}
|
||||||
// return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
|
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
|
||||||
// },
|
},
|
||||||
// }
|
}
|
||||||
|
|
||||||
// cmd = client.PostCommands(cmd)[0]
|
cmd.Flags().String(flagAmount, "", "Coins to send to the contract during instantiation")
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
// return cmd
|
// ExecuteContractCmd will instantiate a contract from previously uploaded code.
|
||||||
// }
|
func ExecuteContractCmd(cdc *codec.Codec) *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "send [from_key_or_address] [contract_addr_bech32] [json_encoded_send_args]",
|
||||||
|
Short: "Execute a command on a wasm contract",
|
||||||
|
Args: cobra.ExactArgs(3),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
inBuf := bufio.NewReader(cmd.InOrStdin())
|
||||||
|
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
|
||||||
|
cliCtx := context.NewCLIContextWithInputAndFrom(inBuf, args[0]).WithCodec(cdc)
|
||||||
|
|
||||||
// // ExecuteContractCmd will instantiate a contract from previously uploaded code.
|
// get the id of the code to instantiate
|
||||||
// func ExecuteContractCmd(cdc *codec.Codec) *cobra.Command {
|
contractAddr, err := sdk.AccAddressFromBech32(args[1])
|
||||||
// cmd := &cobra.Command{
|
if err != nil {
|
||||||
// Use: "send [from_key_or_address] [contract_addr_bech32] [coins] [json_encoded_send_args]",
|
return err
|
||||||
// Short: "Instantiate a wasm contract",
|
}
|
||||||
// Args: cobra.ExactArgs(4),
|
|
||||||
// RunE: func(cmd *cobra.Command, args []string) error {
|
|
||||||
// txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
|
|
||||||
// cliCtx := context.NewCLIContextWithFrom(args[0]).
|
|
||||||
// WithCodec(cdc).
|
|
||||||
// WithAccountDecoder(cdc)
|
|
||||||
|
|
||||||
// // get the id of the code to instantiate
|
amounstStr := viper.GetString(flagAmount)
|
||||||
// contractAddr, err := sdk.AccAddressFromBech32(args[1])
|
amount, err := sdk.ParseCoins(amounstStr)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return err
|
return err
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // parse coins trying to be sent
|
execMsg := args[3]
|
||||||
// coins, err := sdk.ParseCoins(args[2])
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
|
|
||||||
// sendMsg := args[3]
|
// build and sign the transaction, then broadcast to Tendermint
|
||||||
|
msg := types.MsgExecuteContract{
|
||||||
|
Sender: cliCtx.GetFromAddress(),
|
||||||
|
Contract: contractAddr,
|
||||||
|
SentFunds: amount,
|
||||||
|
Msg: []byte(execMsg),
|
||||||
|
}
|
||||||
|
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
// // build and sign the transaction, then broadcast to Tendermint
|
cmd.Flags().String(flagAmount, "", "Coins to send to the contract along with command")
|
||||||
// msg := MsgSendContract{
|
return cmd
|
||||||
// Sender: cliCtx.GetFromAddress(),
|
}
|
||||||
// Contract: contractAddr,
|
|
||||||
// Payment: coins,
|
|
||||||
// Msg: []byte(sendMsg),
|
|
||||||
// }
|
|
||||||
// return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
|
|
||||||
// },
|
|
||||||
// }
|
|
||||||
|
|
||||||
// cmd = client.PostCommands(cmd)[0]
|
|
||||||
|
|
||||||
// return cmd
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/module"
|
"github.com/cosmos/cosmos-sdk/types/module"
|
||||||
// "github.com/cosmwasm/wasmd/x/wasm/client/cli"
|
"github.com/cosmwasm/wasmd/x/wasm/client/cli"
|
||||||
// "github.com/cosmwasm/wasmd/x/wasm/client/rest"
|
// "github.com/cosmwasm/wasmd/x/wasm/client/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -57,7 +57,9 @@ func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetTxCmd returns the root tx command for the wasm module.
|
// GetTxCmd returns the root tx command for the wasm module.
|
||||||
func (AppModuleBasic) GetTxCmd(_ *codec.Codec) *cobra.Command { return nil }
|
func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command {
|
||||||
|
return cli.GetTxCmd(cdc)
|
||||||
|
}
|
||||||
|
|
||||||
// GetQueryCmd returns no root query command for the wasm module.
|
// GetQueryCmd returns no root query command for the wasm module.
|
||||||
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
|
func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command {
|
||||||
|
|||||||
Reference in New Issue
Block a user