Merge pull request #636 from cosmos/rigel/client-cleanup
StdSignMsg logic into common helper functions
This commit is contained in:
commit
df8f2ab2fa
|
@ -88,7 +88,16 @@ func GetFromAddress() (from sdk.Address, err error) {
|
|||
}
|
||||
|
||||
// sign and build the transaction from the msg
|
||||
func SignAndBuild(signMsg sdk.StdSignMsg, cdc *wire.Codec) ([]byte, error) {
|
||||
func SignAndBuild(msg sdk.Msg, cdc *wire.Codec) ([]byte, error) {
|
||||
|
||||
// build the Sign Messsage from the Standard Message
|
||||
chainID := viper.GetString(client.FlagChainID)
|
||||
sequence := int64(viper.GetInt(client.FlagSequence))
|
||||
signMsg := sdk.StdSignMsg{
|
||||
ChainID: chainID,
|
||||
Sequences: []int64{sequence},
|
||||
Msg: msg,
|
||||
}
|
||||
|
||||
keybase, err := keys.GetKeyBase()
|
||||
if err != nil {
|
||||
|
@ -121,8 +130,8 @@ func SignAndBuild(signMsg sdk.StdSignMsg, cdc *wire.Codec) ([]byte, error) {
|
|||
}
|
||||
|
||||
// sign and build the transaction from the msg
|
||||
func SignBuildBroadcast(signMsg sdk.StdSignMsg, cdc *wire.Codec) (*ctypes.ResultBroadcastTxCommit, error) {
|
||||
txBytes, err := SignAndBuild(signMsg, cdc)
|
||||
func SignBuildBroadcast(msg sdk.Msg, cdc *wire.Codec) (*ctypes.ResultBroadcastTxCommit, error) {
|
||||
txBytes, err := SignAndBuild(msg, cdc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -5,11 +5,8 @@ import (
|
|||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/builder"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/examples/basecoin/x/cool"
|
||||
|
@ -33,17 +30,9 @@ func QuizTxCmd(cdc *wire.Codec) *cobra.Command {
|
|||
|
||||
// create the message
|
||||
msg := cool.NewQuizMsg(from, args[0])
|
||||
chainID := viper.GetString(client.FlagChainID)
|
||||
sequence := int64(viper.GetInt(client.FlagSequence))
|
||||
|
||||
signMsg := sdk.StdSignMsg{
|
||||
ChainID: chainID,
|
||||
Sequences: []int64{sequence},
|
||||
Msg: msg,
|
||||
}
|
||||
|
||||
// build and sign the transaction, then broadcast to Tendermint
|
||||
res, err := builder.SignBuildBroadcast(signMsg, cdc)
|
||||
res, err := builder.SignBuildBroadcast(msg, cdc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -72,17 +61,9 @@ func SetTrendTxCmd(cdc *wire.Codec) *cobra.Command {
|
|||
|
||||
// create the message
|
||||
msg := cool.NewSetTrendMsg(from, args[0])
|
||||
chainID := viper.GetString(client.FlagChainID)
|
||||
sequence := int64(viper.GetInt(client.FlagSequence))
|
||||
|
||||
signMsg := sdk.StdSignMsg{
|
||||
ChainID: chainID,
|
||||
Sequences: []int64{sequence},
|
||||
Msg: msg,
|
||||
}
|
||||
|
||||
// build and sign the transaction, then broadcast to Tendermint
|
||||
res, err := builder.SignBuildBroadcast(signMsg, cdc)
|
||||
res, err := builder.SignBuildBroadcast(msg, cdc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/builder"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
|
@ -51,17 +50,8 @@ func (c commander) sendTxCmd(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
chainID := viper.GetString(client.FlagChainID)
|
||||
sequence := int64(viper.GetInt(client.FlagSequence))
|
||||
|
||||
signMsg := sdk.StdSignMsg{
|
||||
ChainID: chainID,
|
||||
Sequences: []int64{sequence},
|
||||
Msg: msg,
|
||||
}
|
||||
|
||||
// build and sign the transaction, then broadcast to Tendermint
|
||||
res, err := builder.SignBuildBroadcast(signMsg, c.cdc)
|
||||
res, err := builder.SignBuildBroadcast(msg, c.cdc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue