From cb00c00f0d262de4288f65da4ab83d857958078b Mon Sep 17 00:00:00 2001 From: rigel rozanski Date: Tue, 18 Jul 2017 05:26:25 -0400 Subject: [PATCH] getting query command to operate --- cmd/basecli/commands/query.go | 32 ++++++++++++++++++++++++++++++++ cmd/basecli/main.go | 1 + modules/nonce/tx.go | 16 ++++++++++------ tests/cli/basictx.sh | 1 + 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/cmd/basecli/commands/query.go b/cmd/basecli/commands/query.go index 3d5b4fb066..3ea3626ce4 100644 --- a/cmd/basecli/commands/query.go +++ b/cmd/basecli/commands/query.go @@ -13,6 +13,7 @@ import ( "github.com/tendermint/basecoin/modules/auth" "github.com/tendermint/basecoin/modules/coin" + "github.com/tendermint/basecoin/modules/nonce" "github.com/tendermint/basecoin/stack" ) @@ -41,6 +42,37 @@ func doAccountQuery(cmd *cobra.Command, args []string) error { return proofcmd.OutputProof(acc, proof.BlockHeight()) } +// 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: lcmd.RequireInit(doNonceQuery), +} + +func doNonceQuery(cmd *cobra.Command, args []string) error { + addr, err := proofcmd.ParseHexKey(args, "address") + if err != nil { + return err + } + + act := []basecoin.Actor{basecoin.NewActor( + nonce.NameNonce, + addr, + )} + + key := stack.PrefixedKey(nonce.NameNonce, nonce.GetSeqKey(act)) + + var seq uint32 + proof, err := proofcmd.GetAndParseAppProof(key, &seq) + if lc.IsNoDataErr(err) { + return errors.Errorf("Sequence is empty for address %X ", addr) + } else if err != nil { + return err + } + + return proofcmd.OutputProof(seq, proof.BlockHeight()) +} + // BaseTxPresenter this decodes all basecoin tx type BaseTxPresenter struct { proofs.RawPresenter // this handles MakeKey as hex bytes diff --git a/cmd/basecli/main.go b/cmd/basecli/main.go index 4d96fc3f08..48dcf1dd59 100644 --- a/cmd/basecli/main.go +++ b/cmd/basecli/main.go @@ -39,6 +39,7 @@ func main() { proofs.TxCmd, proofs.KeyCmd, bcmd.AccountQueryCmd, + bcmd.NonceQueryCmd, ) // you will always want this for the base send command diff --git a/modules/nonce/tx.go b/modules/nonce/tx.go index a31536e5e8..7a70878b2d 100644 --- a/modules/nonce/tx.go +++ b/modules/nonce/tx.go @@ -92,17 +92,21 @@ func (n Tx) CheckIncrementSeq(ctx basecoin.Context, store state.KVStore) error { return nil } -// Generate the sequence key as the concatenated list of signers, sorted by address. func (n Tx) getSeqKey() (seqKey []byte) { + return GetSeqKey(n.Signers) +} + +// GetSeqKey - Generate the sequence key as the concatenated list of signers, sorted by address. +func GetSeqKey(signers []basecoin.Actor) (seqKey []byte) { // First copy the list of signers to sort as sort is done in place - signers2sort := make([]basecoin.Actor, len(n.Signers)) - copy(signers2sort, n.Signers) - sort.Sort(basecoin.ByAll(n.Signers)) + signers2sort := make([]basecoin.Actor, len(signers)) + copy(signers2sort, signers) + sort.Sort(basecoin.ByAll(signers)) - for _, signer := range n.Signers { + for _, signer := range signers { seqKey = append(seqKey, signer.Bytes()...) } - //seqKey = merkle.SimpleHashFromBinary(n.Signers) + return } diff --git a/tests/cli/basictx.sh b/tests/cli/basictx.sh index 009e1ddc02..688ebdcdcb 100755 --- a/tests/cli/basictx.sh +++ b/tests/cli/basictx.sh @@ -73,6 +73,7 @@ test02SendTxWithFee() { # make sure we can query the proper nonce NONCE=$(${CLIENT_EXE} query nonce $SENDER) + echo $NONCE if [ -n "$DEBUG" ]; then echo $NONCE; echo; fi # TODO: note that cobra returns error code 0 on parse failure, # so currently this check passes even if there is no nonce query command