Refactor field printing
@@ -5,6 +5,7 @@ import (
"fmt"
"time"
+ "github.com/onflow/cadence"
"github.com/onflow/flow-go-sdk"
"github.com/onflow/flow-go-sdk/client"
"google.golang.org/grpc"
@@ -100,8 +101,23 @@ func printEvents(events []flow.Event, txID bool) {
}
fmt.Println(" Fields:")
for i, field := range event.Value.EventType.Fields {
- v := event.Value.Fields[i].ToGoValue()
+ value := event.Value.Fields[i]
+ printField(field, value)
+ }
+ }
+}
+
+func isByteSlice(v interface{}) bool {
+ slice, isSlice := v.([]interface{})
+ if !isSlice {
+ return false
+ }
+ _, isBytes := slice[0].(byte)
+ return isBytes
+}
+func printField(field cadence.Field, value cadence.Value) {
+ v := value.ToGoValue()
typeInfo := "Unknown"
if field.Type != nil {
typeInfo = field.Type.ID()
@@ -118,21 +134,10 @@ func printEvents(events []flow.Event, txID bool) {
for _, b := range v.([]interface{}) {
fmt.Printf("%x", b)
}
- } else if uintVal, ok := v.(uint64); field.Type.ID() == "UFix64" && ok {
+ } else if uintVal, ok := v.(uint64); typeInfo == "UFix64" && ok {
fmt.Print(FormatFLOW(uintVal))
} else {
fmt.Printf("%v", v)
}
fmt.Println()
}
- }
-}
-
-func isByteSlice(v interface{}) bool {
- slice, isSlice := v.([]interface{})
- if !isSlice {
- return false
- }
- _, isBytes := slice[0].(byte)
- return isBytes
-}
