Skip to content

Commit

Permalink
Added handler of block type in console reader
Browse files Browse the repository at this point in the history
  • Loading branch information
jubeless committed Dec 11, 2023
1 parent 0c0e3e9 commit 711642b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
/dist
.envrc
.env
/firecore
.DS_Store
15 changes: 14 additions & 1 deletion consolereader.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ type parseCtx struct {
protoMessageType string
}

func (p *parseCtx) setProtoMessageType(typeURL string) {
if strings.HasPrefix(typeURL, "type.googleapis.com/") {
p.protoMessageType = typeURL
return
}
if strings.Contains(typeURL, "/") {
panic(fmt.Sprintf("invalid type url %q, expecting type.googleapis.com/", typeURL))
return
}
p.protoMessageType = "type.googleapis.com/" + typeURL
return
}

type ConsoleReader struct {
lines chan string
close func()
Expand Down Expand Up @@ -161,7 +174,7 @@ func (ctx *parseCtx) readInit(line string) error {
}

ctx.readerProtocolVersion = chunks[0]
ctx.protoMessageType = chunks[1]
ctx.setProtoMessageType(chunks[1])

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion consolereader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func Test_Ctx_readBlock(t *testing.T) {
ctx := &parseCtx{
readerProtocolVersion: "1.0",
protoMessageType: "sf.ethereum.type.v2.Block",
protoMessageType: "type.googleapis.com/sf.ethereum.type.v2.Block",
}

blockHash := "d2836a703a02f3ca2a13f05efe26fc48c6fa0db0d754a49e56b066d3b7d54659"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.15.0
github.com/streamingfast/bstream v0.0.2-0.20231208141508-a50f2c686c91
github.com/streamingfast/bstream v0.0.2-0.20231211192436-01f6a005b0e4
github.com/streamingfast/cli v0.0.4-0.20230825151644-8cc84512cd80
github.com/streamingfast/dauth v0.0.0-20231120142446-843f4e045cc2
github.com/streamingfast/dbin v0.9.1-0.20231117225723-59790c798e2c
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,8 @@ github.com/spf13/viper v1.15.0/go.mod h1:fFcTBJxvhhzSJiZy8n+PeW6t8l+KeT/uTARa0jH
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
github.com/streamingfast/bstream v0.0.2-0.20231208141508-a50f2c686c91 h1:v+r1jME46+c6jNqRfD2nSFXTY59wwNxCoxGS826yjTQ=
github.com/streamingfast/bstream v0.0.2-0.20231208141508-a50f2c686c91/go.mod h1:08GVb+DXyz6jVNIsbf+2zlaC81UeEGu5o1h49KrSR3Y=
github.com/streamingfast/bstream v0.0.2-0.20231211192436-01f6a005b0e4 h1:WFXOC6fg2k9CuxUhbgtH7IYOZvu0CEPXuGRitS74YwQ=
github.com/streamingfast/bstream v0.0.2-0.20231211192436-01f6a005b0e4/go.mod h1:08GVb+DXyz6jVNIsbf+2zlaC81UeEGu5o1h49KrSR3Y=
github.com/streamingfast/cli v0.0.4-0.20230825151644-8cc84512cd80 h1:UxJUTcEVkdZy8N77E3exz0iNlgQuxl4m220GPvzdZ2s=
github.com/streamingfast/cli v0.0.4-0.20230825151644-8cc84512cd80/go.mod h1:QxjVH73Lkqk+mP8bndvhMuQDUINfkgsYhdCH/5TJFKI=
github.com/streamingfast/dauth v0.0.0-20231120142446-843f4e045cc2 h1:g4mG6ZCy3/XtcsZXfOHrQOsjVGoX9uTc/QlemaPV4EE=
Expand Down

0 comments on commit 711642b

Please sign in to comment.