Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paytovote Plugin Dev #13

Closed
wants to merge 12 commits into from
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const (

type Basecoin struct {
eyesCli *eyes.Client
state *sm.State
cacheState *sm.State
state *sm.State // for block processing (deliver tx, etc.)
cacheState *sm.State // just for checktx, derived from state on commit
plugins *types.Plugins
}

Expand Down
107 changes: 107 additions & 0 deletions cmd/paytovote/commands/p2vCommands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package commands

import (
"fmt"

bcmd "github.com/tendermint/basecoin/cmd/basecoin/commands"
"github.com/tendermint/basecoin/plugins/paytovote"
"github.com/tendermint/basecoin/types"
"github.com/urfave/cli"
)

const PaytovoteName = "paytovote"

var (
//common flag
IssueFlag = cli.StringFlag{
Name: "issue",
Value: "default issue",
Usage: "name of the issue to generate or vote for",
}

//createIssue flags
VoteFeeCoinFlag = cli.StringFlag{
Name: "voteFeeCoin",
Value: "",
Usage: "the fee's coin type to vote for the issue",
}
VoteFeeAmtFlag = cli.IntFlag{
Name: "voteFeeAmt",
Value: 0,
Usage: "the fee amount of coin type VoteCoinFlag to vote for the issue",
}

//vote flag
VoteForFlag = cli.BoolFlag{
Name: "voteFor",
Usage: "set to true when vote be cast is a vote-for the issue, false if vote-against",
}
)

var (
P2VCreateIssueCmd = cli.Command{
Name: "P2VCreateIssue",
Usage: "Create an issue which can be voted for",
Action: func(c *cli.Context) error {
return cmdCreateIssue(c)
},
Flags: []cli.Flag{
IssueFlag,
VoteFeeCoinFlag,
VoteFeeAmtFlag,
},
}

P2VVoteCmd = cli.Command{
Name: "P2VVote",
Usage: "Vote for an existing issue",
Action: func(c *cli.Context) error {
return cmdVote(c)
},
Flags: []cli.Flag{
IssueFlag,
VoteForFlag,
},
}

PaytovotePluginFlag = cli.BoolFlag{
Name: "paytovote-plugin",
Usage: "Enable the paytovote plugin",
}
)

func init() {
bcmd.RegisterTxPlugin(P2VCreateIssueCmd)
bcmd.RegisterTxPlugin(P2VVoteCmd)
bcmd.RegisterStartPlugin(PaytovotePluginFlag,
func() types.Plugin { return paytovote.New() })
}

func cmdCreateIssue(c *cli.Context) error {
issue := c.String(IssueFlag.Name)
feeCoin := c.String(VoteFeeCoinFlag.Name)
feeAmt := int64(c.Int(VoteFeeAmtFlag.Name))

voteFee := types.Coins{{feeCoin, feeAmt}}
createIssueFee := types.Coins{{"issueToken", 1}} //manually set the cost to create a new issue

txBytes := paytovote.NewCreateIssueTxBytes(issue, voteFee, createIssueFee)

fmt.Println("Issue creation transaction sent")
return bcmd.AppTx(c.Parent(), PaytovoteName, txBytes)
}

func cmdVote(c *cli.Context) error {
issue := c.String(IssueFlag.Name)
voteFor := c.Bool(VoteForFlag.Name)

var voteTB byte = paytovote.TypeByteVoteFor
if !voteFor {
voteTB = paytovote.TypeByteVoteAgainst
}

txBytes := paytovote.NewVoteTxBytes(issue, voteTB)

fmt.Println("Vote transaction sent")
return bcmd.AppTx(c.Parent(), PaytovoteName, txBytes)
}
13 changes: 13 additions & 0 deletions cmd/paytovote/data/genesis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
"base/chainID", "mint_chain_id",
"mint/add", "D397BC62B435F3CF50570FBAB4340FE52C60858F",
"base/account", {
"pub_key": [1, "B3588BDC92015ED3CDB6F57A86379E8C79A7111063610B7E625487C76496F4DF"],
"coins": [
{
"denom": "blank",
"amount": 1000
}
]
}
]
17 changes: 17 additions & 0 deletions cmd/paytovote/data/priv_validator.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"address": "D397BC62B435F3CF50570FBAB4340FE52C60858F",
"last_height": 0,
"last_round": 0,
"last_signature": null,
"last_signbytes": "",
"last_step": 0,
"priv_key": [
1,
"39E75AA1CF7BC710585977EFC375CD1730519186BD231478C339F2819C3C26E7B3588BDC92015ED3CDB6F57A86379E8C79A7111063610B7E625487C76496F4DF"
],
"pub_key": [
1,
"B3588BDC92015ED3CDB6F57A86379E8C79A7111063610B7E625487C76496F4DF"
]
}

16 changes: 16 additions & 0 deletions cmd/paytovote/data/priv_validator2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"address": "4793A333846E5104C46DD9AB9A00E31821B2F301",
"last_height": 0,
"last_round": 0,
"last_signature": null,
"last_signbytes": "",
"last_step": 0,
"priv_key": [
1,
"13A04A552ABAA2CCFA1F618CF9C97F1FD59FC3EE4968FE87DF3637C9B0F2FAAA93766F08BE7135E78DBFFA76B61BC7C52B96256EB4394A224B4EF8BCC954DE2E"
],
"pub_key": [
1,
"93766F08BE7135E78DBFFA76B61BC7C52B96256EB4394A224B4EF8BCC954DE2E"
]
}
16 changes: 16 additions & 0 deletions cmd/paytovote/desc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# paytovote plugin

### Description
paytovote is a basic application which demonstrates how to leverage the basecoin library to create an instance of the basecoin system which utilizes a custom paytovote plugin. The premise of this plugin is to allow users to pay a fee to create or vote for user-specified issues. Unique fees are applied when voting or creating a new issue. Fees may use coin types (for example "voteTokens" or "newIssueTokens"). Currently, the fee to cast a vote is decided by the user when the issue is being generated, and the fee to create a new issue is defined globally within the plugin CLI commands (cmd/paytovote/commands)

### Usage
- enable the paytovote plugin and start `paytovote start --paytovote-plugin`
- start tendermint in another terminal `tendermint node`
- create issues with `paytovote AppTx P2VCreateIssue`
- for a complete list of required flags and usage see:
- `paytovote AppTx -h`
- `paytovote AppTx P2VCreateIssue -h`
- vote for issues with `paytovote AppTx P2VVote`
- for a complete list of required flags and usage see:
- `paytovote AppTx -h`
- `paytovote AppTx P2VVote -h`
27 changes: 27 additions & 0 deletions cmd/paytovote/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"os"

"github.com/tendermint/basecoin/cmd/basecoin/commands"
_ "github.com/tendermint/basecoin/cmd/paytovote/commands"
"github.com/urfave/cli"
)

func main() {
app := cli.NewApp()
app.Name = "paytovote"
app.Usage = "paytovote [command] [args...]"
app.Version = "0.1.0"
app.Commands = []cli.Command{
commands.StartCmd,
commands.SendTxCmd,
commands.AppTxCmd,
commands.IbcCmd,
commands.QueryCmd,
commands.VerifyCmd,
commands.BlockCmd,
commands.AccountCmd,
}
app.Run(os.Args)
}
2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import:
- package: github.com/tendermint/merkleeyes
version: develop
- package: github.com/tendermint/tendermint
version: develop
version: abci_proof
- package: github.com/tendermint/abci
version: develop
- package: github.com/gorilla/websocket
Expand Down
Loading