Merge pull request #140 from tendermint/feature/132-earlier-sign
Add Signers in ReadAppTxFlags
This commit is contained in:
commit
648bcd05bb
|
@ -10,6 +10,7 @@ import (
|
||||||
bc "github.com/tendermint/basecoin/types"
|
bc "github.com/tendermint/basecoin/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// AppTx Application transaction structure for client
|
||||||
type AppTx struct {
|
type AppTx struct {
|
||||||
chainID string
|
chainID string
|
||||||
signers []crypto.PubKey
|
signers []crypto.PubKey
|
||||||
|
@ -58,23 +59,6 @@ func (s *AppTx) TxBytes() ([]byte, error) {
|
||||||
return txBytes, nil
|
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,
|
// TODO: this should really be in the basecoin.types SendTx,
|
||||||
// but that code is too ugly now, needs refactor..
|
// but that code is too ugly now, needs refactor..
|
||||||
func (a *AppTx) ValidateBasic() error {
|
func (a *AppTx) ValidateBasic() error {
|
||||||
|
|
|
@ -143,12 +143,8 @@ func parseChainAddress(toFlag string) ([]byte, error) {
|
||||||
// BroadcastAppTx wraps, signs, and executes an app tx basecoin transaction
|
// BroadcastAppTx wraps, signs, and executes an app tx basecoin transaction
|
||||||
func BroadcastAppTx(tx *btypes.AppTx) (*ctypes.ResultBroadcastTxCommit, error) {
|
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
|
// 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
|
// AddAppTxFlags adds flags required by apptx
|
||||||
|
@ -172,17 +168,32 @@ func ReadAppTxFlags() (gas int64, fee btypes.Coin, txInput btypes.TxInput, err e
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// craft the inputs
|
// retrieve the amount
|
||||||
var amount btypes.Coins
|
var amount btypes.Coins
|
||||||
amount, err = btypes.ParseCoins(viper.GetString(FlagAmount))
|
amount, err = btypes.ParseCoins(viper.GetString(FlagAmount))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
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{
|
txInput = btypes.TxInput{
|
||||||
Coins: amount,
|
Coins: amount,
|
||||||
Sequence: viper.GetInt(FlagSequence),
|
Sequence: viper.GetInt(FlagSequence),
|
||||||
|
Address: addr,
|
||||||
|
}
|
||||||
|
// set the pubkey if needed
|
||||||
|
if txInput.Sequence == 1 {
|
||||||
|
txInput.PubKey = pk
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue