Merge branch 'refactor_cli' into develop
This commit is contained in:
commit
b8f5178300
|
@ -1,226 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var (
|
||||
startCmd = cli.Command{
|
||||
Name: "start",
|
||||
Usage: "Start basecoin",
|
||||
ArgsUsage: "",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdStart(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
addrFlag,
|
||||
eyesFlag,
|
||||
dirFlag,
|
||||
inProcTMFlag,
|
||||
chainIDFlag,
|
||||
ibcPluginFlag,
|
||||
counterPluginFlag,
|
||||
},
|
||||
}
|
||||
|
||||
sendTxCmd = cli.Command{
|
||||
Name: "sendtx",
|
||||
Usage: "Broadcast a basecoin SendTx",
|
||||
ArgsUsage: "",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdSendTx(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
nodeFlag,
|
||||
chainIDFlag,
|
||||
|
||||
fromFlag,
|
||||
|
||||
amountFlag,
|
||||
coinFlag,
|
||||
gasFlag,
|
||||
feeFlag,
|
||||
seqFlag,
|
||||
|
||||
toFlag,
|
||||
},
|
||||
}
|
||||
|
||||
appTxCmd = cli.Command{
|
||||
Name: "apptx",
|
||||
Usage: "Broadcast a basecoin AppTx",
|
||||
ArgsUsage: "",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdAppTx(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
nodeFlag,
|
||||
chainIDFlag,
|
||||
|
||||
fromFlag,
|
||||
|
||||
amountFlag,
|
||||
coinFlag,
|
||||
gasFlag,
|
||||
feeFlag,
|
||||
seqFlag,
|
||||
|
||||
nameFlag,
|
||||
dataFlag,
|
||||
},
|
||||
Subcommands: []cli.Command{
|
||||
counterTxCmd,
|
||||
},
|
||||
}
|
||||
|
||||
counterTxCmd = cli.Command{
|
||||
Name: "counter",
|
||||
Usage: "Craft a transaction to the counter plugin",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdCounterTx(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
validFlag,
|
||||
},
|
||||
}
|
||||
|
||||
ibcCmd = cli.Command{
|
||||
Name: "ibc",
|
||||
Usage: "Send a transaction to the interblockchain (ibc) plugin",
|
||||
Flags: []cli.Flag{
|
||||
nodeFlag,
|
||||
chainIDFlag,
|
||||
|
||||
fromFlag,
|
||||
|
||||
amountFlag,
|
||||
coinFlag,
|
||||
gasFlag,
|
||||
feeFlag,
|
||||
seqFlag,
|
||||
|
||||
nameFlag,
|
||||
dataFlag,
|
||||
},
|
||||
Subcommands: []cli.Command{
|
||||
ibcRegisterTxCmd,
|
||||
ibcUpdateTxCmd,
|
||||
ibcPacketTxCmd,
|
||||
},
|
||||
}
|
||||
|
||||
ibcRegisterTxCmd = cli.Command{
|
||||
Name: "register",
|
||||
Usage: "Register a blockchain via IBC",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdIBCRegisterTx(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
ibcChainIDFlag,
|
||||
ibcGenesisFlag,
|
||||
},
|
||||
}
|
||||
|
||||
ibcUpdateTxCmd = cli.Command{
|
||||
Name: "update",
|
||||
Usage: "Update the latest state of a blockchain via IBC",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdIBCUpdateTx(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
ibcHeaderFlag,
|
||||
ibcCommitFlag,
|
||||
},
|
||||
}
|
||||
|
||||
ibcPacketTxCmd = cli.Command{
|
||||
Name: "packet",
|
||||
Usage: "Send a new packet via IBC",
|
||||
Flags: []cli.Flag{
|
||||
//
|
||||
},
|
||||
Subcommands: []cli.Command{
|
||||
ibcPacketCreateTx,
|
||||
ibcPacketPostTx,
|
||||
},
|
||||
}
|
||||
|
||||
ibcPacketCreateTx = cli.Command{
|
||||
Name: "create",
|
||||
Usage: "Create an egress IBC packet",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdIBCPacketCreateTx(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
ibcFromFlag,
|
||||
ibcToFlag,
|
||||
ibcTypeFlag,
|
||||
ibcPayloadFlag,
|
||||
ibcSequenceFlag,
|
||||
},
|
||||
}
|
||||
|
||||
ibcPacketPostTx = cli.Command{
|
||||
Name: "post",
|
||||
Usage: "Deliver an IBC packet to another chain",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdIBCPacketPostTx(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
ibcFromFlag,
|
||||
ibcHeightFlag,
|
||||
ibcPacketFlag,
|
||||
ibcProofFlag,
|
||||
},
|
||||
}
|
||||
|
||||
queryCmd = cli.Command{
|
||||
Name: "query",
|
||||
Usage: "Query the merkle tree",
|
||||
ArgsUsage: "<key>",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdQuery(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
nodeFlag,
|
||||
},
|
||||
}
|
||||
|
||||
accountCmd = cli.Command{
|
||||
Name: "account",
|
||||
Usage: "Get details of an account",
|
||||
ArgsUsage: "<address>",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdAccount(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
nodeFlag,
|
||||
},
|
||||
}
|
||||
|
||||
blockCmd = cli.Command{
|
||||
Name: "block",
|
||||
Usage: "Get the header and commit of a block",
|
||||
ArgsUsage: "<height>",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdBlock(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
nodeFlag,
|
||||
},
|
||||
}
|
||||
|
||||
verifyCmd = cli.Command{
|
||||
Name: "verify",
|
||||
Usage: "Verify the IAVL proof",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdVerify(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
proofFlag,
|
||||
keyFlag,
|
||||
valueFlag,
|
||||
rootFlag,
|
||||
},
|
||||
}
|
||||
)
|
|
@ -0,0 +1,56 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/tendermint/basecoin/plugins/counter"
|
||||
"github.com/tendermint/basecoin/types"
|
||||
wire "github.com/tendermint/go-wire"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var (
|
||||
CounterTxCmd = cli.Command{
|
||||
Name: "counter",
|
||||
Usage: "Craft a transaction to the counter plugin",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdCounterTx(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
ValidFlag,
|
||||
},
|
||||
}
|
||||
|
||||
CounterPluginFlag = cli.BoolFlag{
|
||||
Name: "counter-plugin",
|
||||
Usage: "Enable the counter plugin",
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterTxPlugin(CounterTxCmd)
|
||||
RegisterStartPlugin(CounterPluginFlag,
|
||||
func() types.Plugin { return counter.New("counter") })
|
||||
}
|
||||
|
||||
func cmdCounterTx(c *cli.Context) error {
|
||||
valid := c.Bool("valid")
|
||||
parent := c.Parent()
|
||||
|
||||
counterTx := counter.CounterTx{
|
||||
Valid: valid,
|
||||
Fee: types.Coins{
|
||||
{
|
||||
Denom: parent.String("coin"),
|
||||
Amount: int64(parent.Int("fee")),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Println("CounterTx:", string(wire.JSONBytes(counterTx)))
|
||||
|
||||
data := wire.BinaryBytes(counterTx)
|
||||
name := "counter"
|
||||
|
||||
return AppTx(parent, name, data)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package commands
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli"
|
||||
|
@ -6,13 +6,13 @@ import (
|
|||
|
||||
// start flags
|
||||
var (
|
||||
addrFlag = cli.StringFlag{
|
||||
AddrFlag = cli.StringFlag{
|
||||
Name: "address",
|
||||
Value: "tcp://0.0.0.0:46658",
|
||||
Usage: "Listen address",
|
||||
}
|
||||
|
||||
eyesFlag = cli.StringFlag{
|
||||
EyesFlag = cli.StringFlag{
|
||||
Name: "eyes",
|
||||
Value: "local",
|
||||
Usage: "MerkleEyes address, or 'local' for embedded",
|
||||
|
@ -21,98 +21,93 @@ var (
|
|||
// TODO: move to config file
|
||||
// eyesCacheSizePtr := flag.Int("eyes-cache-size", 10000, "MerkleEyes db cache size, for embedded")
|
||||
|
||||
dirFlag = cli.StringFlag{
|
||||
DirFlag = cli.StringFlag{
|
||||
Name: "dir",
|
||||
Value: ".",
|
||||
Usage: "Root directory",
|
||||
}
|
||||
|
||||
inProcTMFlag = cli.BoolFlag{
|
||||
InProcTMFlag = cli.BoolFlag{
|
||||
Name: "in-proc",
|
||||
Usage: "Run Tendermint in-process with the App",
|
||||
}
|
||||
|
||||
ibcPluginFlag = cli.BoolFlag{
|
||||
IbcPluginFlag = cli.BoolFlag{
|
||||
Name: "ibc-plugin",
|
||||
Usage: "Enable the ibc plugin",
|
||||
}
|
||||
|
||||
counterPluginFlag = cli.BoolFlag{
|
||||
Name: "counter-plugin",
|
||||
Usage: "Enable the counter plugin",
|
||||
}
|
||||
)
|
||||
|
||||
// tx flags
|
||||
|
||||
var (
|
||||
nodeFlag = cli.StringFlag{
|
||||
NodeFlag = cli.StringFlag{
|
||||
Name: "node",
|
||||
Value: "tcp://localhost:46657",
|
||||
Usage: "Tendermint RPC address",
|
||||
}
|
||||
|
||||
toFlag = cli.StringFlag{
|
||||
ToFlag = cli.StringFlag{
|
||||
Name: "to",
|
||||
Value: "",
|
||||
Usage: "Destination address for the transaction",
|
||||
}
|
||||
|
||||
amountFlag = cli.IntFlag{
|
||||
AmountFlag = cli.IntFlag{
|
||||
Name: "amount",
|
||||
Value: 0,
|
||||
Usage: "Amount of coins to send in the transaction",
|
||||
}
|
||||
|
||||
fromFlag = cli.StringFlag{
|
||||
FromFlag = cli.StringFlag{
|
||||
Name: "from",
|
||||
Value: "priv_validator.json",
|
||||
Usage: "Path to a private key to sign the transaction",
|
||||
}
|
||||
|
||||
seqFlag = cli.IntFlag{
|
||||
SeqFlag = cli.IntFlag{
|
||||
Name: "sequence",
|
||||
Value: 0,
|
||||
Usage: "Sequence number for the account",
|
||||
}
|
||||
|
||||
coinFlag = cli.StringFlag{
|
||||
CoinFlag = cli.StringFlag{
|
||||
Name: "coin",
|
||||
Value: "blank",
|
||||
Usage: "Specify a coin denomination",
|
||||
}
|
||||
|
||||
gasFlag = cli.IntFlag{
|
||||
GasFlag = cli.IntFlag{
|
||||
Name: "gas",
|
||||
Value: 0,
|
||||
Usage: "The amount of gas for the transaction",
|
||||
}
|
||||
|
||||
feeFlag = cli.IntFlag{
|
||||
FeeFlag = cli.IntFlag{
|
||||
Name: "fee",
|
||||
Value: 0,
|
||||
Usage: "The transaction fee",
|
||||
}
|
||||
|
||||
dataFlag = cli.StringFlag{
|
||||
DataFlag = cli.StringFlag{
|
||||
Name: "data",
|
||||
Value: "",
|
||||
Usage: "Data to send with the transaction",
|
||||
}
|
||||
|
||||
nameFlag = cli.StringFlag{
|
||||
NameFlag = cli.StringFlag{
|
||||
Name: "name",
|
||||
Value: "",
|
||||
Usage: "Plugin to send the transaction to",
|
||||
}
|
||||
|
||||
chainIDFlag = cli.StringFlag{
|
||||
ChainIDFlag = cli.StringFlag{
|
||||
Name: "chain_id",
|
||||
Value: "test_chain_id",
|
||||
Usage: "ID of the chain for replay protection",
|
||||
}
|
||||
|
||||
validFlag = cli.BoolFlag{
|
||||
ValidFlag = cli.BoolFlag{
|
||||
Name: "valid",
|
||||
Usage: "Set valid field in CounterTx",
|
||||
}
|
||||
|
@ -120,73 +115,73 @@ var (
|
|||
|
||||
// ibc flags
|
||||
var (
|
||||
ibcChainIDFlag = cli.StringFlag{
|
||||
IbcChainIDFlag = cli.StringFlag{
|
||||
Name: "chain_id",
|
||||
Usage: "ChainID for the new blockchain",
|
||||
Value: "",
|
||||
}
|
||||
|
||||
ibcGenesisFlag = cli.StringFlag{
|
||||
IbcGenesisFlag = cli.StringFlag{
|
||||
Name: "genesis",
|
||||
Usage: "Genesis file for the new blockchain",
|
||||
Value: "",
|
||||
}
|
||||
|
||||
ibcHeaderFlag = cli.StringFlag{
|
||||
IbcHeaderFlag = cli.StringFlag{
|
||||
Name: "header",
|
||||
Usage: "Block header for an ibc update",
|
||||
Value: "",
|
||||
}
|
||||
|
||||
ibcCommitFlag = cli.StringFlag{
|
||||
IbcCommitFlag = cli.StringFlag{
|
||||
Name: "commit",
|
||||
Usage: "Block commit for an ibc update",
|
||||
Value: "",
|
||||
}
|
||||
|
||||
ibcFromFlag = cli.StringFlag{
|
||||
IbcFromFlag = cli.StringFlag{
|
||||
Name: "from",
|
||||
Usage: "Source ChainID",
|
||||
Value: "",
|
||||
}
|
||||
|
||||
ibcToFlag = cli.StringFlag{
|
||||
IbcToFlag = cli.StringFlag{
|
||||
Name: "to",
|
||||
Usage: "Destination ChainID",
|
||||
Value: "",
|
||||
}
|
||||
|
||||
ibcTypeFlag = cli.StringFlag{
|
||||
IbcTypeFlag = cli.StringFlag{
|
||||
Name: "type",
|
||||
Usage: "IBC packet type (eg. coin)",
|
||||
Value: "",
|
||||
}
|
||||
|
||||
ibcPayloadFlag = cli.StringFlag{
|
||||
IbcPayloadFlag = cli.StringFlag{
|
||||
Name: "payload",
|
||||
Usage: "IBC packet payload",
|
||||
Value: "",
|
||||
}
|
||||
|
||||
ibcPacketFlag = cli.StringFlag{
|
||||
IbcPacketFlag = cli.StringFlag{
|
||||
Name: "packet",
|
||||
Usage: "hex-encoded IBC packet",
|
||||
Value: "",
|
||||
}
|
||||
|
||||
ibcProofFlag = cli.StringFlag{
|
||||
IbcProofFlag = cli.StringFlag{
|
||||
Name: "proof",
|
||||
Usage: "hex-encoded proof of IBC packet from source chain",
|
||||
Value: "",
|
||||
}
|
||||
|
||||
ibcSequenceFlag = cli.IntFlag{
|
||||
IbcSequenceFlag = cli.IntFlag{
|
||||
Name: "sequence",
|
||||
Usage: "sequence number for IBC packet",
|
||||
Value: 0,
|
||||
}
|
||||
|
||||
ibcHeightFlag = cli.IntFlag{
|
||||
IbcHeightFlag = cli.IntFlag{
|
||||
Name: "height",
|
||||
Usage: "Height the packet became egress in source chain",
|
||||
Value: 0,
|
||||
|
@ -195,25 +190,25 @@ var (
|
|||
|
||||
// proof flags
|
||||
var (
|
||||
proofFlag = cli.StringFlag{
|
||||
ProofFlag = cli.StringFlag{
|
||||
Name: "proof",
|
||||
Usage: "hex-encoded IAVL proof",
|
||||
Value: "",
|
||||
}
|
||||
|
||||
keyFlag = cli.StringFlag{
|
||||
KeyFlag = cli.StringFlag{
|
||||
Name: "key",
|
||||
Usage: "key to the IAVL tree",
|
||||
Value: "",
|
||||
}
|
||||
|
||||
valueFlag = cli.StringFlag{
|
||||
ValueFlag = cli.StringFlag{
|
||||
Name: "value",
|
||||
Usage: "value in the IAVL tree",
|
||||
Value: "",
|
||||
}
|
||||
|
||||
rootFlag = cli.StringFlag{
|
||||
RootFlag = cli.StringFlag{
|
||||
Name: "root",
|
||||
Usage: "root hash of the IAVL tree",
|
||||
Value: "",
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package commands
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
@ -16,6 +16,98 @@ import (
|
|||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
var (
|
||||
IbcCmd = cli.Command{
|
||||
Name: "ibc",
|
||||
Usage: "Send a transaction to the interblockchain (ibc) plugin",
|
||||
Flags: []cli.Flag{
|
||||
NodeFlag,
|
||||
ChainIDFlag,
|
||||
|
||||
FromFlag,
|
||||
|
||||
AmountFlag,
|
||||
CoinFlag,
|
||||
GasFlag,
|
||||
FeeFlag,
|
||||
SeqFlag,
|
||||
|
||||
NameFlag,
|
||||
DataFlag,
|
||||
},
|
||||
Subcommands: []cli.Command{
|
||||
IbcRegisterTxCmd,
|
||||
IbcUpdateTxCmd,
|
||||
IbcPacketTxCmd,
|
||||
},
|
||||
}
|
||||
|
||||
IbcRegisterTxCmd = cli.Command{
|
||||
Name: "register",
|
||||
Usage: "Register a blockchain via IBC",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdIBCRegisterTx(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
IbcChainIDFlag,
|
||||
IbcGenesisFlag,
|
||||
},
|
||||
}
|
||||
|
||||
IbcUpdateTxCmd = cli.Command{
|
||||
Name: "update",
|
||||
Usage: "Update the latest state of a blockchain via IBC",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdIBCUpdateTx(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
IbcHeaderFlag,
|
||||
IbcCommitFlag,
|
||||
},
|
||||
}
|
||||
|
||||
IbcPacketTxCmd = cli.Command{
|
||||
Name: "packet",
|
||||
Usage: "Send a new packet via IBC",
|
||||
Flags: []cli.Flag{
|
||||
//
|
||||
},
|
||||
Subcommands: []cli.Command{
|
||||
IbcPacketCreateTx,
|
||||
IbcPacketPostTx,
|
||||
},
|
||||
}
|
||||
|
||||
IbcPacketCreateTx = cli.Command{
|
||||
Name: "create",
|
||||
Usage: "Create an egress IBC packet",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdIBCPacketCreateTx(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
IbcFromFlag,
|
||||
IbcToFlag,
|
||||
IbcTypeFlag,
|
||||
IbcPayloadFlag,
|
||||
IbcSequenceFlag,
|
||||
},
|
||||
}
|
||||
|
||||
IbcPacketPostTx = cli.Command{
|
||||
Name: "post",
|
||||
Usage: "Deliver an IBC packet to another chain",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdIBCPacketPostTx(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
IbcFromFlag,
|
||||
IbcHeightFlag,
|
||||
IbcPacketFlag,
|
||||
IbcProofFlag,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func cmdIBCRegisterTx(c *cli.Context) error {
|
||||
chainID := c.String("chain_id")
|
||||
genesisFile := c.String("genesis")
|
||||
|
@ -40,15 +132,15 @@ func cmdIBCRegisterTx(c *cli.Context) error {
|
|||
}{ibcTx}))
|
||||
name := "IBC"
|
||||
|
||||
return appTx(parent, name, data)
|
||||
return AppTx(parent, name, data)
|
||||
}
|
||||
|
||||
func cmdIBCUpdateTx(c *cli.Context) error {
|
||||
headerBytes, err := hex.DecodeString(stripHex(c.String("header")))
|
||||
headerBytes, err := hex.DecodeString(StripHex(c.String("header")))
|
||||
if err != nil {
|
||||
return errors.New(cmn.Fmt("Header (%v) is invalid hex: %v", c.String("header"), err))
|
||||
}
|
||||
commitBytes, err := hex.DecodeString(stripHex(c.String("commit")))
|
||||
commitBytes, err := hex.DecodeString(StripHex(c.String("commit")))
|
||||
if err != nil {
|
||||
return errors.New(cmn.Fmt("Commit (%v) is invalid hex: %v", c.String("commit"), err))
|
||||
}
|
||||
|
@ -75,14 +167,14 @@ func cmdIBCUpdateTx(c *cli.Context) error {
|
|||
}{ibcTx}))
|
||||
name := "IBC"
|
||||
|
||||
return appTx(c.Parent(), name, data)
|
||||
return AppTx(c.Parent(), name, data)
|
||||
}
|
||||
|
||||
func cmdIBCPacketCreateTx(c *cli.Context) error {
|
||||
fromChain, toChain := c.String("from"), c.String("to")
|
||||
packetType := c.String("type")
|
||||
|
||||
payloadBytes, err := hex.DecodeString(stripHex(c.String("payload")))
|
||||
payloadBytes, err := hex.DecodeString(StripHex(c.String("payload")))
|
||||
if err != nil {
|
||||
return errors.New(cmn.Fmt("Payload (%v) is invalid hex: %v", c.String("payload"), err))
|
||||
}
|
||||
|
@ -108,17 +200,17 @@ func cmdIBCPacketCreateTx(c *cli.Context) error {
|
|||
ibc.IBCTx `json:"unwrap"`
|
||||
}{ibcTx}))
|
||||
|
||||
return appTx(c.Parent().Parent(), "IBC", data)
|
||||
return AppTx(c.Parent().Parent(), "IBC", data)
|
||||
}
|
||||
|
||||
func cmdIBCPacketPostTx(c *cli.Context) error {
|
||||
fromChain, fromHeight := c.String("from"), c.Int("height")
|
||||
|
||||
packetBytes, err := hex.DecodeString(stripHex(c.String("packet")))
|
||||
packetBytes, err := hex.DecodeString(StripHex(c.String("packet")))
|
||||
if err != nil {
|
||||
return errors.New(cmn.Fmt("Packet (%v) is invalid hex: %v", c.String("packet"), err))
|
||||
}
|
||||
proofBytes, err := hex.DecodeString(stripHex(c.String("proof")))
|
||||
proofBytes, err := hex.DecodeString(StripHex(c.String("proof")))
|
||||
if err != nil {
|
||||
return errors.New(cmn.Fmt("Proof (%v) is invalid hex: %v", c.String("proof"), err))
|
||||
}
|
||||
|
@ -146,7 +238,7 @@ func cmdIBCPacketPostTx(c *cli.Context) error {
|
|||
ibc.IBCTx `json:"unwrap"`
|
||||
}{ibcTx}))
|
||||
|
||||
return appTx(c.Parent().Parent(), "IBC", data)
|
||||
return AppTx(c.Parent().Parent(), "IBC", data)
|
||||
}
|
||||
|
||||
func getIBCSequence(c *cli.Context) (uint64, error) {
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package commands
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
@ -14,6 +14,58 @@ import (
|
|||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
var (
|
||||
QueryCmd = cli.Command{
|
||||
Name: "query",
|
||||
Usage: "Query the merkle tree",
|
||||
ArgsUsage: "<key>",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdQuery(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
NodeFlag,
|
||||
},
|
||||
}
|
||||
|
||||
AccountCmd = cli.Command{
|
||||
Name: "account",
|
||||
Usage: "Get details of an account",
|
||||
ArgsUsage: "<address>",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdAccount(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
NodeFlag,
|
||||
},
|
||||
}
|
||||
|
||||
BlockCmd = cli.Command{
|
||||
Name: "block",
|
||||
Usage: "Get the header and commit of a block",
|
||||
ArgsUsage: "<height>",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdBlock(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
NodeFlag,
|
||||
},
|
||||
}
|
||||
|
||||
VerifyCmd = cli.Command{
|
||||
Name: "verify",
|
||||
Usage: "Verify the IAVL proof",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdVerify(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
ProofFlag,
|
||||
KeyFlag,
|
||||
ValueFlag,
|
||||
RootFlag,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func cmdQuery(c *cli.Context) error {
|
||||
if len(c.Args()) != 1 {
|
||||
return errors.New("query command requires an argument ([key])")
|
||||
|
@ -23,7 +75,7 @@ func cmdQuery(c *cli.Context) error {
|
|||
if isHex(keyString) {
|
||||
// convert key to bytes
|
||||
var err error
|
||||
key, err = hex.DecodeString(stripHex(keyString))
|
||||
key, err = hex.DecodeString(StripHex(keyString))
|
||||
if err != nil {
|
||||
return errors.New(cmn.Fmt("Query key (%v) is invalid hex: %v", keyString, err))
|
||||
}
|
||||
|
@ -55,7 +107,7 @@ func cmdAccount(c *cli.Context) error {
|
|||
if len(c.Args()) != 1 {
|
||||
return errors.New("account command requires an argument ([address])")
|
||||
}
|
||||
addrHex := stripHex(c.Args()[0])
|
||||
addrHex := StripHex(c.Args()[0])
|
||||
|
||||
// convert destination address to bytes
|
||||
addr, err := hex.DecodeString(addrHex)
|
||||
|
@ -123,7 +175,7 @@ func cmdVerify(c *cli.Context) error {
|
|||
var err error
|
||||
key := []byte(keyString)
|
||||
if isHex(keyString) {
|
||||
key, err = hex.DecodeString(stripHex(keyString))
|
||||
key, err = hex.DecodeString(StripHex(keyString))
|
||||
if err != nil {
|
||||
return errors.New(cmn.Fmt("Key (%v) is invalid hex: %v", keyString, err))
|
||||
}
|
||||
|
@ -131,18 +183,18 @@ func cmdVerify(c *cli.Context) error {
|
|||
|
||||
value := []byte(valueString)
|
||||
if isHex(valueString) {
|
||||
value, err = hex.DecodeString(stripHex(valueString))
|
||||
value, err = hex.DecodeString(StripHex(valueString))
|
||||
if err != nil {
|
||||
return errors.New(cmn.Fmt("Value (%v) is invalid hex: %v", valueString, err))
|
||||
}
|
||||
}
|
||||
|
||||
root, err := hex.DecodeString(stripHex(c.String("root")))
|
||||
root, err := hex.DecodeString(StripHex(c.String("root")))
|
||||
if err != nil {
|
||||
return errors.New(cmn.Fmt("Root (%v) is invalid hex: %v", c.String("root"), err))
|
||||
}
|
||||
|
||||
proofBytes, err := hex.DecodeString(stripHex(c.String("proof")))
|
||||
proofBytes, err := hex.DecodeString(StripHex(c.String("proof")))
|
||||
if err != nil {
|
||||
return errors.New(cmn.Fmt("Proof (%v) is invalid hex: %v", c.String("proof"), err))
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package commands
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
@ -19,14 +19,45 @@ import (
|
|||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/tendermint/basecoin/app"
|
||||
"github.com/tendermint/basecoin/plugins/counter"
|
||||
"github.com/tendermint/basecoin/plugins/ibc"
|
||||
"github.com/tendermint/basecoin/types"
|
||||
)
|
||||
|
||||
var config cfg.Config
|
||||
|
||||
const EyesCacheSize = 10000
|
||||
|
||||
var StartCmd = cli.Command{
|
||||
Name: "start",
|
||||
Usage: "Start basecoin",
|
||||
ArgsUsage: "",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdStart(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
AddrFlag,
|
||||
EyesFlag,
|
||||
DirFlag,
|
||||
InProcTMFlag,
|
||||
ChainIDFlag,
|
||||
IbcPluginFlag,
|
||||
// CounterPluginFlag,
|
||||
},
|
||||
}
|
||||
|
||||
type plugin struct {
|
||||
name string
|
||||
init func() types.Plugin
|
||||
}
|
||||
|
||||
var plugins = []plugin{}
|
||||
|
||||
// RegisterStartPlugin is used to add another
|
||||
func RegisterStartPlugin(flag cli.BoolFlag, init func() types.Plugin) {
|
||||
StartCmd.Flags = append(StartCmd.Flags, flag)
|
||||
plugins = append(plugins, plugin{name: flag.GetName(), init: init})
|
||||
}
|
||||
|
||||
func cmdStart(c *cli.Context) error {
|
||||
|
||||
// Connect to MerkleEyes
|
||||
|
@ -43,14 +74,15 @@ func cmdStart(c *cli.Context) error {
|
|||
|
||||
// Create Basecoin app
|
||||
basecoinApp := app.NewBasecoin(eyesCli)
|
||||
|
||||
if c.Bool("counter-plugin") {
|
||||
basecoinApp.RegisterPlugin(counter.New("counter"))
|
||||
}
|
||||
|
||||
if c.Bool("ibc-plugin") {
|
||||
basecoinApp.RegisterPlugin(ibc.New())
|
||||
}
|
||||
|
||||
// loop through all registered plugins and enable if desired
|
||||
for _, p := range plugins {
|
||||
if c.Bool(p.name) {
|
||||
basecoinApp.RegisterPlugin(p.init())
|
||||
}
|
||||
}
|
||||
|
||||
// If genesis file exists, set key-value options
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package commands
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
@ -7,7 +7,6 @@ import (
|
|||
|
||||
"github.com/urfave/cli"
|
||||
|
||||
"github.com/tendermint/basecoin/plugins/counter"
|
||||
"github.com/tendermint/basecoin/types"
|
||||
|
||||
cmn "github.com/tendermint/go-common"
|
||||
|
@ -17,6 +16,63 @@ import (
|
|||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
)
|
||||
|
||||
var (
|
||||
SendTxCmd = cli.Command{
|
||||
Name: "sendtx",
|
||||
Usage: "Broadcast a basecoin SendTx",
|
||||
ArgsUsage: "",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdSendTx(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
NodeFlag,
|
||||
ChainIDFlag,
|
||||
|
||||
FromFlag,
|
||||
|
||||
AmountFlag,
|
||||
CoinFlag,
|
||||
GasFlag,
|
||||
FeeFlag,
|
||||
SeqFlag,
|
||||
|
||||
ToFlag,
|
||||
},
|
||||
}
|
||||
|
||||
AppTxCmd = cli.Command{
|
||||
Name: "apptx",
|
||||
Usage: "Broadcast a basecoin AppTx",
|
||||
ArgsUsage: "",
|
||||
Action: func(c *cli.Context) error {
|
||||
return cmdAppTx(c)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
NodeFlag,
|
||||
ChainIDFlag,
|
||||
|
||||
FromFlag,
|
||||
|
||||
AmountFlag,
|
||||
CoinFlag,
|
||||
GasFlag,
|
||||
FeeFlag,
|
||||
SeqFlag,
|
||||
|
||||
NameFlag,
|
||||
DataFlag,
|
||||
},
|
||||
// Subcommands are dynamically registered with plugins as needed
|
||||
Subcommands: []cli.Command{},
|
||||
}
|
||||
)
|
||||
|
||||
// RegisterTxPlugin is used to add another subcommand and create a custom
|
||||
// apptx encoding. Look at counter.go for an example
|
||||
func RegisterTxPlugin(cmd cli.Command) {
|
||||
AppTxCmd.Subcommands = append(AppTxCmd.Subcommands, cmd)
|
||||
}
|
||||
|
||||
func cmdSendTx(c *cli.Context) error {
|
||||
toHex := c.String("to")
|
||||
fromFile := c.String("from")
|
||||
|
@ -26,7 +82,7 @@ func cmdSendTx(c *cli.Context) error {
|
|||
chainID := c.String("chain_id")
|
||||
|
||||
// convert destination address to bytes
|
||||
to, err := hex.DecodeString(stripHex(toHex))
|
||||
to, err := hex.DecodeString(StripHex(toHex))
|
||||
if err != nil {
|
||||
return errors.New("To address is invalid hex: " + err.Error())
|
||||
}
|
||||
|
@ -73,10 +129,10 @@ func cmdAppTx(c *cli.Context) error {
|
|||
data, _ = hex.DecodeString(dataString)
|
||||
}
|
||||
name := c.String("name")
|
||||
return appTx(c, name, data)
|
||||
return AppTx(c, name, data)
|
||||
}
|
||||
|
||||
func appTx(c *cli.Context, name string, data []byte) error {
|
||||
func AppTx(c *cli.Context, name string, data []byte) error {
|
||||
fromFile := c.String("from")
|
||||
amount := int64(c.Int("amount"))
|
||||
coin := c.String("coin")
|
||||
|
@ -111,28 +167,6 @@ func appTx(c *cli.Context, name string, data []byte) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func cmdCounterTx(c *cli.Context) error {
|
||||
valid := c.Bool("valid")
|
||||
parent := c.Parent()
|
||||
|
||||
counterTx := counter.CounterTx{
|
||||
Valid: valid,
|
||||
Fee: types.Coins{
|
||||
{
|
||||
Denom: parent.String("coin"),
|
||||
Amount: int64(parent.Int("fee")),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Println("CounterTx:", string(wire.JSONBytes(counterTx)))
|
||||
|
||||
data := wire.BinaryBytes(counterTx)
|
||||
name := "counter"
|
||||
|
||||
return appTx(parent, name, data)
|
||||
}
|
||||
|
||||
// broadcast the transaction to tendermint
|
||||
func broadcastTx(c *cli.Context, tx types.Tx) ([]byte, error) {
|
||||
tmResult := new(ctypes.TMResult)
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package commands
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
@ -28,7 +28,7 @@ func isHex(s string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func stripHex(s string) string {
|
||||
func StripHex(s string) string {
|
||||
if isHex(s) {
|
||||
return s[2:]
|
||||
}
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"os"
|
||||
|
||||
"github.com/tendermint/basecoin/cmd/basecoin/commands"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
|
@ -12,14 +13,14 @@ func main() {
|
|||
app.Usage = "basecoin [command] [args...]"
|
||||
app.Version = "0.1.0"
|
||||
app.Commands = []cli.Command{
|
||||
startCmd,
|
||||
sendTxCmd,
|
||||
appTxCmd,
|
||||
ibcCmd,
|
||||
queryCmd,
|
||||
verifyCmd,
|
||||
blockCmd,
|
||||
accountCmd,
|
||||
commands.StartCmd,
|
||||
commands.SendTxCmd,
|
||||
commands.AppTxCmd,
|
||||
commands.IbcCmd,
|
||||
commands.QueryCmd,
|
||||
commands.VerifyCmd,
|
||||
commands.BlockCmd,
|
||||
commands.AccountCmd,
|
||||
}
|
||||
app.Run(os.Args)
|
||||
}
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"github.com/tendermint/abci/server"
|
||||
"github.com/tendermint/basecoin/app"
|
||||
"github.com/tendermint/basecoin/plugins/counter"
|
||||
cmn "github.com/tendermint/go-common"
|
||||
eyes "github.com/tendermint/merkleeyes/client"
|
||||
)
|
||||
|
||||
func main() {
|
||||
addrPtr := flag.String("address", "tcp://0.0.0.0:46658", "Listen address")
|
||||
eyesPtr := flag.String("eyes", "local", "MerkleEyes address, or 'local' for embedded")
|
||||
genFilePath := flag.String("genesis", "", "Genesis file, if any")
|
||||
flag.Parse()
|
||||
|
||||
// Connect to MerkleEyes
|
||||
eyesCli, err := eyes.NewClient(*eyesPtr)
|
||||
if err != nil {
|
||||
cmn.Exit("connect to MerkleEyes: " + err.Error())
|
||||
}
|
||||
|
||||
// Create Basecoin app
|
||||
app := app.NewBasecoin(eyesCli)
|
||||
|
||||
// add plugins
|
||||
// TODO: add some more, like the cool voting app
|
||||
counter := counter.New("counter")
|
||||
app.RegisterPlugin(counter)
|
||||
|
||||
// If genesis file was specified, set key-value options
|
||||
if *genFilePath != "" {
|
||||
err := app.LoadGenesis(*genFilePath)
|
||||
if err != nil {
|
||||
cmn.Exit(cmn.Fmt("%+v", err))
|
||||
}
|
||||
}
|
||||
|
||||
// Start the listener
|
||||
svr, err := server.NewServer(*addrPtr, "socket", app)
|
||||
if err != nil {
|
||||
cmn.Exit("create listener: " + err.Error())
|
||||
}
|
||||
|
||||
// Wait forever
|
||||
cmn.TrapSignal(func() {
|
||||
// Cleanup
|
||||
svr.Stop()
|
||||
})
|
||||
|
||||
}
|
Loading…
Reference in New Issue