client: On any tx that broadcasts a tx, check that acct exists
This subverts the really hard to decipher ABCI error message, with a nice user friendly error message.
This commit is contained in:
parent
d04c6cf9e5
commit
6a742c8773
@ -7,6 +7,9 @@
|
||||
BREAKING CHANGES
|
||||
* [x/stake] Fixed the period check for the inflation calculation
|
||||
|
||||
IMPROVEMENTS
|
||||
* [cli] Improve error messages for all txs when the account doesn't exist
|
||||
|
||||
## 0.22.0
|
||||
|
||||
*July 16th, 2018*
|
||||
|
||||
@ -186,6 +186,11 @@ func (ctx CoreContext) SignAndBuild(name, passphrase string, msgs []sdk.Msg, cdc
|
||||
|
||||
// sign and build the transaction from the msg
|
||||
func (ctx CoreContext) ensureSignBuild(name string, msgs []sdk.Msg, cdc *wire.Codec) (tyBytes []byte, err error) {
|
||||
err = EnsureAccountExists(ctx, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx, err = EnsureAccountNumber(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -3,6 +3,7 @@ package context
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
||||
@ -10,6 +11,9 @@ import (
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
)
|
||||
|
||||
// NewCoreContextFromViper - return a new context with parameters from the command line
|
||||
@ -68,6 +72,36 @@ func defaultChainID() (string, error) {
|
||||
return doc.ChainID, nil
|
||||
}
|
||||
|
||||
// EnsureAccountExists - Make sure account exists
|
||||
func EnsureAccountExists(ctx CoreContext, name string) error {
|
||||
keybase, err := keys.GetKeyBase()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if name == "" {
|
||||
return errors.Errorf("must provide a from address name")
|
||||
}
|
||||
|
||||
info, err := keybase.Get(name)
|
||||
if err != nil {
|
||||
return errors.Errorf("no key for: %s", name)
|
||||
}
|
||||
|
||||
accAddr := sdk.AccAddress(info.GetPubKey().Address())
|
||||
|
||||
Acc, err := ctx.QueryStore(auth.AddressStoreKey(accAddr), ctx.AccountStore)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Check if account was found
|
||||
if Acc == nil {
|
||||
return errors.Errorf("No account with address %s was found in the state.\nAre you sure there has been a transaction involving it?", accAddr)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EnsureAccount - automatically set account number if none provided
|
||||
func EnsureAccountNumber(ctx CoreContext) (CoreContext, error) {
|
||||
// Should be viper.IsSet, but this does not work - https://github.com/spf13/viper/pull/331
|
||||
|
||||
Loading…
Reference in New Issue
Block a user