From fc36b216696f5d956ab99d8f2a61cb73d6bf8481 Mon Sep 17 00:00:00 2001 From: rigel rozanski Date: Fri, 23 Jun 2017 17:50:54 -0400 Subject: [PATCH] Add Signers in ReadAppTxFlags --- cmd/basecli/commands/apptx.go | 18 +----------------- cmd/basecli/commands/cmds.go | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/cmd/basecli/commands/apptx.go b/cmd/basecli/commands/apptx.go index acfc5932d..6b18d52e5 100644 --- a/cmd/basecli/commands/apptx.go +++ b/cmd/basecli/commands/apptx.go @@ -10,6 +10,7 @@ import ( bc "github.com/tendermint/basecoin/types" ) +// AppTx Application transaction structure for client type AppTx struct { chainID string signers []crypto.PubKey @@ -58,23 +59,6 @@ func (s *AppTx) TxBytes() ([]byte, error) { return txBytes, nil } -// AddSigner sets address and pubkey info on the tx based on the key that -// will be used for signing -func (a *AppTx) AddSigner(pk crypto.PubKey) { - // get addr if available - var addr []byte - if !pk.Empty() { - addr = pk.Address() - } - - // set the send address, and pubkey if needed - in := &a.Tx.Input - in.Address = addr - if in.Sequence == 1 { - in.PubKey = pk - } -} - // TODO: this should really be in the basecoin.types SendTx, // but that code is too ugly now, needs refactor.. func (a *AppTx) ValidateBasic() error { diff --git a/cmd/basecli/commands/cmds.go b/cmd/basecli/commands/cmds.go index 8ac60bced..e71a8a35f 100644 --- a/cmd/basecli/commands/cmds.go +++ b/cmd/basecli/commands/cmds.go @@ -143,12 +143,8 @@ func parseChainAddress(toFlag string) ([]byte, error) { // BroadcastAppTx wraps, signs, and executes an app tx basecoin transaction func BroadcastAppTx(tx *btypes.AppTx) (*ctypes.ResultBroadcastTxCommit, error) { - // Generate app transaction to be broadcast - appTx := WrapAppTx(tx) - appTx.AddSigner(txcmd.GetSigner()) - // Sign if needed and post to the node. This it the work-horse - return txcmd.SignAndPostTx(appTx) + return txcmd.SignAndPostTx(WrapAppTx(tx)) } // AddAppTxFlags adds flags required by apptx @@ -172,17 +168,32 @@ func ReadAppTxFlags() (gas int64, fee btypes.Coin, txInput btypes.TxInput, err e return } - // craft the inputs + // retrieve the amount var amount btypes.Coins amount, err = btypes.ParseCoins(viper.GetString(FlagAmount)) if err != nil { return } + + // get the PubKey of the signer + pk := txcmd.GetSigner() + + // get addr if available + var addr []byte + if !pk.Empty() { + addr = pk.Address() + } + + // set the output txInput = btypes.TxInput{ Coins: amount, Sequence: viper.GetInt(FlagSequence), + Address: addr, + } + // set the pubkey if needed + if txInput.Sequence == 1 { + txInput.PubKey = pk } - return }