Cleanup nonce parsing for multiple keys
This commit is contained in:
parent
a060bde1c4
commit
f41aed4945
@ -1,6 +1,8 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
@ -8,8 +10,6 @@ import (
|
||||
lcmd "github.com/tendermint/light-client/commands"
|
||||
proofcmd "github.com/tendermint/light-client/commands/proofs"
|
||||
|
||||
"github.com/tendermint/basecoin"
|
||||
"github.com/tendermint/basecoin/modules/auth"
|
||||
"github.com/tendermint/basecoin/modules/nonce"
|
||||
"github.com/tendermint/basecoin/stack"
|
||||
)
|
||||
@ -22,22 +22,21 @@ var NonceQueryCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func doNonceQuery(cmd *cobra.Command, args []string) error {
|
||||
addr, err := proofcmd.ParseHexKey(args, "address")
|
||||
if len(args) == 0 {
|
||||
return errors.New("Missing required argument [address]")
|
||||
}
|
||||
addr := strings.Join(args, ",")
|
||||
act, err := parseActors(addr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
act := []basecoin.Actor{basecoin.NewActor(
|
||||
auth.NameSigs,
|
||||
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)
|
||||
return errors.Errorf("Sequence is empty for address %s ", addr)
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -27,16 +27,16 @@ var _ bcmd.Wrapper = NonceWrapper{}
|
||||
// the tx with this nonce. Grabs the permission from the signer,
|
||||
// as we still only support single sig on the cli
|
||||
func (NonceWrapper) Wrap(tx basecoin.Tx) (res basecoin.Tx, err error) {
|
||||
//add the nonce tx layer to the tx
|
||||
seq := viper.GetInt(FlagSequence)
|
||||
if seq < 0 {
|
||||
return res, fmt.Errorf("sequence must be greater than 0")
|
||||
seq, err := readSequence()
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
signers, err := readNonceKey()
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res = nonce.NewTx(uint32(seq), signers, tx)
|
||||
res = nonce.NewTx(seq, signers, tx)
|
||||
return
|
||||
}
|
||||
|
||||
@ -46,14 +46,17 @@ func (NonceWrapper) Register(fs *pflag.FlagSet) {
|
||||
fs.String(FlagNonceKey, "", "Set of comma-separated addresses for the nonce (for multisig)")
|
||||
}
|
||||
|
||||
func readNonceKey() (signers []basecoin.Actor, err error) {
|
||||
func readNonceKey() ([]basecoin.Actor, error) {
|
||||
nonce := viper.GetString(FlagNonceKey)
|
||||
if nonce == "" {
|
||||
return []basecoin.Actor{bcmd.GetSignerAct()}, nil
|
||||
}
|
||||
return parseActors(nonce)
|
||||
}
|
||||
|
||||
func parseActors(key string) (signers []basecoin.Actor, err error) {
|
||||
var act basecoin.Actor
|
||||
for _, k := range strings.Split(nonce, ",") {
|
||||
for _, k := range strings.Split(key, ",") {
|
||||
act, err = bcmd.ParseAddress(k)
|
||||
if err != nil {
|
||||
return
|
||||
@ -62,3 +65,14 @@ func readNonceKey() (signers []basecoin.Actor, err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func readSequence() (uint32, error) {
|
||||
//add the nonce tx layer to the tx
|
||||
seq := viper.GetInt(FlagSequence)
|
||||
if seq > 0 {
|
||||
return uint32(seq), nil
|
||||
}
|
||||
|
||||
// TODO: try to download from query..
|
||||
return 0, fmt.Errorf("sequence must be greater than 0")
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user