Skip to content

Commit

Permalink
txBld -> txBldr
Browse files Browse the repository at this point in the history
  • Loading branch information
jaekwon committed Sep 7, 2018
1 parent acd1250 commit 6325441
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 116 deletions.
6 changes: 3 additions & 3 deletions client/utils/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ func ParseFloat64OrReturnBadRequest(w http.ResponseWriter, s string, defaultIfEm
}

// WriteGenerateStdTxResponse writes response for the generate_only mode.
func WriteGenerateStdTxResponse(w http.ResponseWriter, txBld authtxb.TxBuilder, msgs []sdk.Msg) {
stdMsg, err := txBld.Build(msgs)
func WriteGenerateStdTxResponse(w http.ResponseWriter, txBldr authtxb.TxBuilder, msgs []sdk.Msg) {
stdMsg, err := txBldr.Build(msgs)
if err != nil {
WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
output, err := txBld.Codec.MarshalJSON(auth.NewStdTx(stdMsg.Msgs, stdMsg.Fee, nil, stdMsg.Memo))
output, err := txBldr.Codec.MarshalJSON(auth.NewStdTx(stdMsg.Msgs, stdMsg.Fee, nil, stdMsg.Memo))
if err != nil {
WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
Expand Down
60 changes: 30 additions & 30 deletions client/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ import (
// ensures that the account exists, has a proper number and sequence set. In
// addition, it builds and signs a transaction with the supplied messages.
// Finally, it broadcasts the signed transaction to a node.
func SendTx(txBld authtxb.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) error {
txBld, err := prepareTxContext(txBld, cliCtx)
func SendTx(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) error {
txBldr, err := prepareTxContext(txBldr, cliCtx)
if err != nil {
return err
}
autogas := cliCtx.DryRun || (cliCtx.Gas == 0)
if autogas {
txBld, err = EnrichCtxWithGas(txBld, cliCtx, cliCtx.FromAddressName, msgs)
txBldr, err = EnrichCtxWithGas(txBldr, cliCtx, cliCtx.FromAddressName, msgs)
if err != nil {
return err
}
fmt.Fprintf(os.Stderr, "estimated gas = %v\n", txBld.Gas)
fmt.Fprintf(os.Stderr, "estimated gas = %v\n", txBldr.Gas)
}
if cliCtx.DryRun {
return nil
Expand All @@ -41,7 +41,7 @@ func SendTx(txBld authtxb.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg)
}

// build and sign the transaction
txBytes, err := txBld.BuildAndSign(cliCtx.FromAddressName, passphrase, msgs)
txBytes, err := txBldr.BuildAndSign(cliCtx.FromAddressName, passphrase, msgs)
if err != nil {
return err
}
Expand All @@ -50,8 +50,8 @@ func SendTx(txBld authtxb.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg)
}

// SimulateMsgs simulates the transaction and returns the gas estimate and the adjusted value.
func SimulateMsgs(txBld authtxb.TxBuilder, cliCtx context.CLIContext, name string, msgs []sdk.Msg, gas int64) (estimated, adjusted int64, err error) {
txBytes, err := txBld.WithGas(gas).BuildWithPubKey(name, msgs)
func SimulateMsgs(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, name string, msgs []sdk.Msg, gas int64) (estimated, adjusted int64, err error) {
txBytes, err := txBldr.WithGas(gas).BuildWithPubKey(name, msgs)
if err != nil {
return
}
Expand All @@ -61,12 +61,12 @@ func SimulateMsgs(txBld authtxb.TxBuilder, cliCtx context.CLIContext, name strin

// EnrichCtxWithGas calculates the gas estimate that would be consumed by the
// transaction and set the transaction's respective value accordingly.
func EnrichCtxWithGas(txBld authtxb.TxBuilder, cliCtx context.CLIContext, name string, msgs []sdk.Msg) (authtxb.TxBuilder, error) {
_, adjusted, err := SimulateMsgs(txBld, cliCtx, name, msgs, 0)
func EnrichCtxWithGas(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, name string, msgs []sdk.Msg) (authtxb.TxBuilder, error) {
_, adjusted, err := SimulateMsgs(txBldr, cliCtx, name, msgs, 0)
if err != nil {
return txBld, err
return txBldr, err
}
return txBld.WithGas(adjusted), nil
return txBldr.WithGas(adjusted), nil
}

// CalculateGas simulates the execution of a transaction and returns
Expand All @@ -87,12 +87,12 @@ func CalculateGas(queryFunc func(string, common.HexBytes) ([]byte, error), cdc *
}

// PrintUnsignedStdTx builds an unsigned StdTx and prints it to os.Stdout.
func PrintUnsignedStdTx(txBld authtxb.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) (err error) {
stdTx, err := buildUnsignedStdTx(txBld, cliCtx, msgs)
func PrintUnsignedStdTx(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) (err error) {
stdTx, err := buildUnsignedStdTx(txBldr, cliCtx, msgs)
if err != nil {
return
}
json, err := txBld.Codec.MarshalJSON(stdTx)
json, err := txBldr.Codec.MarshalJSON(stdTx)
if err == nil {
fmt.Printf("%s\n", json)
}
Expand All @@ -111,53 +111,53 @@ func parseQueryResponse(cdc *amino.Codec, rawRes []byte) (int64, error) {
return simulationResult.GasUsed, nil
}

func prepareTxContext(txBld authtxb.TxBuilder, cliCtx context.CLIContext) (authtxb.TxBuilder, error) {
func prepareTxContext(txBldr authtxb.TxBuilder, cliCtx context.CLIContext) (authtxb.TxBuilder, error) {
if err := cliCtx.EnsureAccountExists(); err != nil {
return txBld, err
return txBldr, err
}

from, err := cliCtx.GetFromAddress()
if err != nil {
return txBld, err
return txBldr, err
}

// TODO: (ref #1903) Allow for user supplied account number without
// automatically doing a manual lookup.
if txBld.AccountNumber == 0 {
if txBldr.AccountNumber == 0 {
accNum, err := cliCtx.GetAccountNumber(from)
if err != nil {
return txBld, err
return txBldr, err
}
txBld = txBld.WithAccountNumber(accNum)
txBldr = txBldr.WithAccountNumber(accNum)
}

// TODO: (ref #1903) Allow for user supplied account sequence without
// automatically doing a manual lookup.
if txBld.Sequence == 0 {
if txBldr.Sequence == 0 {
accSeq, err := cliCtx.GetAccountSequence(from)
if err != nil {
return txBld, err
return txBldr, err
}
txBld = txBld.WithSequence(accSeq)
txBldr = txBldr.WithSequence(accSeq)
}
return txBld, nil
return txBldr, nil
}

// buildUnsignedStdTx builds a StdTx as per the parameters passed in the
// contexts. Gas is automatically estimated if gas wanted is set to 0.
func buildUnsignedStdTx(txBld authtxb.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) (stdTx auth.StdTx, err error) {
txBld, err = prepareTxContext(txBld, cliCtx)
func buildUnsignedStdTx(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) (stdTx auth.StdTx, err error) {
txBldr, err = prepareTxContext(txBldr, cliCtx)
if err != nil {
return
}
if txBld.Gas == 0 {
txBld, err = EnrichCtxWithGas(txBld, cliCtx, cliCtx.FromAddressName, msgs)
if txBldr.Gas == 0 {
txBldr, err = EnrichCtxWithGas(txBldr, cliCtx, cliCtx.FromAddressName, msgs)
if err != nil {
return
}
fmt.Fprintf(os.Stderr, "estimated gas = %v\n", txBld.Gas)
fmt.Fprintf(os.Stderr, "estimated gas = %v\n", txBldr.Gas)
}
stdSignMsg, err := txBld.Build(msgs)
stdSignMsg, err := txBldr.Build(msgs)
if err != nil {
return
}
Expand Down
8 changes: 4 additions & 4 deletions examples/democoin/x/cool/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func QuizTxCmd(cdc *wire.Codec) *cobra.Command {
Short: "What's cooler than being cool?",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
txBld := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithLogger(os.Stdout).
Expand All @@ -34,7 +34,7 @@ func QuizTxCmd(cdc *wire.Codec) *cobra.Command {

msg := cool.NewMsgQuiz(from, args[0])

return utils.SendTx(txBld, cliCtx, []sdk.Msg{msg})
return utils.SendTx(txBldr, cliCtx, []sdk.Msg{msg})
},
}
}
Expand All @@ -46,7 +46,7 @@ func SetTrendTxCmd(cdc *wire.Codec) *cobra.Command {
Short: "You're so cool, tell us what is cool!",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
txBld := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithLogger(os.Stdout).
Expand All @@ -59,7 +59,7 @@ func SetTrendTxCmd(cdc *wire.Codec) *cobra.Command {

msg := cool.NewMsgSetTrend(from, args[0])

return utils.SendTx(txBld, cliCtx, []sdk.Msg{msg})
return utils.SendTx(txBldr, cliCtx, []sdk.Msg{msg})
},
}
}
4 changes: 2 additions & 2 deletions examples/democoin/x/pow/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func MineCmd(cdc *wire.Codec) *cobra.Command {
Short: "Mine some coins with proof-of-work!",
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
txBld := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithLogger(os.Stdout).
Expand Down Expand Up @@ -53,7 +53,7 @@ func MineCmd(cdc *wire.Codec) *cobra.Command {

// Build and sign the transaction, then broadcast to a Tendermint
// node.
return utils.SendTx(txBld, cliCtx, []sdk.Msg{msg})
return utils.SendTx(txBldr, cliCtx, []sdk.Msg{msg})
},
}
}
8 changes: 4 additions & 4 deletions examples/democoin/x/simplestake/client/cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func BondTxCmd(cdc *wire.Codec) *cobra.Command {
Use: "bond",
Short: "Bond to a validator",
RunE: func(cmd *cobra.Command, args []string) error {
txBld := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithLogger(os.Stdout).
Expand Down Expand Up @@ -68,7 +68,7 @@ func BondTxCmd(cdc *wire.Codec) *cobra.Command {

// Build and sign the transaction, then broadcast to a Tendermint
// node.
return utils.SendTx(txBld, cliCtx, []sdk.Msg{msg})
return utils.SendTx(txBldr, cliCtx, []sdk.Msg{msg})
},
}

Expand All @@ -84,7 +84,7 @@ func UnbondTxCmd(cdc *wire.Codec) *cobra.Command {
Use: "unbond",
Short: "Unbond from a validator",
RunE: func(cmd *cobra.Command, args []string) error {
txBld := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithLogger(os.Stdout)
Expand All @@ -98,7 +98,7 @@ func UnbondTxCmd(cdc *wire.Codec) *cobra.Command {

// Build and sign the transaction, then broadcast to a Tendermint
// node.
return utils.SendTx(txBld, cliCtx, []sdk.Msg{msg})
return utils.SendTx(txBldr, cliCtx, []sdk.Msg{msg})
},
}

Expand Down
6 changes: 3 additions & 3 deletions x/bank/client/cli/sendtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func SendTxCmd(cdc *wire.Codec) *cobra.Command {
Use: "send",
Short: "Create and sign a send tx",
RunE: func(cmd *cobra.Command, args []string) error {
txBld := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithLogger(os.Stdout).
Expand Down Expand Up @@ -69,10 +69,10 @@ func SendTxCmd(cdc *wire.Codec) *cobra.Command {
// build and sign the transaction, then broadcast to Tendermint
msg := client.BuildMsg(from, to, coins)
if cliCtx.GenerateOnly {
return utils.PrintUnsignedStdTx(txBld, cliCtx, []sdk.Msg{msg})
return utils.PrintUnsignedStdTx(txBldr, cliCtx, []sdk.Msg{msg})
}

return utils.SendTx(txBld, cliCtx, []sdk.Msg{msg})
return utils.SendTx(txBldr, cliCtx, []sdk.Msg{msg})
},
}

Expand Down
12 changes: 6 additions & 6 deletions x/bank/client/rest/sendtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func SendRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.CLICo
return
}

txBld := authtxb.TxBuilder{
txBldr := authtxb.TxBuilder{
Codec: cdc,
Gas: m.Gas,
ChainID: m.ChainID,
Expand All @@ -95,24 +95,24 @@ func SendRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, cliCtx context.CLICo
cliCtx = cliCtx.WithGasAdjustment(adjustment)

if utils.HasDryRunArg(r) || m.Gas == 0 {
newCtx, err := utils.EnrichCtxWithGas(txBld, cliCtx, m.LocalAccountName, []sdk.Msg{msg})
newCtx, err := utils.EnrichCtxWithGas(txBldr, cliCtx, m.LocalAccountName, []sdk.Msg{msg})
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
if utils.HasDryRunArg(r) {
utils.WriteSimulationResponse(w, txBld.Gas)
utils.WriteSimulationResponse(w, txBldr.Gas)
return
}
txBld = newCtx
txBldr = newCtx
}

if utils.HasGenerateOnlyArg(r) {
utils.WriteGenerateStdTxResponse(w, txBld, []sdk.Msg{msg})
utils.WriteGenerateStdTxResponse(w, txBldr, []sdk.Msg{msg})
return
}

txBytes, err := txBld.BuildAndSign(m.LocalAccountName, m.Password, []sdk.Msg{msg})
txBytes, err := txBldr.BuildAndSign(m.LocalAccountName, m.Password, []sdk.Msg{msg})
if err != nil {
utils.WriteErrorResponse(w, http.StatusUnauthorized, err.Error())
return
Expand Down
18 changes: 9 additions & 9 deletions x/gov/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ $ gaiacli gov submit-proposal --title="Test Proposal" --description="My awesome
return err
}

txBld := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithLogger(os.Stdout).
Expand Down Expand Up @@ -105,13 +105,13 @@ $ gaiacli gov submit-proposal --title="Test Proposal" --description="My awesome
}

if cliCtx.GenerateOnly {
return utils.PrintUnsignedStdTx(txBld, cliCtx, []sdk.Msg{msg})
return utils.PrintUnsignedStdTx(txBldr, cliCtx, []sdk.Msg{msg})
}

// Build and sign the transaction, then broadcast to Tendermint
// proposalID must be returned, and it is a part of response.
cliCtx.PrintResponse = true
return utils.SendTx(txBld, cliCtx, []sdk.Msg{msg})
return utils.SendTx(txBldr, cliCtx, []sdk.Msg{msg})
},
}

Expand Down Expand Up @@ -161,7 +161,7 @@ func GetCmdDeposit(cdc *wire.Codec) *cobra.Command {
Use: "deposit",
Short: "deposit tokens for activing proposal",
RunE: func(cmd *cobra.Command, args []string) error {
txBld := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithLogger(os.Stdout).
Expand All @@ -186,12 +186,12 @@ func GetCmdDeposit(cdc *wire.Codec) *cobra.Command {
}

if cliCtx.GenerateOnly {
return utils.PrintUnsignedStdTx(txBld, cliCtx, []sdk.Msg{msg})
return utils.PrintUnsignedStdTx(txBldr, cliCtx, []sdk.Msg{msg})
}

// Build and sign the transaction, then broadcast to a Tendermint
// node.
return utils.SendTx(txBld, cliCtx, []sdk.Msg{msg})
return utils.SendTx(txBldr, cliCtx, []sdk.Msg{msg})
},
}

Expand All @@ -207,7 +207,7 @@ func GetCmdVote(cdc *wire.Codec) *cobra.Command {
Use: "vote",
Short: "vote for an active proposal, options: Yes/No/NoWithVeto/Abstain",
RunE: func(cmd *cobra.Command, args []string) error {
txBld := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithLogger(os.Stdout).
Expand All @@ -233,7 +233,7 @@ func GetCmdVote(cdc *wire.Codec) *cobra.Command {
}

if cliCtx.GenerateOnly {
return utils.PrintUnsignedStdTx(txBld, cliCtx, []sdk.Msg{msg})
return utils.PrintUnsignedStdTx(txBldr, cliCtx, []sdk.Msg{msg})
}

fmt.Printf("Vote[Voter:%s,ProposalID:%d,Option:%s]",
Expand All @@ -242,7 +242,7 @@ func GetCmdVote(cdc *wire.Codec) *cobra.Command {

// Build and sign the transaction, then broadcast to a Tendermint
// node.
return utils.SendTx(txBld, cliCtx, []sdk.Msg{msg})
return utils.SendTx(txBldr, cliCtx, []sdk.Msg{msg})
},
}

Expand Down
Loading

0 comments on commit 6325441

Please sign in to comment.