gaiacli: Improve error messages for `send` command
Now provides better error messages when the account you're sending from has no money, or it has insufficient funds. (Avoids making the user interpret ABCI errors) closes #1489
This commit is contained in:
parent
3654579ea7
commit
819eedd281
|
@ -60,6 +60,7 @@ FEATURES
|
|||
- You can now use a Ledger with `gaiacli --ledger` for all key-related commands
|
||||
- Ledger keys can be named and tracked locally in the key DB
|
||||
* [gaiacli] added an --async flag to the cli to deliver transactions without waiting for a tendermint response
|
||||
* [gaiacli] improve error messages on `send` and `account` commands
|
||||
|
||||
FIXES
|
||||
* [gaia] Added self delegation for validators in the genesis creation
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cli
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -54,7 +55,7 @@ func GetAccountCmd(storeName string, cdc *wire.Codec, decoder auth.AccountDecode
|
|||
|
||||
// Check if account was found
|
||||
if res == nil {
|
||||
return sdk.ErrUnknownAddress("No account with address " + addr +
|
||||
return errors.New("No account with address " + addr +
|
||||
" was found in the state.\nAre you sure there has been a transaction involving it?")
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cli
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -9,6 +10,7 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/wire"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/client"
|
||||
)
|
||||
|
@ -19,7 +21,7 @@ const (
|
|||
flagAsync = "async"
|
||||
)
|
||||
|
||||
// SendTxCommand will create a send tx and sign it with the given key
|
||||
// SendTxCmd will create a send tx and sign it with the given key
|
||||
func SendTxCmd(cdc *wire.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "send",
|
||||
|
@ -33,19 +35,41 @@ func SendTxCmd(cdc *wire.Codec) *cobra.Command {
|
|||
return err
|
||||
}
|
||||
|
||||
fromAcc, err := ctx.QueryStore(auth.AddressStoreKey(from), ctx.AccountStore)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
bech32From := sdk.MustBech32ifyAcc(from)
|
||||
// Check if account was found
|
||||
if fromAcc == nil {
|
||||
return errors.New("No account with address " + bech32From +
|
||||
" was found in the state.\nAre you sure there has been a transaction involving it?")
|
||||
}
|
||||
|
||||
toStr := viper.GetString(flagTo)
|
||||
|
||||
to, err := sdk.GetAccAddressBech32(toStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// parse coins
|
||||
// parse coins trying to be sent
|
||||
amount := viper.GetString(flagAmount)
|
||||
coins, err := sdk.ParseCoins(amount)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// ensure account has enough coins
|
||||
account, err := ctx.Decoder(fromAcc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !account.GetCoins().IsGTE(coins) {
|
||||
return errors.New("Address " + bech32From +
|
||||
" doesn't have enough coins to pay for this transaction.")
|
||||
}
|
||||
|
||||
// build and sign the transaction, then broadcast to Tendermint
|
||||
msg := client.BuildMsg(from, to, coins)
|
||||
|
||||
|
|
Loading…
Reference in New Issue