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

55 lines
1.3 KiB
Go
Raw Normal View History

package commands
import (
"strings"
"github.com/pkg/errors"
"github.com/spf13/cobra"
2017-08-04 10:21:22 -07:00
"github.com/spf13/viper"
2017-07-19 01:51:36 -07:00
lc "github.com/tendermint/light-client"
2017-07-18 21:13:39 -07:00
"github.com/tendermint/basecoin"
"github.com/tendermint/basecoin/client/commands"
"github.com/tendermint/basecoin/client/commands/query"
"github.com/tendermint/basecoin/modules/nonce"
"github.com/tendermint/basecoin/stack"
)
// NonceQueryCmd - command to query an nonce account
var NonceQueryCmd = &cobra.Command{
Use: "nonce [address]",
Short: "Get details of a nonce sequence number, with proof",
RunE: commands.RequireInit(nonceQueryCmd),
}
2017-07-18 21:13:39 -07:00
func nonceQueryCmd(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("Missing required argument [address]")
}
addr := strings.Join(args, ",")
2017-07-18 21:13:39 -07:00
signers, err := commands.ParseActors(addr)
if err != nil {
return err
}
2017-08-04 10:21:22 -07:00
seq, height, err := doNonceQuery(signers)
2017-07-18 21:13:39 -07:00
if err != nil {
return err
}
return query.OutputProof(seq, height)
}
2017-07-18 21:13:39 -07:00
2017-08-04 10:21:22 -07:00
func doNonceQuery(signers []basecoin.Actor) (sequence uint32, height uint64, err error) {
2017-07-18 21:13:39 -07:00
key := stack.PrefixedKey(nonce.NameNonce, nonce.GetSeqKey(signers))
2017-08-04 10:21:22 -07:00
prove := !viper.GetBool(commands.FlagTrustNode)
height, err = query.GetParsed(key, &sequence, prove)
2017-07-18 21:13:39 -07:00
if lc.IsNoDataErr(err) {
// no data, return sequence 0
2017-08-04 10:21:22 -07:00
return 0, 0, nil
2017-07-18 21:13:39 -07:00
}
return
}