Helper function
This commit is contained in:
parent
ec98545a1b
commit
bd626ba94e
|
@ -2,6 +2,7 @@ package context
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/spf13/viper"
|
||||
"io/ioutil"
|
||||
|
||||
|
@ -47,3 +48,18 @@ func NewCoreContextFromViper() core.CoreContext {
|
|||
AccountStore: "main",
|
||||
}
|
||||
}
|
||||
|
||||
// Automatically set sequence number
|
||||
func AutoSequence(ctx core.CoreContext) (core.CoreContext, error) {
|
||||
from, err := ctx.GetFromAddress()
|
||||
if err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
seq, err := ctx.NextSequence(from)
|
||||
if err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
fmt.Printf("Defaulting to next sequence number: %d\n", seq)
|
||||
ctx = ctx.WithSequence(seq)
|
||||
return ctx, nil
|
||||
}
|
||||
|
|
|
@ -64,17 +64,9 @@ func (c Commander) sendTxCmd(cmd *cobra.Command, args []string) error {
|
|||
msg := BuildMsg(from, to, coins)
|
||||
|
||||
// default to next sequence number if none provided
|
||||
if viper.GetInt64(client.FlagSequence) == 0 {
|
||||
from, err := ctx.GetFromAddress()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
seq, err := ctx.NextSequence(from)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Defaulting to next sequence number: %d\n", seq)
|
||||
ctx = ctx.WithSequence(seq)
|
||||
ctx, err = context.AutoSequence(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// build and sign the transaction, then broadcast to Tendermint
|
||||
|
|
Loading…
Reference in New Issue