2017-08-06 13:51:07 -07:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
"github.com/tendermint/basecoin/client/commands"
|
|
|
|
"github.com/tendermint/basecoin/client/commands/txs"
|
2017-08-07 09:49:03 -07:00
|
|
|
"github.com/tendermint/basecoin/modules/eyes"
|
2017-08-06 13:51:07 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
// SetTxCmd is CLI command to set data
|
|
|
|
var SetTxCmd = &cobra.Command{
|
|
|
|
Use: "set",
|
|
|
|
Short: "Sets a key value pair",
|
|
|
|
RunE: commands.RequireInit(setTxCmd),
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveTxCmd is CLI command to remove data
|
|
|
|
var RemoveTxCmd = &cobra.Command{
|
2017-08-06 15:00:34 -07:00
|
|
|
Use: "remove",
|
2017-08-06 13:51:07 -07:00
|
|
|
Short: "Removes a key value pair",
|
|
|
|
RunE: commands.RequireInit(removeTxCmd),
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
2017-08-07 09:47:22 -07:00
|
|
|
// FlagKey is the cli flag to set the key
|
|
|
|
FlagKey = "key"
|
|
|
|
// FlagValue is the cli flag to set the value
|
2017-08-06 13:51:07 -07:00
|
|
|
FlagValue = "value"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
SetTxCmd.Flags().String(FlagKey, "", "Key to store data under (hex)")
|
|
|
|
SetTxCmd.Flags().String(FlagValue, "", "Data to store (hex)")
|
|
|
|
|
|
|
|
RemoveTxCmd.Flags().String(FlagKey, "", "Key under which to remove data (hex)")
|
|
|
|
}
|
|
|
|
|
|
|
|
// setTxCmd creates a SetTx, wraps, signs, and delivers it
|
|
|
|
func setTxCmd(cmd *cobra.Command, args []string) error {
|
|
|
|
key, err := commands.ParseHexFlag(FlagKey)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
value, err := commands.ParseHexFlag(FlagValue)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
tx := etc.NewSetTx(key, value)
|
|
|
|
return txs.DoTx(tx)
|
|
|
|
}
|
|
|
|
|
|
|
|
// removeTxCmd creates a RemoveTx, wraps, signs, and delivers it
|
|
|
|
func removeTxCmd(cmd *cobra.Command, args []string) error {
|
|
|
|
key, err := commands.ParseHexFlag(FlagKey)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
tx := etc.NewRemoveTx(key)
|
|
|
|
return txs.DoTx(tx)
|
|
|
|
}
|