From c3da09ed2dcc826dc43cab8bcad2ec1cd26ed6da Mon Sep 17 00:00:00 2001 From: Emil Bay Date: Fri, 17 Dec 2021 15:55:38 +0100 Subject: [PATCH 1/3] WIP transaction inspect util --- cmd/inspect-tx.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 cmd/inspect-tx.go diff --git a/cmd/inspect-tx.go b/cmd/inspect-tx.go new file mode 100644 index 00000000..73d1fc7a --- /dev/null +++ b/cmd/inspect-tx.go @@ -0,0 +1,45 @@ +package cmd + +import ( + "fmt" + "github.com/golang/protobuf/proto" + commandspb "code.vegaprotocol.io/protos/vega/commands/v1" + "github.com/golang/protobuf/jsonpb" + "github.com/spf13/cobra" +) + +var ( + rawTransaction []byte + inspectTxCmd = &cobra.Command{ + Use: "inspect-tx", + Short: "Inspect a raw Vega transaction", + RunE: runInspectTx, + } +) + +func init() { + rootCmd.AddCommand(inspectTxCmd) + inspectTxCmd.Flags().BytesBase64VarP(&rawTransaction, "tx", "t", []byte(""), "Base64 encoding of the raw Vega transaction to decode") + inspectTxCmd.MarkFlagRequired("tx") +} + +func runInspectTx(cmd *cobra.Command, args []string) error { + var tx = commandspb.Transaction{} + marshaler := jsonpb.Marshaler{ + Indent: " ", + } + + if err := proto.Unmarshal(rawTransaction, tx); err != nil { + fmt.Errorf("Couldn't unmarshal transaction: %w", err) + return nil + } + + g, err := marshaler.MarshalToString(tx) + if err != nil { + fmt.Errorf("Couldn't unmarshal transaction: %w", err) + return nil + } + + fmt.Println(g) + return nil +} From a40f6b8db15c56f1582fd4791c36db0ef2696bf0 Mon Sep 17 00:00:00 2001 From: Valentin Trinque Date: Fri, 17 Dec 2021 16:23:36 +0100 Subject: [PATCH 2/3] some fixes --- cmd/inspect-tx.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/cmd/inspect-tx.go b/cmd/inspect-tx.go index 73d1fc7a..afbb3075 100644 --- a/cmd/inspect-tx.go +++ b/cmd/inspect-tx.go @@ -2,15 +2,16 @@ package cmd import ( "fmt" - "github.com/golang/protobuf/proto" + commandspb "code.vegaprotocol.io/protos/vega/commands/v1" "github.com/golang/protobuf/jsonpb" + "github.com/golang/protobuf/proto" "github.com/spf13/cobra" ) var ( rawTransaction []byte - inspectTxCmd = &cobra.Command{ + inspectTxCmd = &cobra.Command{ Use: "inspect-tx", Short: "Inspect a raw Vega transaction", RunE: runInspectTx, @@ -24,20 +25,18 @@ func init() { } func runInspectTx(cmd *cobra.Command, args []string) error { - var tx = commandspb.Transaction{} + var tx = &commandspb.Transaction{} marshaler := jsonpb.Marshaler{ Indent: " ", } if err := proto.Unmarshal(rawTransaction, tx); err != nil { - fmt.Errorf("Couldn't unmarshal transaction: %w", err) - return nil + return fmt.Errorf("Couldn't unmarshal transaction: %w", err) } g, err := marshaler.MarshalToString(tx) if err != nil { - fmt.Errorf("Couldn't unmarshal transaction: %w", err) - return nil + return fmt.Errorf("Couldn't unmarshal transaction: %w", err) } fmt.Println(g) From 0440089825e121bfaa662c46d4182b51b939bfe1 Mon Sep 17 00:00:00 2001 From: Emil Bay Date: Mon, 7 Mar 2022 15:49:41 +0100 Subject: [PATCH 3/3] WIP inspect --- cmd/inspect-tx.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/cmd/inspect-tx.go b/cmd/inspect-tx.go index afbb3075..047f87d0 100644 --- a/cmd/inspect-tx.go +++ b/cmd/inspect-tx.go @@ -20,13 +20,14 @@ var ( func init() { rootCmd.AddCommand(inspectTxCmd) - inspectTxCmd.Flags().BytesBase64VarP(&rawTransaction, "tx", "t", []byte(""), "Base64 encoding of the raw Vega transaction to decode") + inspectTxCmd.Flags().BytesBase64VarP(&rawTransaction, "tx", "t", []byte(""), "Base64 encoding of the raw Vega to decode") inspectTxCmd.MarkFlagRequired("tx") } func runInspectTx(cmd *cobra.Command, args []string) error { var tx = &commandspb.Transaction{} - marshaler := jsonpb.Marshaler{ + var input_data = &commandspb.InputData{} + jsonMarshaler := jsonpb.Marshaler{ Indent: " ", } @@ -34,11 +35,21 @@ func runInspectTx(cmd *cobra.Command, args []string) error { return fmt.Errorf("Couldn't unmarshal transaction: %w", err) } - g, err := marshaler.MarshalToString(tx) + if err := proto.Unmarshal(tx.GetInputData(), input_data); err != nil { + return fmt.Errorf("Couldn't unmarshal input_data: %w", err) + } + + json, err := jsonMarshaler.MarshalToString(tx) if err != nil { - return fmt.Errorf("Couldn't unmarshal transaction: %w", err) + return fmt.Errorf("Couldn't serialise transaction: %w", err) + } + + json2, err := jsonMarshaler.MarshalToString(input_data) + if err != nil { + return fmt.Errorf("Couldn't serialise input_data: %w", err) } - fmt.Println(g) + fmt.Println(json) + fmt.Println(json2) return nil }