From 6a078f0faf840b99ef70b36d69ef949ffc7f226e Mon Sep 17 00:00:00 2001 From: Eduard Voiculescu Date: Mon, 20 Jan 2025 10:03:25 -0500 Subject: [PATCH] adding decode_block tool cmd --- cmd/firestellar/main.go | 6 ++++-- decoder/decoder.go | 27 +++++++++++++++++++++++++++ go.mod | 10 ++++++---- go.sum | 20 ++++++++++++-------- rpc/fetcher.go | 5 +++++ 5 files changed, 54 insertions(+), 14 deletions(-) diff --git a/cmd/firestellar/main.go b/cmd/firestellar/main.go index a574bb2..031cb12 100644 --- a/cmd/firestellar/main.go +++ b/cmd/firestellar/main.go @@ -3,7 +3,6 @@ package main import ( "fmt" "os" - "time" "github.com/spf13/cobra" "github.com/streamingfast/logging" @@ -20,6 +19,10 @@ var rootCmd = &cobra.Command{ func init() { logging.InstantiateLoggers(logging.WithDefaultLevel(zap.InfoLevel)) rootCmd.AddCommand(newFetchCmd(logger, tracer)) + + // Tool commands + rootCmd.AddCommand(NewToolCreateAccountCmd(logger, tracer)) + rootCmd.AddCommand(NewToolDecodeBlockCmd(logger, tracer)) } func main() { @@ -35,7 +38,6 @@ func newFetchCmd(logger *zap.Logger, tracer logging.Tracer) *cobra.Command { Short: "fetch blocks from different sources", Args: cobra.ExactArgs(2), } - time.Now().UnixMilli() cmd.AddCommand(NewFetchCmd(logger, tracer)) return cmd } diff --git a/decoder/decoder.go b/decoder/decoder.go index 70ce8f4..934d8e5 100644 --- a/decoder/decoder.go +++ b/decoder/decoder.go @@ -49,6 +49,15 @@ func (d *Decoder) DecodeTransactionEnvelope(envelopeXdr string) (*xdrTypes.Trans return &envelope, nil } +func (d *Decoder) DecodeTransactionEnvelopeFromBytes(envelopeXdr []byte) (*xdrTypes.TransactionEnvelope, error) { + var envelope xdrTypes.TransactionEnvelope + _, err := xdr.Unmarshal(bytes.NewBuffer(envelopeXdr), &envelope) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal transaction envelope XDR: %w", err) + } + return &envelope, nil +} + // TODO: convert all the result types of the operations in their protobuf equivalent func (d *Decoder) DecodeTransactionResult(resultXdr string) (*xdrTypes.TransactionResult, error) { data, err := base64.StdEncoding.DecodeString(resultXdr) @@ -64,6 +73,15 @@ func (d *Decoder) DecodeTransactionResult(resultXdr string) (*xdrTypes.Transacti return &result, nil } +func (d *Decoder) DecodeTransactionResultFromBytes(resultXdr []byte) (*xdrTypes.TransactionResult, error) { + var result xdrTypes.TransactionResult + _, err := xdr.Unmarshal(bytes.NewBuffer(resultXdr), &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal transaction result XDR: %w", err) + } + return &result, nil +} + func (d *Decoder) DecodeTransactionResultMeta(resultMetaXd string) (*xdrTypes.TransactionMeta, error) { data, err := base64.StdEncoding.DecodeString(resultMetaXd) if err != nil { @@ -77,3 +95,12 @@ func (d *Decoder) DecodeTransactionResultMeta(resultMetaXd string) (*xdrTypes.Tr } return &transactionMeta, nil } + +func (d *Decoder) DecodeTransactionResultMetaFromBytes(resultMetaBytes []byte) (*xdrTypes.TransactionMeta, error) { + var transactionMeta xdrTypes.TransactionMeta + _, err := xdr.Unmarshal(bytes.NewBuffer(resultMetaBytes), &transactionMeta) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal transaction meta XDR: %w", err) + } + return &transactionMeta, nil +} diff --git a/go.mod b/go.mod index 732e666..897d0a9 100644 --- a/go.mod +++ b/go.mod @@ -6,13 +6,14 @@ require ( github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 github.com/spf13/cobra v1.8.1 github.com/streamingfast/bstream v0.0.2-0.20250114192704-6a23c67c0b4d - github.com/streamingfast/cli v0.0.4-0.20241204195552-16b367a5935e - github.com/streamingfast/firehose-core v1.6.10-0.20250115205411-9be23e08f63a + github.com/streamingfast/cli v0.0.4-0.20250116003948-fbf66c930cce + github.com/streamingfast/firehose-core v1.7.0 github.com/streamingfast/logging v0.0.0-20230608130331-f22c91403091 go.uber.org/zap v1.27.0 ) require ( + github.com/mr-tron/base58 v1.2.0 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/sagikazarmark/locafero v0.3.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect @@ -65,6 +66,7 @@ require ( github.com/envoyproxy/protoc-gen-validate v1.1.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/go-json-experiment/json v0.0.0-20250116043007-0640c115aea5 github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect @@ -122,7 +124,7 @@ require ( github.com/streamingfast/dauth v0.0.0-20240222213226-519afc16cf84 // indirect github.com/streamingfast/dbin v0.9.1-0.20231117225723-59790c798e2c // indirect github.com/streamingfast/derr v0.0.0-20230515163924-8570aaa43fe1 // indirect - github.com/streamingfast/dgrpc v0.0.0-20250109212433-ae21a7f7a01a // indirect + github.com/streamingfast/dgrpc v0.0.0-20250115215805-6f4ad2be7eef // indirect github.com/streamingfast/dhammer v0.0.0-20230125192823-c34bbd561bd4 // indirect github.com/streamingfast/dmetering v0.0.0-20241101155221-489f5a9d9139 // indirect github.com/streamingfast/dmetrics v0.0.0-20230919161904-206fa8ebd545 // indirect @@ -132,7 +134,7 @@ require ( github.com/streamingfast/pbgo v0.0.6-0.20250114182320-0b43084f4000 // indirect github.com/streamingfast/sf-tracing v0.0.0-20240430173521-888827872b90 // indirect github.com/streamingfast/shutter v1.5.0 // indirect - github.com/streamingfast/substreams v1.11.4-0.20250113142113-36c2750be692 // indirect + github.com/streamingfast/substreams v1.12.0 // indirect github.com/stretchr/testify v1.9.0 github.com/subosito/gotenv v1.6.0 // indirect github.com/teris-io/shortid v0.0.0-20201117134242-e59966efd125 // indirect diff --git a/go.sum b/go.sum index 8d17086..259a662 100644 --- a/go.sum +++ b/go.sum @@ -208,6 +208,8 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-json-experiment/json v0.0.0-20250116043007-0640c115aea5 h1:MZu1NBx4m+lYVrt55nFcKb3Fze2F7LUwJXyywvNm11A= +github.com/go-json-experiment/json v0.0.0-20250116043007-0640c115aea5/go.mod h1:BWmvoE1Xia34f3l/ibJweyhrT+aROb/FQ6d+37F0e2s= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -392,6 +394,8 @@ github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJ github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= +github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/mschoch/smat v0.2.0 h1:8imxQsjDm8yFEAVBe7azKmKSgzSkZXDuKkSq9374khM= github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw= github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a h1:2MaM6YC3mGu54x+RKAA6JiFFHlHDY1UbkxqppT7wYOg= @@ -480,16 +484,16 @@ github.com/stellar/go-xdr v0.0.0-20231122183749-b53fb00bcac2 h1:OzCVd0SV5qE3ZcDe github.com/stellar/go-xdr v0.0.0-20231122183749-b53fb00bcac2/go.mod h1:yoxyU/M8nl9LKeWIoBrbDPQ7Cy+4jxRcWcOayZ4BMps= github.com/streamingfast/bstream v0.0.2-0.20250114192704-6a23c67c0b4d h1:5cGG1t9rwbAwXeTq9epU7hm6cBsC2V8DM2jVCIN6JSo= github.com/streamingfast/bstream v0.0.2-0.20250114192704-6a23c67c0b4d/go.mod h1:n5wy+Vmwp4xbjXO7B81MAkAgjnf1vJ/lI2y6hWWyFbg= -github.com/streamingfast/cli v0.0.4-0.20241204195552-16b367a5935e h1:SoA0Yr852Ci4z8taHEn33bw2MWWHfAQ2QfCsbAM/ZG8= -github.com/streamingfast/cli v0.0.4-0.20241204195552-16b367a5935e/go.mod h1:qOksW3DPhHVYBo8dcYxS7K3Q09wlcOChSdopeOjLWng= +github.com/streamingfast/cli v0.0.4-0.20250116003948-fbf66c930cce h1:RWla1PaRrlDf/MOwVoN/dJhIM/dXa9O4rmKZkv9T5bg= +github.com/streamingfast/cli v0.0.4-0.20250116003948-fbf66c930cce/go.mod h1:qOksW3DPhHVYBo8dcYxS7K3Q09wlcOChSdopeOjLWng= github.com/streamingfast/dauth v0.0.0-20240222213226-519afc16cf84 h1:yCvuNcwQ21J4Ua6YrAmHDBx3bjK04y+ssEYBe65BXRU= github.com/streamingfast/dauth v0.0.0-20240222213226-519afc16cf84/go.mod h1:cwfI5vaMd+CiwZIL0H0JdP5UDWCZOVFz/ex3L0+o/j4= github.com/streamingfast/dbin v0.9.1-0.20231117225723-59790c798e2c h1:6WjE2yInE+5jnI7cmCcxOiGZiEs2FQm9Zsg2a9Ivp0Q= github.com/streamingfast/dbin v0.9.1-0.20231117225723-59790c798e2c/go.mod h1:dbfiy9ORrL8c6ldSq+L0H9pg8TOqqu/FsghsgUEWK54= github.com/streamingfast/derr v0.0.0-20230515163924-8570aaa43fe1 h1:xJB7rXnOHLesosMjfwWsEL2i/40mFSkzenEb3M0qTyM= github.com/streamingfast/derr v0.0.0-20230515163924-8570aaa43fe1/go.mod h1:QSm/AfaDsE0k1xBYi0lW580YJ/WDV/FKZI628tkZR0Y= -github.com/streamingfast/dgrpc v0.0.0-20250109212433-ae21a7f7a01a h1:yrxCZ7Py0FdMu80cWPv/EpDvBLyumPlfhehD7iJ5VJM= -github.com/streamingfast/dgrpc v0.0.0-20250109212433-ae21a7f7a01a/go.mod h1:bxRfCxRKQ0ZH2BGi6UcYdlH0nkj8yERm3kpP1jPLQLY= +github.com/streamingfast/dgrpc v0.0.0-20250115215805-6f4ad2be7eef h1:He9qXjmnDtxVrJcHAOfFiWFA6An48zTezpU5iMnNHuY= +github.com/streamingfast/dgrpc v0.0.0-20250115215805-6f4ad2be7eef/go.mod h1:bxRfCxRKQ0ZH2BGi6UcYdlH0nkj8yERm3kpP1jPLQLY= github.com/streamingfast/dhammer v0.0.0-20230125192823-c34bbd561bd4 h1:HKi8AIkLBzxZWmbCRUo1RxoOLK33iXO6gZprfsE9rf4= github.com/streamingfast/dhammer v0.0.0-20230125192823-c34bbd561bd4/go.mod h1:ehPytv7E4rI65iLcrwTes4rNGGqPPiugnH+20nDQyp4= github.com/streamingfast/dmetering v0.0.0-20241101155221-489f5a9d9139 h1:a22XzjeY7n9Xv+0yJMV2pzuPptALtOu6jdg69pOwuO4= @@ -500,8 +504,8 @@ github.com/streamingfast/dstore v0.1.1-0.20241011152904-9acd6205dc14 h1:/2HxIOzA github.com/streamingfast/dstore v0.1.1-0.20241011152904-9acd6205dc14/go.mod h1:kNzxgv2MzYFn2T4kelBVpGp/yP/1njtr3+csWuqxK3w= github.com/streamingfast/dtracing v0.0.0-20220305214756-b5c0e8699839 h1:K6mJPvh1jAL+/gBS7Bh9jyzWaTib6N47m06gZOTUPwQ= github.com/streamingfast/dtracing v0.0.0-20220305214756-b5c0e8699839/go.mod h1:huOJyjMYS6K8upTuxDxaNd+emD65RrXoVBvh8f1/7Ns= -github.com/streamingfast/firehose-core v1.6.10-0.20250115205411-9be23e08f63a h1:wmLbLGvY0WOSjOVb/pLIroy98TynMTyY//PRF6coVFg= -github.com/streamingfast/firehose-core v1.6.10-0.20250115205411-9be23e08f63a/go.mod h1:oo8rhLxG8+3whIrGvi+P8FF6pdlsuKnoLKh/TjZQ73U= +github.com/streamingfast/firehose-core v1.7.0 h1:jBbFwGtLniXmddSP+3uhZOrrK2522+C+DMMdQydYOXw= +github.com/streamingfast/firehose-core v1.7.0/go.mod h1:V1JaIfMtnK8fwdSRSNtm9vW6qtyf4P/wsptgSmcM21Y= github.com/streamingfast/logging v0.0.0-20210811175431-f3b44b61606a/go.mod h1:4GdqELhZOXj4xwc4IaBmzofzdErGynnaSzuzxy0ZIBo= github.com/streamingfast/logging v0.0.0-20220304183711-ddba33d79e27/go.mod h1:4GdqELhZOXj4xwc4IaBmzofzdErGynnaSzuzxy0ZIBo= github.com/streamingfast/logging v0.0.0-20220304214715-bc750a74b424/go.mod h1:VlduQ80JcGJSargkRU4Sg9Xo63wZD/l8A5NC/Uo1/uU= @@ -515,8 +519,8 @@ github.com/streamingfast/sf-tracing v0.0.0-20240430173521-888827872b90 h1:94Hllk github.com/streamingfast/sf-tracing v0.0.0-20240430173521-888827872b90/go.mod h1:e6tKS/udlfXFUTQBYfDDdISfjULvQXet1kBrOeRfgI4= github.com/streamingfast/shutter v1.5.0 h1:NpzDYzj0HVpSiDJVO/FFSL6QIK/YKOxY0gJAtyaTOgs= github.com/streamingfast/shutter v1.5.0/go.mod h1:B/T6efqdeMGbGwjzPS1ToXzYZI4kDzI5/u4I+7qbjY8= -github.com/streamingfast/substreams v1.11.4-0.20250113142113-36c2750be692 h1:YrIj24iHkkdhzWHVNqdjdL76BqEOs9PxMjW8ejbEGnk= -github.com/streamingfast/substreams v1.11.4-0.20250113142113-36c2750be692/go.mod h1:gl4g6eqMV3tAvir2J+3tY/JfXwm3TThHe7VL53glywE= +github.com/streamingfast/substreams v1.12.0 h1:AhsXsJTmwukurvD65YVqcEkIdFjSa0S1HO3sU4Vq7sY= +github.com/streamingfast/substreams v1.12.0/go.mod h1:Dgbt37alWqMyahFQ4rdhX8iFLZHn2qD8TBhcP3NIuW8= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= diff --git a/rpc/fetcher.go b/rpc/fetcher.go index 3383341..eb5adc6 100644 --- a/rpc/fetcher.go +++ b/rpc/fetcher.go @@ -97,6 +97,11 @@ func (f *Fetcher) Fetch(ctx context.Context, client *Client, requestBlockNum uin transactionMeta := make([]*types.TransactionMeta, 0) for _, trx := range transactions { + // FIXME: change to use txHashBytes with the hex encoding + // txHashbytes, err := hex.DecodeString(trx.TxHash) + // if err != nil { + // return nil, false, fmt.Errorf("decoding transaction hash: %w", err) + // } txHashBytes, err := base64.StdEncoding.DecodeString(trx.TxHash) if err != nil { return nil, false, fmt.Errorf("decoding transaction hash: %w", err)