Separate account getters from client/context (#4579)

Account getters are removed from client context. x/auth has the
queriers necessary for retrieving account information.
These functions should be removed since they are currently
redundant and don't provide any extra value.

Closes: #4543
This commit is contained in:
Alessio Treglia
2019-06-19 14:24:11 +02:00
committed by GitHub
parent 84a2582877
commit 1eb7706c28
13 changed files with 184 additions and 109 deletions
-76
View File
@@ -16,7 +16,6 @@ import (
"github.com/cosmos/cosmos-sdk/store/rootmulti"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)
// GetNode returns an RPC client. If the context's client is not defined, an
@@ -63,26 +62,6 @@ func (ctx CLIContext) QuerySubspace(subspace []byte, storeName string) (res []sd
return
}
// GetAccount queries for an account given an address and a block height. An
// error is returned if the query or decoding fails.
func (ctx CLIContext) GetAccount(address []byte) (authtypes.Account, error) {
if ctx.AccDecoder == nil {
return nil, errors.New("account decoder required but not provided")
}
res, err := ctx.queryAccount(address)
if err != nil {
return nil, err
}
var account authtypes.Account
if err := ctx.Codec.UnmarshalJSON(res, &account); err != nil {
return nil, err
}
return account, nil
}
// GetFromAddress returns the from address from the context's name.
func (ctx CLIContext) GetFromAddress() sdk.AccAddress {
return ctx.FromAddress
@@ -93,61 +72,6 @@ func (ctx CLIContext) GetFromName() string {
return ctx.FromName
}
// GetAccountNumber returns the next account number for the given account
// address.
func (ctx CLIContext) GetAccountNumber(address []byte) (uint64, error) {
account, err := ctx.GetAccount(address)
if err != nil {
return 0, err
}
return account.GetAccountNumber(), nil
}
// GetAccountSequence returns the sequence number for the given account
// address.
func (ctx CLIContext) GetAccountSequence(address []byte) (uint64, error) {
account, err := ctx.GetAccount(address)
if err != nil {
return 0, err
}
return account.GetSequence(), nil
}
// EnsureAccountExists ensures that an account exists for a given context. An
// error is returned if it does not.
func (ctx CLIContext) EnsureAccountExists() error {
addr := ctx.GetFromAddress()
return ctx.EnsureAccountExistsFromAddr(addr)
}
// EnsureAccountExistsFromAddr ensures that an account exists for a given
// address. Instead of using the context's from name, a direct address is
// given. An error is returned if it does not.
func (ctx CLIContext) EnsureAccountExistsFromAddr(addr sdk.AccAddress) error {
_, err := ctx.queryAccount(addr)
return err
}
// queryAccount queries an account using custom query endpoint of auth module
// returns an error if result is `null` otherwise account data
func (ctx CLIContext) queryAccount(addr sdk.AccAddress) ([]byte, error) {
bz, err := ctx.Codec.MarshalJSON(authtypes.NewQueryAccountParams(addr))
if err != nil {
return nil, err
}
route := fmt.Sprintf("custom/%s/%s", ctx.AccountStore, authtypes.QueryAccount)
res, _, err := ctx.query(route, bz)
if err != nil {
return nil, err
}
return res, nil
}
// query performs a query to a Tendermint node with the provided store name
// and path. It returns the result and height of the query upon success
// or an error if the query fails.