From a57e2d34b1b0e4d1558615ecfb88f019464571bf Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 16 Jun 2017 20:42:41 +0200 Subject: [PATCH] Remove remnants of basecoin tx as ibc functions are now under relay --- cmd/basecoin/main.go | 1 - cmd/commands/ibc.go | 81 +------------------- cmd/commands/plugin_util.go | 5 -- cmd/commands/relay.go | 2 +- cmd/commands/tx.go | 142 ------------------------------------ cmd/counter/cmd.go | 48 ------------ cmd/counter/main.go | 1 - 7 files changed, 2 insertions(+), 278 deletions(-) delete mode 100644 cmd/commands/tx.go diff --git a/cmd/basecoin/main.go b/cmd/basecoin/main.go index f95eb93438f..5d74ae5585a 100644 --- a/cmd/basecoin/main.go +++ b/cmd/basecoin/main.go @@ -19,7 +19,6 @@ func main() { commands.InitCmd, commands.StartCmd, commands.RelayCmd, - commands.TxCmd, commands.UnsafeResetAllCmd, commands.VersionCmd, ) diff --git a/cmd/commands/ibc.go b/cmd/commands/ibc.go index ddde46825e7..b76eae90236 100644 --- a/cmd/commands/ibc.go +++ b/cmd/commands/ibc.go @@ -1,87 +1,8 @@ package commands -import ( - "encoding/json" - "fmt" - "io/ioutil" - - "github.com/pkg/errors" - "github.com/spf13/cobra" - - "github.com/tendermint/basecoin/plugins/ibc" - - "github.com/tendermint/go-wire" -) +import "github.com/tendermint/basecoin/plugins/ibc" // returns a new IBC plugin to be registered with Basecoin func NewIBCPlugin() *ibc.IBCPlugin { return ibc.New() } - -//commands -var ( - IBCTxCmd = &cobra.Command{ - Use: "ibc", - Short: "An IBC transaction, for InterBlockchain Communication", - } - - IBCRegisterTxCmd = &cobra.Command{ - Use: "register", - Short: "Register a blockchain via IBC", - RunE: ibcRegisterTxCmd, - } -) - -//flags -var ( - ibcChainIDFlag string - ibcGenesisFlag string -) - -func init() { - // register flags - registerFlags := []Flag2Register{ - {&ibcChainIDFlag, "ibc_chain_id", "", "ChainID for the new blockchain"}, - {&ibcGenesisFlag, "genesis", "", "Genesis file for the new blockchain"}, - } - - RegisterFlags(IBCRegisterTxCmd, registerFlags) - - //register commands - IBCTxCmd.AddCommand(IBCRegisterTxCmd) - RegisterTxSubcommand(IBCTxCmd) -} - -//--------------------------------------------------------------------- -// ibc command implementations - -func ibcRegisterTxCmd(cmd *cobra.Command, args []string) error { - chainID := ibcChainIDFlag - genesisFile := ibcGenesisFlag - - genesisBytes, err := ioutil.ReadFile(genesisFile) - if err != nil { - return errors.Errorf("Error reading genesis file %v: %v\n", genesisFile, err) - } - - ibcTx := ibc.IBCRegisterChainTx{ - ibc.BlockchainGenesis{ - ChainID: chainID, - Genesis: string(genesisBytes), - }, - } - - out, err := json.Marshal(ibcTx) - if err != nil { - return err - } - - fmt.Printf("IBCTx: %s\n", string(out)) - - data := []byte(wire.BinaryBytes(struct { - ibc.IBCTx `json:"unwrap"` - }{ibcTx})) - name := "IBC" - - return AppTx(name, data) -} diff --git a/cmd/commands/plugin_util.go b/cmd/commands/plugin_util.go index 43afd93c284..d4f47b323a2 100644 --- a/cmd/commands/plugin_util.go +++ b/cmd/commands/plugin_util.go @@ -19,11 +19,6 @@ func RegisterStartPlugin(name string, newPlugin func() types.Plugin) { plugins = append(plugins, plugin{name: name, newPlugin: newPlugin}) } -// Register a subcommand of TxCmd to craft transactions for plugins -func RegisterTxSubcommand(cmd *cobra.Command) { - TxCmd.AddCommand(cmd) -} - //Returns a version command based on version input func QuickVersionCmd(version string) *cobra.Command { return &cobra.Command{ diff --git a/cmd/commands/relay.go b/cmd/commands/relay.go index 573a53bbfc6..b9ae47afa4a 100644 --- a/cmd/commands/relay.go +++ b/cmd/commands/relay.go @@ -118,7 +118,7 @@ func loop(addr1, addr2, id1, id2 string) { nextSeq := 0 // load the priv key - privKey, err := LoadKey(fromFlag) + privKey, err := LoadKey(fromFileFlag) if err != nil { logger.Error(err.Error()) cmn.PanicCrisis(err.Error()) diff --git a/cmd/commands/tx.go b/cmd/commands/tx.go deleted file mode 100644 index 8c661568c5d..00000000000 --- a/cmd/commands/tx.go +++ /dev/null @@ -1,142 +0,0 @@ -package commands - -import ( - "fmt" - - "github.com/pkg/errors" - "github.com/spf13/cobra" - - "github.com/tendermint/basecoin/types" - - wire "github.com/tendermint/go-wire" - "github.com/tendermint/tendermint/rpc/client" -) - -//commands -var ( - TxCmd = &cobra.Command{ - Use: "tx", - Short: "Create, sign, and broadcast a transaction", - } -) - -var ( - //persistent flags - txNodeFlag string - amountFlag string - fromFlag string - seqFlag int - gasFlag int - feeFlag string - chainIDFlag string -) - -func init() { - - // register flags - cmdTxFlags := []Flag2Register{ - {&txNodeFlag, "node", "tcp://localhost:46657", "Tendermint RPC address"}, - {&chainIDFlag, "chain_id", "test_chain_id", "ID of the chain for replay protection"}, - {&fromFlag, "from", "key.json", "Path to a private key to sign the transaction"}, - {&amountFlag, "amount", "", "Coins to send in transaction of the format ,,... (eg: 1btc,2gold,5silver)"}, - {&gasFlag, "gas", 0, "The amount of gas for the transaction"}, - {&feeFlag, "fee", "0coin", "Coins for the transaction fee of the format "}, - {&seqFlag, "sequence", -1, "Sequence number for the account (-1 to autocalculate)"}, - } - RegisterPersistentFlags(TxCmd, cmdTxFlags) -} - -func AppTx(name string, data []byte) error { - - privKey, err := LoadKey(fromFlag) - if err != nil { - return err - } - - sequence, err := getSeq(privKey.Address[:]) - if err != nil { - return err - } - - //parse the fee and amounts into coin types - feeCoin, err := types.ParseCoin(feeFlag) - if err != nil { - return err - } - - amountCoins, err := types.ParseCoins(amountFlag) - if err != nil { - return err - } - - input := types.NewTxInput(privKey.PubKey, amountCoins, sequence) - tx := &types.AppTx{ - Gas: int64(gasFlag), - Fee: feeCoin, - Name: name, - Input: input, - Data: data, - } - - tx.Input.Signature = privKey.Sign(tx.SignBytes(chainIDFlag)) - - out := wire.BinaryBytes(tx) - fmt.Println("Signed AppTx:") - fmt.Printf("%X\n", out) - - data, log, err := broadcastTx(tx) - if err != nil { - return err - } - fmt.Printf("Response: %X ; %s\n", data, log) - return nil -} - -// broadcast the transaction to tendermint -func broadcastTx(tx types.Tx) ([]byte, string, error) { - httpClient := client.NewHTTP(txNodeFlag, "/websocket") - // Don't you hate having to do this? - // How many times have I lost an hour over this trick?! - txBytes := []byte(wire.BinaryBytes(struct { - types.Tx `json:"unwrap"` - }{tx})) - res, err := httpClient.BroadcastTxCommit(txBytes) - if err != nil { - return nil, "", errors.Errorf("Error on broadcast tx: %v", err) - } - - // if it fails check, we don't even get a delivertx back! - if !res.CheckTx.Code.IsOK() { - r := res.CheckTx - return nil, "", errors.Errorf("BroadcastTxCommit got non-zero exit code: %v. %X; %s", r.Code, r.Data, r.Log) - } - - if !res.DeliverTx.Code.IsOK() { - r := res.DeliverTx - return nil, "", errors.Errorf("BroadcastTxCommit got non-zero exit code: %v. %X; %s", r.Code, r.Data, r.Log) - } - - return res.DeliverTx.Data, res.DeliverTx.Log, nil -} - -// if the sequence flag is set, return it; -// else, fetch the account by querying the app and return the sequence number -func getSeq(address []byte) (int, error) { - if seqFlag >= 0 { - return seqFlag, nil - } - - httpClient := client.NewHTTP(txNodeFlag, "/websocket") - acc, err := getAccWithClient(httpClient, address) - if err != nil { - return 0, err - } - return acc.Sequence + 1, nil -} - -func newOutput(to []byte, amount types.Coins) types.TxOutput { - return types.TxOutput{ - Address: to, - Coins: amount, - } -} diff --git a/cmd/counter/cmd.go b/cmd/counter/cmd.go index a8c543e1360..63431591bbd 100644 --- a/cmd/counter/cmd.go +++ b/cmd/counter/cmd.go @@ -1,59 +1,11 @@ package main import ( - "encoding/json" - "fmt" - - "github.com/spf13/cobra" - "github.com/spf13/viper" - wire "github.com/tendermint/go-wire" - "github.com/tendermint/basecoin/cmd/commands" "github.com/tendermint/basecoin/plugins/counter" "github.com/tendermint/basecoin/types" ) -//commands -var CounterTxCmd = &cobra.Command{ - Use: "counter", - Short: "Create, sign, and broadcast a transaction to the counter plugin", - RunE: counterTxCmd, -} - -const ( - flagValid = "valid" - flagCountFee = "countfee" -) - func init() { - - CounterTxCmd.Flags().Bool(flagValid, false, "Set valid field in CounterTx") - CounterTxCmd.Flags().String(flagCountFee, "", "Coins for the counter fee of the format ") - - commands.RegisterTxSubcommand(CounterTxCmd) commands.RegisterStartPlugin("counter", func() types.Plugin { return counter.New() }) } - -func counterTxCmd(cmd *cobra.Command, args []string) error { - - countFee, err := types.ParseCoins(viper.GetString(flagCountFee)) - if err != nil { - return err - } - - counterTx := counter.CounterTx{ - Valid: viper.GetBool(flagValid), - Fee: countFee, - } - - out, err := json.Marshal(counterTx) - if err != nil { - return err - } - fmt.Println("CounterTx:", string(out)) - - data := wire.BinaryBytes(counterTx) - name := "counter" - - return commands.AppTx(name, data) -} diff --git a/cmd/counter/main.go b/cmd/counter/main.go index e9694002944..11c16f8ebf7 100644 --- a/cmd/counter/main.go +++ b/cmd/counter/main.go @@ -18,7 +18,6 @@ func main() { RootCmd.AddCommand( commands.InitCmd, commands.StartCmd, - commands.TxCmd, commands.UnsafeResetAllCmd, commands.VersionCmd, )