示例#1
0
func cliName(cmd *cobra.Command, args []string) {
	if dataFlag != "" && dataFileFlag != "" {
		common.Exit(fmt.Errorf("Please specify only one of --data and --data-file"))
	}
	data := dataFlag
	if dataFlag == "" && dataFileFlag != "" {
		b, err := ioutil.ReadFile(dataFileFlag)
		common.IfExit(err)
		data = string(b)
	}
	tx, err := core.Name(nodeAddrFlag, signAddrFlag, pubkeyFlag, addrFlag, amtFlag, nonceFlag, feeFlag, nameFlag, data)
	common.IfExit(err)
	logger.Debugf("%v\n", tx)
	unpackSignAndBroadcast(core.SignAndBroadcast(chainidFlag, nodeAddrFlag, signAddrFlag, tx, signFlag, broadcastFlag, waitFlag))
}
示例#2
0
func cliBond(cmd *cobra.Command, args []string) {
	tx, err := core.Bond(nodeAddrFlag, signAddrFlag, pubkeyFlag, unbondtoFlag, amtFlag, nonceFlag)
	common.IfExit(err)

	logger.Debugf("%v\n", tx)
	unpackSignAndBroadcast(core.SignAndBroadcast(chainidFlag, nodeAddrFlag, signAddrFlag, tx, signFlag, broadcastFlag, waitFlag))
}
示例#3
0
文件: cli.go 项目: alist/mint-client
func cliSend(c *cli.Context) {
	chainID, nodeAddr, signAddr := c.String("chainID"), c.String("node-addr"), c.String("sign-addr")
	sign, broadcast, wait := c.Bool("sign"), c.Bool("broadcast"), c.Bool("wait")
	pubkey, amtS, nonceS, addr, toAddr := c.String("pubkey"), c.String("amt"), c.String("nonce"), c.String("addr"), c.String("to")
	tx, err := core.Send(nodeAddr, pubkey, addr, toAddr, amtS, nonceS)
	common.IfExit(err)
	logger.Debugf("%v\n", tx)
	unpackSignAndBroadcast(core.SignAndBroadcast(chainID, nodeAddr, signAddr, tx, sign, broadcast, wait))
}
示例#4
0
文件: cli.go 项目: alist/mint-client
func cliRebond(c *cli.Context) {
	chainID, nodeAddr, signAddr := c.String("chainID"), c.String("node-addr"), c.String("sign-addr")
	sign, broadcast, wait := c.Bool("sign"), c.Bool("broadcast"), c.Bool("wait")
	addr, height := c.String("addr"), c.String("height")
	tx, err := core.Rebond(addr, height)
	common.IfExit(err)
	logger.Debugf("%v\n", tx)
	unpackSignAndBroadcast(core.SignAndBroadcast(chainID, nodeAddr, signAddr, tx, sign, broadcast, wait))
}
示例#5
0
文件: cli.go 项目: alist/mint-client
func cliName(c *cli.Context) {
	chainID, nodeAddr, signAddr := c.String("chainID"), c.String("node-addr"), c.String("sign-addr")
	sign, broadcast, wait := c.Bool("sign"), c.Bool("broadcast"), c.Bool("wait")
	pubkey, amtS, nonceS, feeS, addr := c.String("pubkey"), c.String("amt"), c.String("nonce"), c.String("fee"), c.String("addr")

	if c.IsSet("data") && c.IsSet("data-file") {
		common.Exit(fmt.Errorf("Please specify only one of --data and --data-file"))
	}
	name, data, dataFile := c.String("name"), c.String("data"), c.String("data-file")
	if data == "" && dataFile != "" {
		b, err := ioutil.ReadFile(dataFile)
		common.IfExit(err)
		data = string(b)
	}
	tx, err := core.Name(nodeAddr, pubkey, addr, amtS, nonceS, feeS, name, data)
	common.IfExit(err)
	logger.Debugf("%v\n", tx)
	unpackSignAndBroadcast(core.SignAndBroadcast(chainID, nodeAddr, signAddr, tx, sign, broadcast, wait))
}
示例#6
0
文件: cli.go 项目: alist/mint-client
func unpackSignAndBroadcast(result *core.TxResult, err error) {
	common.IfExit(err)
	if result == nil {
		// if we don't provide --sign or --broadcast
		return
	}
	fmt.Printf("Transaction Hash: %X\n", result.Hash)
	if result.Return != nil {
		fmt.Printf("Block Hash: %X\n", result.BlockHash)
		fmt.Printf("Return Value: %X\n", result.Return)
		fmt.Printf("Exception: %s\n", result.Exception)
	}
}
示例#7
0
文件: cli.go 项目: alist/mint-client
func cliPermissions(c *cli.Context) {
	chainID, nodeAddr, signAddr := c.String("chainID"), c.String("node-addr"), c.String("sign-addr")
	sign, broadcast, wait := c.Bool("sign"), c.Bool("broadcast"), c.Bool("wait")
	pubkey, nonceS, addr := c.String("pubkey"), c.String("nonce"), c.String("addr")

	// all functions take at least 2 args (+ name)
	if len(c.Args()) < 3 {
		common.Exit(fmt.Errorf("Please enter the permission function you'd like to call, followed by it's arguments"))
	}
	permFunc := c.Args()[0]
	tx, err := core.Permissions(nodeAddr, pubkey, addr, nonceS, permFunc, c.Args()[1:])
	common.IfExit(err)
	logger.Debugf("%v\n", tx)
	unpackSignAndBroadcast(core.SignAndBroadcast(chainID, nodeAddr, signAddr, tx, sign, broadcast, wait))
}
示例#8
0
func cliPermissions(cmd *cobra.Command, args []string) {
	// all functions take at least 2 args (+ name)
	if len(args) < 3 {
		s := fmt.Sprintf("Please enter the permission function you'd like to call, followed by it's arguments.")
		s = fmt.Sprintf("%s\nOptions:", s)
		for _, p := range core.PermsFuncs {
			s = fmt.Sprintf("%s\n\t%s(%s)", s, p.Name, p.Args)
		}
		s += "\n"
		s += "eg. mintx permission set_base 098E260AD99FFAE17A02E0F3692C7A493B122274 create_account true\n"

		common.Exit(fmt.Errorf(s))
	}
	permFunc := args[0]
	tx, err := core.Permissions(nodeAddrFlag, signAddrFlag, pubkeyFlag, addrFlag, nonceFlag, permFunc, args[1:])
	common.IfExit(err)
	logger.Debugf("%v\n", tx)
	unpackSignAndBroadcast(core.SignAndBroadcast(chainidFlag, nodeAddrFlag, signAddrFlag, tx, signFlag, broadcastFlag, waitFlag))
}
示例#9
0
func main() {

	// these are defined in here so we can update the
	// defaults with env variables first

	var versionCmd = &cobra.Command{
		Use:   "version",
		Short: "print the mintx version",
		Long:  "print the mintx version",
		Run: func(cmd *cobra.Command, args []string) {
			fmt.Println("0.2.0") // upgrade cli to cobra
		},
	}

	var sendCmd = &cobra.Command{
		Use:   "send",
		Short: "mintx send --amt <amt> --to <addr>",
		Long:  "mintx send --amt <amt> --to <addr>",
		Run:   cliSend,
	}
	sendCmd.Flags().StringVarP(&amtFlag, "amt", "a", "", "specify an amount")
	sendCmd.Flags().StringVarP(&toFlag, "to", "t", "", "specify an address to send to")

	var nameCmd = &cobra.Command{
		Use:   "name",
		Short: "mintx name --amt <amt> --name <name> --data <data>",
		Long:  "mintx name --amt <amt> --name <name> --data <data>",
		Run:   cliName,
	}
	nameCmd.Flags().StringVarP(&amtFlag, "amt", "a", "", "specify an amount")
	nameCmd.Flags().StringVarP(&nameFlag, "name", "n", "", "specify a name")
	nameCmd.Flags().StringVarP(&dataFlag, "data", "d", "", "specify some data")
	nameCmd.Flags().StringVarP(&dataFileFlag, "data-file", "", "", "specify a file with some data")
	nameCmd.Flags().StringVarP(&feeFlag, "fee", "f", "", "specify the fee to send")

	var callCmd = &cobra.Command{
		Use:   "call",
		Short: "mintx call --amt <amt> --fee <fee> --gas <gas> --to <contract addr> --data <data>",
		Long:  "mintx call --amt <amt> --fee <fee> --gas <gas> --to <contract addr> --data <data>",
		Run:   cliCall,
	}
	callCmd.Flags().StringVarP(&amtFlag, "amt", "a", "", "specify an amount")
	callCmd.Flags().StringVarP(&toFlag, "to", "t", "", "specify an address to send to")
	callCmd.Flags().StringVarP(&dataFlag, "data", "d", "", "specify some data")
	callCmd.Flags().StringVarP(&feeFlag, "fee", "f", "", "specify the fee to send")
	callCmd.Flags().StringVarP(&gasFlag, "gas", "g", "", "specify the gas limit for a CallTx")

	var bondCmd = &cobra.Command{
		Use:   "bond",
		Short: "mintx bond --pubkey <pubkey> --amt <amt> --unbond-to <address>",
		Long:  "mintx bond --pubkey <pubkey> --amt <amt> --unbond-to <address>",
		Run:   cliBond,
	}
	bondCmd.Flags().StringVarP(&amtFlag, "amt", "a", "", "specify an amount")
	bondCmd.Flags().StringVarP(&unbondtoFlag, "to", "t", "", "specify an address to unbond to")

	var unbondCmd = &cobra.Command{
		Use:   "unbond",
		Short: "mintx unbond --addr <address> --height <block_height>",
		Long:  "mintx unbond --addr <address> --height <block_height>",
		Run:   cliUnbond,
	}
	unbondCmd.Flags().StringVarP(&addrFlag, "addr", "a", "", "specify an address")
	unbondCmd.Flags().StringVarP(&heightFlag, "height", "h", "", "specify a height to unbond at")

	var rebondCmd = &cobra.Command{
		Use:   "rebond",
		Short: "mintx rebond --addr <address> --height <block_height>",
		Long:  "mintx rebond --addr <address> --height <block_height>",
		Run:   cliRebond,
	}
	rebondCmd.Flags().StringVarP(&addrFlag, "addr", "a", "", "specify an address")
	rebondCmd.Flags().StringVarP(&heightFlag, "height", "h", "", "specify a height to unbond at")

	var permissionsCmd = &cobra.Command{
		Use:   "permission",
		Short: "mintx perm <function name> <args ...>",
		Long:  "mintx perm <function name> <args ...>",
		Run:   cliPermissions,
	}
	permissionsCmd.Flags().StringVarP(&addrFlag, "addr", "a", "", "specify an address")
	permissionsCmd.Flags().StringVarP(&heightFlag, "height", "n", "", "specify a height to unbond at")

	var rootCmd = &cobra.Command{
		Use:               "mintx",
		Short:             "craft, sign, and broadcast tendermint transactions",
		Long:              "craft, sign, and broadcast tendermint transactions",
		PersistentPreRun:  before,
		PersistentPostRun: after,
	}

	rootCmd.PersistentFlags().StringVarP(&signAddrFlag, "sign-addr", "", DefaultKeyDaemonAddr, "set eris-keys daemon address (defaults to $MINTX_SIGN_ADDR)")
	rootCmd.PersistentFlags().StringVarP(&nodeAddrFlag, "node-addr", "", DefaultNodeRPCAddr, "set the tendermint rpc server address (defaults to $MINTX_NODE_ADDR)")
	rootCmd.PersistentFlags().StringVarP(&pubkeyFlag, "pubkey", "", DefaultPubKey, "specify the pubkey (defaults to $MINTX_PUBKEY)")
	rootCmd.PersistentFlags().StringVarP(&addrFlag, "addr", "", "", "specify the address (from which the pubkey can be fetch from eris-keys)")
	rootCmd.PersistentFlags().StringVarP(&chainidFlag, "chainID", "", DefaultChainID, "specify the pubkey (defaults to $MINTX_CHAINID)")
	rootCmd.PersistentFlags().StringVarP(&nonceFlag, "nonce", "", "", "specify the nonce to use for the transaction (should equal the sender account's nonce + 1)")

	rootCmd.PersistentFlags().BoolVarP(&signFlag, "sign", "s", false, "sign the transaction using the eris-keys daemon")
	rootCmd.PersistentFlags().BoolVarP(&broadcastFlag, "broadcast", "b", false, "broadcast the transaction to the blockchain")
	rootCmd.PersistentFlags().BoolVarP(&waitFlag, "wait", "w", false, "wait for the transaction to be committed in a block")

	rootCmd.PersistentFlags().IntVarP(&logLevelFlag, "log", "l", 0, "log level")

	rootCmd.AddCommand(versionCmd, sendCmd, callCmd, nameCmd, bondCmd, unbondCmd, rebondCmd, permissionsCmd)
	common.IfExit(rootCmd.Execute())
}
示例#10
0
func cliRebond(cmd *cobra.Command, args []string) {
	tx, err := core.Rebond(addrFlag, heightFlag)
	common.IfExit(err)
	logger.Debugf("%v\n", tx)
	unpackSignAndBroadcast(core.SignAndBroadcast(chainidFlag, nodeAddrFlag, signAddrFlag, tx, signFlag, broadcastFlag, waitFlag))
}