Merge pull request #140 from tendermint/feature/132-earlier-sign

Add Signers in ReadAppTxFlags
This commit is contained in:
Ethan Frey 2017-06-26 18:18:53 +02:00 committed by GitHub
commit 648bcd05bb
2 changed files with 19 additions and 24 deletions

View File

@ -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 {

View File

@ -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
}