Skip to content

Commit

Permalink
sed -i 's/txCtx/txBld/g'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessio Treglia committed Sep 7, 2018
1 parent 3b6da7a commit 54b3b5c
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, txCtx authctx.TxBuilder, msgs []sdk.Msg) {
stdMsg, err := txCtx.Build(msgs)
func WriteGenerateStdTxResponse(w http.ResponseWriter, txBld authctx.TxBuilder, msgs []sdk.Msg) {
stdMsg, err := txBld.Build(msgs)
if err != nil {
WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}
output, err := txCtx.Codec.MarshalJSON(auth.NewStdTx(stdMsg.Msgs, stdMsg.Fee, nil, stdMsg.Memo))
output, err := txBld.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(txCtx authctx.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) error {
txCtx, err := prepareTxContext(txCtx, cliCtx)
func SendTx(txBld authctx.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) error {
txBld, err := prepareTxContext(txBld, cliCtx)
if err != nil {
return err
}
autogas := cliCtx.DryRun || (cliCtx.Gas == 0)
if autogas {
txCtx, err = EnrichCtxWithGas(txCtx, cliCtx, cliCtx.FromAddressName, msgs)
txBld, err = EnrichCtxWithGas(txBld, cliCtx, cliCtx.FromAddressName, msgs)
if err != nil {
return err
}
fmt.Fprintf(os.Stderr, "estimated gas = %v\n", txCtx.Gas)
fmt.Fprintf(os.Stderr, "estimated gas = %v\n", txBld.Gas)
}
if cliCtx.DryRun {
return nil
Expand All @@ -41,7 +41,7 @@ func SendTx(txCtx authctx.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg)
}

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

// SimulateMsgs simulates the transaction and returns the gas estimate and the adjusted value.
func SimulateMsgs(txCtx authctx.TxBuilder, cliCtx context.CLIContext, name string, msgs []sdk.Msg, gas int64) (estimated, adjusted int64, err error) {
txBytes, err := txCtx.WithGas(gas).BuildWithPubKey(name, msgs)
func SimulateMsgs(txBld authctx.TxBuilder, cliCtx context.CLIContext, name string, msgs []sdk.Msg, gas int64) (estimated, adjusted int64, err error) {
txBytes, err := txBld.WithGas(gas).BuildWithPubKey(name, msgs)
if err != nil {
return
}
Expand All @@ -61,12 +61,12 @@ func SimulateMsgs(txCtx authctx.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(txCtx authctx.TxBuilder, cliCtx context.CLIContext, name string, msgs []sdk.Msg) (authctx.TxBuilder, error) {
_, adjusted, err := SimulateMsgs(txCtx, cliCtx, name, msgs, 0)
func EnrichCtxWithGas(txBld authctx.TxBuilder, cliCtx context.CLIContext, name string, msgs []sdk.Msg) (authctx.TxBuilder, error) {
_, adjusted, err := SimulateMsgs(txBld, cliCtx, name, msgs, 0)
if err != nil {
return txCtx, err
return txBld, err
}
return txCtx.WithGas(adjusted), nil
return txBld.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(txCtx authctx.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) (err error) {
stdTx, err := buildUnsignedStdTx(txCtx, cliCtx, msgs)
func PrintUnsignedStdTx(txBld authctx.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) (err error) {
stdTx, err := buildUnsignedStdTx(txBld, cliCtx, msgs)
if err != nil {
return
}
json, err := txCtx.Codec.MarshalJSON(stdTx)
json, err := txBld.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(txCtx authctx.TxBuilder, cliCtx context.CLIContext) (authctx.TxBuilder, error) {
func prepareTxContext(txBld authctx.TxBuilder, cliCtx context.CLIContext) (authctx.TxBuilder, error) {
if err := cliCtx.EnsureAccountExists(); err != nil {
return txCtx, err
return txBld, err
}

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

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

// TODO: (ref #1903) Allow for user supplied account sequence without
// automatically doing a manual lookup.
if txCtx.Sequence == 0 {
if txBld.Sequence == 0 {
accSeq, err := cliCtx.GetAccountSequence(from)
if err != nil {
return txCtx, err
return txBld, err
}
txCtx = txCtx.WithSequence(accSeq)
txBld = txBld.WithSequence(accSeq)
}
return txCtx, nil
return txBld, 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(txCtx authctx.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) (stdTx auth.StdTx, err error) {
txCtx, err = prepareTxContext(txCtx, cliCtx)
func buildUnsignedStdTx(txBld authctx.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) (stdTx auth.StdTx, err error) {
txBld, err = prepareTxContext(txBld, cliCtx)
if err != nil {
return
}
if txCtx.Gas == 0 {
txCtx, err = EnrichCtxWithGas(txCtx, cliCtx, cliCtx.FromAddressName, msgs)
if txBld.Gas == 0 {
txBld, err = EnrichCtxWithGas(txBld, cliCtx, cliCtx.FromAddressName, msgs)
if err != nil {
return
}
fmt.Fprintf(os.Stderr, "estimated gas = %v\n", txCtx.Gas)
fmt.Fprintf(os.Stderr, "estimated gas = %v\n", txBld.Gas)
}
stdSignMsg, err := txCtx.Build(msgs)
stdSignMsg, err := txBld.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 {
txCtx := authctx.NewTxBuilderFromCLI().WithCodec(cdc)
txBld := authctx.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(txCtx, cliCtx, []sdk.Msg{msg})
return utils.SendTx(txBld, 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 {
txCtx := authctx.NewTxBuilderFromCLI().WithCodec(cdc)
txBld := authctx.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(txCtx, cliCtx, []sdk.Msg{msg})
return utils.SendTx(txBld, 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 {
txCtx := authctx.NewTxBuilderFromCLI().WithCodec(cdc)
txBld := authctx.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(txCtx, cliCtx, []sdk.Msg{msg})
return utils.SendTx(txBld, 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 {
txCtx := authctx.NewTxBuilderFromCLI().WithCodec(cdc)
txBld := authctx.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(txCtx, cliCtx, []sdk.Msg{msg})
return utils.SendTx(txBld, 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 {
txCtx := authctx.NewTxBuilderFromCLI().WithCodec(cdc)
txBld := authctx.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(txCtx, cliCtx, []sdk.Msg{msg})
return utils.SendTx(txBld, 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 {
txCtx := authctx.NewTxBuilderFromCLI().WithCodec(cdc)
txBld := authctx.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(txCtx, cliCtx, []sdk.Msg{msg})
return utils.PrintUnsignedStdTx(txBld, cliCtx, []sdk.Msg{msg})
}

return utils.SendTx(txCtx, cliCtx, []sdk.Msg{msg})
return utils.SendTx(txBld, 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
}

txCtx := authctx.TxBuilder{
txBld := authctx.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(txCtx, cliCtx, m.LocalAccountName, []sdk.Msg{msg})
newCtx, err := utils.EnrichCtxWithGas(txBld, cliCtx, m.LocalAccountName, []sdk.Msg{msg})
if err != nil {
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
if utils.HasDryRunArg(r) {
utils.WriteSimulationResponse(w, txCtx.Gas)
utils.WriteSimulationResponse(w, txBld.Gas)
return
}
txCtx = newCtx
txBld = newCtx
}

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

txBytes, err := txCtx.BuildAndSign(m.LocalAccountName, m.Password, []sdk.Msg{msg})
txBytes, err := txBld.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
}

txCtx := authctx.NewTxBuilderFromCLI().WithCodec(cdc)
txBld := authctx.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(txCtx, cliCtx, []sdk.Msg{msg})
return utils.PrintUnsignedStdTx(txBld, 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(txCtx, cliCtx, []sdk.Msg{msg})
return utils.SendTx(txBld, 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 {
txCtx := authctx.NewTxBuilderFromCLI().WithCodec(cdc)
txBld := authctx.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(txCtx, cliCtx, []sdk.Msg{msg})
return utils.PrintUnsignedStdTx(txBld, cliCtx, []sdk.Msg{msg})
}

// Build and sign the transaction, then broadcast to a Tendermint
// node.
return utils.SendTx(txCtx, cliCtx, []sdk.Msg{msg})
return utils.SendTx(txBld, 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 {
txCtx := authctx.NewTxBuilderFromCLI().WithCodec(cdc)
txBld := authctx.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(txCtx, cliCtx, []sdk.Msg{msg})
return utils.PrintUnsignedStdTx(txBld, 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(txCtx, cliCtx, []sdk.Msg{msg})
return utils.SendTx(txBld, cliCtx, []sdk.Msg{msg})
},
}

Expand Down
Loading

0 comments on commit 54b3b5c

Please sign in to comment.