Helper function

This commit is contained in:
Christopher Goes
2018-04-10 11:16:30 +02:00
parent ec98545a1b
commit bd626ba94e
2 changed files with 19 additions and 11 deletions
+16
View File
@@ -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
}