From e27a30bacf61ec4578b615be45bee42838b2f2fa Mon Sep 17 00:00:00 2001 From: oysheng <33340252+oysheng@users.noreply.github.com> Date: Sun, 8 Apr 2018 14:28:21 +0800 Subject: [PATCH] fix tx actions only contain spend and will be success (#544) * fix tx actions only contain spend and tx will be success * modify func name --- api/transact.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/api/transact.go b/api/transact.go index 58b96524..be2cf05a 100644 --- a/api/transact.go +++ b/api/transact.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "strings" "time" log "github.com/sirupsen/logrus" @@ -69,11 +70,27 @@ func mergeActions(req *BuildRequest) []map[string]interface{} { return actions } +func onlyHaveSpendActions(req *BuildRequest) bool { + count := 0 + for _, m := range req.Actions { + if actionType := m["type"].(string); strings.HasPrefix(actionType, "spend") { + count++ + } + } + + return count == len(req.Actions) +} + func (a *API) buildSingle(ctx context.Context, req *BuildRequest) (*txbuilder.Template, error) { err := a.filterAliases(ctx, req) if err != nil { return nil, err } + + if onlyHaveSpendActions(req) { + return nil, errors.New("transaction only contain spend actions, didn't have output actions") + } + reqActions := mergeActions(req) actions := make([]txbuilder.Action, 0, len(reqActions)) for i, act := range reqActions { -- 2.11.0