diff --git a/pkg/vm/output.go b/pkg/vm/output.go index 4cad005d8..14e83103b 100644 --- a/pkg/vm/output.go +++ b/pkg/vm/output.go @@ -9,7 +9,7 @@ type stackItem struct { Type string `json:"type"` } -func buildStackOutput(s *Stack) string { +func stackToArray(s *Stack) []stackItem { items := make([]stackItem, 0, s.Len()) s.Iter(func(e *Element) { items = append(items, stackItem{ @@ -17,7 +17,10 @@ func buildStackOutput(s *Stack) string { Type: e.value.String(), }) }) + return items +} - b, _ := json.MarshalIndent(items, "", " ") +func buildStackOutput(s *Stack) string { + b, _ := json.MarshalIndent(stackToArray(s), "", " ") return string(b) } diff --git a/pkg/vm/stack.go b/pkg/vm/stack.go index f295d1e59..13a6c0f75 100644 --- a/pkg/vm/stack.go +++ b/pkg/vm/stack.go @@ -1,6 +1,7 @@ package vm import ( + "encoding/json" "fmt" "math/big" @@ -334,3 +335,8 @@ func (s *Stack) popSigElements() ([][]byte, error) { } return elems, nil } + +// MarshalJSON implements JSON marshalling interface. +func (s *Stack) MarshalJSON() ([]byte, error) { + return json.Marshal(stackToArray(s)) +}