cosmos-sdk/modules/coin/commands/query.go

46 lines
1.1 KiB
Go
Raw Normal View History

package commands
import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
2017-08-04 10:21:22 -07:00
"github.com/spf13/viper"
2017-07-18 22:23:13 -07:00
lc "github.com/tendermint/light-client"
"github.com/tendermint/basecoin/client/commands"
2017-07-19 01:51:36 -07:00
proofcmd "github.com/tendermint/basecoin/client/commands/proofs"
"github.com/tendermint/basecoin/modules/coin"
"github.com/tendermint/basecoin/stack"
)
// AccountQueryCmd - command to query an account
var AccountQueryCmd = &cobra.Command{
Use: "account [address]",
Short: "Get details of an account, with proof",
RunE: commands.RequireInit(accountQueryCmd),
}
2017-07-18 22:23:13 -07:00
func accountQueryCmd(cmd *cobra.Command, args []string) error {
addr, err := commands.GetOneArg(args, "address")
if err != nil {
return err
}
act, err := commands.ParseActor(addr)
if err != nil {
return err
}
2017-07-24 07:55:06 -07:00
act = coin.ChainAddr(act)
key := stack.PrefixedKey(coin.NameCoin, act.Bytes())
acc := coin.Account{}
2017-08-04 10:21:22 -07:00
prove := !viper.GetBool(commands.FlagTrustNode)
height, err := proofcmd.GetParsed(key, &acc, prove)
if lc.IsNoDataErr(err) {
2017-07-27 11:05:28 -07:00
return errors.Errorf("Account bytes are empty for address %s ", addr)
} else if err != nil {
return err
}
2017-08-04 10:21:22 -07:00
return proofcmd.OutputProof(acc, height)
}