getting query command to operate
This commit is contained in:
parent
f43fceeb4d
commit
cb00c00f0d
@ -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
|
||||
|
||||
@ -39,6 +39,7 @@ func main() {
|
||||
proofs.TxCmd,
|
||||
proofs.KeyCmd,
|
||||
bcmd.AccountQueryCmd,
|
||||
bcmd.NonceQueryCmd,
|
||||
)
|
||||
|
||||
// you will always want this for the base send command
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user