Skip to content

Commit

Permalink
fix matching of well-known protocols on blocktype without type.google…
Browse files Browse the repository at this point in the history
…apis.com
  • Loading branch information
sduchesneau committed Aug 27, 2024
1 parent de657a9 commit ac38d56
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
4 changes: 3 additions & 1 deletion firehose/info/info_filler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package info

import (
"fmt"
"strings"

pbbstream "github.com/streamingfast/bstream/pb/sf/bstream/v1"
wellknown "github.com/streamingfast/firehose-core/well-known"
Expand All @@ -11,8 +12,9 @@ import (
var DefaultInfoResponseFiller = func(firstStreamableBlock *pbbstream.Block, resp *pbfirehose.InfoResponse, validate bool) error {
resp.FirstStreamableBlockId = firstStreamableBlock.Id

shortTypeURL := strings.TrimPrefix(firstStreamableBlock.Payload.TypeUrl, "type.googleapis.com/")
for _, protocol := range wellknown.WellKnownProtocols {
if protocol.BlockType == firstStreamableBlock.Payload.TypeUrl {
if protocol.BlockType == shortTypeURL {
resp.BlockIdEncoding = protocol.BytesEncoding
break
}
Expand Down
22 changes: 11 additions & 11 deletions well-known/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

type WellKnownProtocol struct {
Name string
BlockType string
BlockType string // we always trim `type.googleapis.com/`
BufBuildURL string
BytesEncoding pbfirehose.InfoResponse_BlockIdEncoding
KnownChains []*Chain
Expand All @@ -31,7 +31,7 @@ type WellKnownProtocolList []WellKnownProtocol
var WellKnownProtocols = WellKnownProtocolList([]WellKnownProtocol{
{
Name: "ethereum",
BlockType: "type.googleapis.com/sf.ethereum.type.v2.Block",
BlockType: "sf.ethereum.type.v2.Block",
BufBuildURL: "buf.build/streamingfast/firehose-ethereum",
BytesEncoding: pbfirehose.InfoResponse_BLOCK_ID_ENCODING_HEX,
KnownChains: []*Chain{
Expand Down Expand Up @@ -112,7 +112,7 @@ var WellKnownProtocols = WellKnownProtocolList([]WellKnownProtocol{
},
{
Name: "near",
BlockType: "type.googleapis.com/sf.near.type.v1.Block",
BlockType: "sf.near.type.v1.Block",
BufBuildURL: "buf.build/streamingfast/firehose-near",
BytesEncoding: pbfirehose.InfoResponse_BLOCK_ID_ENCODING_BASE58,
KnownChains: []*Chain{
Expand All @@ -132,7 +132,7 @@ var WellKnownProtocols = WellKnownProtocolList([]WellKnownProtocol{
},
{
Name: "solana",
BlockType: "type.googleapis.com/sf.solana.type.v1.Block",
BlockType: "sf.solana.type.v1.Block",
BufBuildURL: "buf.build/streamingfast/firehose-solana",
BytesEncoding: pbfirehose.InfoResponse_BLOCK_ID_ENCODING_BASE58,
KnownChains: []*Chain{
Expand All @@ -146,7 +146,7 @@ var WellKnownProtocols = WellKnownProtocolList([]WellKnownProtocol{
},
{
Name: "bitcoin",
BlockType: "type.googleapis.com/sf.bitcoin.type.v1.Block",
BlockType: "sf.bitcoin.type.v1.Block",
BufBuildURL: "buf.build/streamingfast/firehose-bitcoin",
BytesEncoding: pbfirehose.InfoResponse_BLOCK_ID_ENCODING_HEX,
KnownChains: []*Chain{
Expand All @@ -160,7 +160,7 @@ var WellKnownProtocols = WellKnownProtocolList([]WellKnownProtocol{
},
{
Name: "antelope",
BlockType: "type.googleapis.com/sf.antelope.type.v1.Block",
BlockType: "sf.antelope.type.v1.Block",
BufBuildURL: "buf.build/pinax/firehose-antelope",
BytesEncoding: pbfirehose.InfoResponse_BLOCK_ID_ENCODING_HEX,
KnownChains: []*Chain{
Expand All @@ -186,7 +186,7 @@ var WellKnownProtocols = WellKnownProtocolList([]WellKnownProtocol{
},
{
Name: "arweave",
BlockType: "type.googleapis.com/sf.arweave.type.v1.Block",
BlockType: "sf.arweave.type.v1.Block",
BufBuildURL: "buf.build/pinax/firehose-arweave",
BytesEncoding: pbfirehose.InfoResponse_BLOCK_ID_ENCODING_HEX, // even though the usual encoding is base64url, firehose blocks are written with the hex-encoded version
KnownChains: []*Chain{
Expand All @@ -200,7 +200,7 @@ var WellKnownProtocols = WellKnownProtocolList([]WellKnownProtocol{
},
{
Name: "beacon",
BlockType: "type.googleapis.com/sf.beacon.type.v1.Block",
BlockType: "sf.beacon.type.v1.Block",
BufBuildURL: "buf.build/pinax/firehose-beacon",
BytesEncoding: pbfirehose.InfoResponse_BLOCK_ID_ENCODING_0X_HEX,
KnownChains: []*Chain{
Expand All @@ -226,7 +226,7 @@ var WellKnownProtocols = WellKnownProtocolList([]WellKnownProtocol{
},
{
Name: "starknet",
BlockType: "type.googleapis.com/sf.starknet.type.v1.Block",
BlockType: "sf.starknet.type.v1.Block",
BufBuildURL: "buf.build/streamingfast/firehose-starknet",
BytesEncoding: pbfirehose.InfoResponse_BLOCK_ID_ENCODING_0X_HEX,
KnownChains: []*Chain{
Expand All @@ -246,7 +246,7 @@ var WellKnownProtocols = WellKnownProtocolList([]WellKnownProtocol{
},
{
Name: "cosmos",
BlockType: "type.googleapis.com/sf.cosmos.type.v2.Block",
BlockType: "sf.cosmos.type.v2.Block",
BufBuildURL: "buf.build/streamingfast/firehose-cosmos",
BytesEncoding: pbfirehose.InfoResponse_BLOCK_ID_ENCODING_HEX,
KnownChains: []*Chain{
Expand All @@ -266,7 +266,7 @@ var WellKnownProtocols = WellKnownProtocolList([]WellKnownProtocol{
},
{
Name: "gear",
BlockType: "type.googleapis.com/sf.gear.type.v1.Block",
BlockType: "sf.gear.type.v1.Block",
BufBuildURL: "buf.build/streamingfast/firehose-gear",
BytesEncoding: pbfirehose.InfoResponse_BLOCK_ID_ENCODING_HEX,
KnownChains: []*Chain{
Expand Down

0 comments on commit ac38d56

Please sign in to comment.