Example #1
0
func cmdPropose(c *cli.Context) {
	args := c.Args()
	if len(args) != 2 {
		Exit("propose takes two args")
	}

	name, data := args[0], args[1]

	pTx := gov.ProposalTx{
		Name:       name,
		Data:       data,
		GroupID:    c.String("group"),
		ProposerID: c.String("proposer"),
	}

	sig, err := SignTx(pTx, c.String("key"))
	if err != nil {
		Exit(err.Error())
	}
	tx := &gov.SignedTx{pTx, sig}
	buf := new(bytes.Buffer)
	var n int
	wire.WriteJSON(tx, buf, &n, &err)
	if err != nil {
		Exit(err.Error())
	}
	_, err = rpcclient.CallHTTP(TendermintHost, "broadcast_tx", []interface{}{hex.EncodeToString(buf.Bytes())}, &rpctypes.ResultBroadcastTx{})
	if err != nil {
		Exit(err.Error())
	}
	log.Notice("Broadcast proposal", "id", []byte((&gov.Proposal{ProposalTx: &pTx}).ID()), "sig", sig)
}
Example #2
0
func cmdVote(c *cli.Context) {
	args := c.Args()
	if len(args) != 3 {
		Exit("propose takes three args")
	}

	proposal, memberS, voteS := args[0], args[1], args[2]

	member, err := strconv.Atoi(memberS)
	if err != nil {
		Exit(err.Error())
	}

	var vote bool
	switch voteS {
	case "yes", "true", "1", "for":
		vote = true
	case "no", "false", "0", "against":
		vote = false
	default:
		Exit("Unknown vote " + voteS)

	}

	vTx := gov.VoteTx{
		ProposalID: proposal,
		Member:     member,
		Vote:       vote,
	}

	sig, err := SignTx(vTx, c.String("key"))
	if err != nil {
		Exit(err.Error())
	}
	tx := &gov.SignedTx{vTx, sig}
	buf := new(bytes.Buffer)
	var n int
	wire.WriteJSON(tx, buf, &n, &err)
	if err != nil {
		Exit(err.Error())
	}
	_, err = rpcclient.CallHTTP(TendermintHost, "broadcast_tx", []interface{}{hex.EncodeToString(buf.Bytes())}, &rpctypes.ResultBroadcastTx{})
	if err != nil {
		Exit(err.Error())
	}
	log.Notice("Broadcast vote", "tx", vTx, "sig", sig)
}