2017-07-18 11:12:51 -07:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2017-07-18 11:55:12 -07:00
|
|
|
"strings"
|
|
|
|
|
2017-07-18 11:12:51 -07:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2017-07-18 21:13:39 -07:00
|
|
|
"github.com/tendermint/basecoin"
|
2017-07-18 12:57:37 -07:00
|
|
|
lcmd "github.com/tendermint/basecoin/client/commands"
|
|
|
|
proofcmd "github.com/tendermint/basecoin/client/commands/proofs"
|
2017-07-18 21:13:39 -07:00
|
|
|
lc "github.com/tendermint/light-client"
|
2017-07-18 11:12:51 -07:00
|
|
|
|
|
|
|
"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",
|
2017-07-18 21:13:39 -07:00
|
|
|
RunE: lcmd.RequireInit(nonceQueryCmd),
|
2017-07-18 11:12:51 -07:00
|
|
|
}
|
|
|
|
|
2017-07-18 21:13:39 -07:00
|
|
|
func nonceQueryCmd(cmd *cobra.Command, args []string) error {
|
2017-07-18 11:55:12 -07:00
|
|
|
if len(args) == 0 {
|
|
|
|
return errors.New("Missing required argument [address]")
|
|
|
|
}
|
|
|
|
addr := strings.Join(args, ",")
|
2017-07-18 21:13:39 -07:00
|
|
|
|
|
|
|
var signers []basecoin.Actor
|
|
|
|
signers, err := parseActors(addr)
|
2017-07-18 11:12:51 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-07-18 21:13:39 -07:00
|
|
|
seq, proof, err := doNonceQuery(signers)
|
|
|
|
if err != nil {
|
2017-07-18 11:12:51 -07:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return proofcmd.OutputProof(seq, proof.BlockHeight())
|
|
|
|
}
|
2017-07-18 21:13:39 -07:00
|
|
|
|
|
|
|
func doNonceQuery(signers []basecoin.Actor) (sequence uint32, proof lc.Proof, err error) {
|
|
|
|
|
|
|
|
key := stack.PrefixedKey(nonce.NameNonce, nonce.GetSeqKey(signers))
|
|
|
|
|
|
|
|
proof, err = proofcmd.GetAndParseAppProof(key, &sequence)
|
|
|
|
if lc.IsNoDataErr(err) {
|
|
|
|
err = errors.Errorf("Sequence is empty for key %s ", key)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|