forked from graphprotocol/firehose-cosmos
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
474 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,2 @@ | ||
*.lz4 | ||
/.idea | ||
/injective/.idea/ | ||
/injective/devel/.env | ||
/injective/devel/data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
module github.com/streamingfast/firehose-cosmos/cosmos | ||
|
||
go 1.22 | ||
go 1.22.0 | ||
|
||
toolchain go1.22.0 | ||
|
||
require google.golang.org/protobuf v1.33.0 | ||
require github.com/google/go-cmp v0.6.0 // indirect | ||
|
||
replace github.com/jhump/protoreflect => github.com/streamingfast/protoreflect v0.0.0-20231205191344-4b629d20ce8d | ||
toolchain go1.22.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= | ||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= | ||
github.com/streamingfast/bstream v0.0.2-0.20240619142813-9d23840859bf/go.mod h1:n5wy+Vmwp4xbjXO7B81MAkAgjnf1vJ/lI2y6hWWyFbg= | ||
github.com/streamingfast/firehose-core v1.5.8-0.20240814134036-ad3d137d66d4/go.mod h1:QR6NRnN9EEXVAtMJ05YEisd5UesdMoY9liILX1WzFgs= | ||
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= | ||
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"unicode/utf8" | ||
|
||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
var UnmarshallerDiscardUnknown = &proto.UnmarshalOptions{ | ||
DiscardUnknown: true, | ||
} | ||
|
||
func ArrayToPointerArray[T any](ts []T) []*T { | ||
res := make([]*T, len(ts)) | ||
for i, t := range ts { | ||
res[i] = &t | ||
} | ||
return res | ||
} | ||
|
||
func ArrayProtoFlip[U cosmoProto.Message, V proto.Message](origins []U, targets []V) error { | ||
if len(origins) != len(targets) { | ||
return fmt.Errorf("origin and target arrays have different lengths: %d != %d", len(origins), len(targets)) | ||
} | ||
if len(origins) == 0 { | ||
return nil | ||
} | ||
|
||
for i := range origins { | ||
err := ProtoFlip(origins[i], targets[i]) | ||
if err != nil { | ||
return fmt.Errorf("converting element %d: %w", i, err) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func ProtoFlip(origin cosmoProto.Message, target proto.Message) error { | ||
if origin == nil || reflect.ValueOf(origin).IsNil() { | ||
return nil | ||
} | ||
//marshall origin the unmarshall to target | ||
data, err := cosmoProto.Marshal(origin) | ||
if err != nil { | ||
return fmt.Errorf("mashalling origin object %T: %w", data, err) | ||
} | ||
|
||
err = UnmarshallerDiscardUnknown.Unmarshal(data, target) | ||
if err != nil { | ||
return fmt.Errorf("unmashalling target object %T: %w", data, err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func FixUtf(r rune) rune { | ||
if r == utf8.RuneError { | ||
fmt.Println("found rune error") | ||
return '�' | ||
} | ||
return r | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/streamingfast/firehose-cosmos/cosmos/cmd" | ||
"github.com/streamingfast/logging" | ||
"go.uber.org/zap" | ||
) | ||
|
||
var logger, tracer = logging.PackageLogger("firecosmos", "github.com/streamingfast/firehose-cosmos") | ||
var rootCmd = &cobra.Command{ | ||
Use: "fireinjective", | ||
Short: "injective block fetching and tooling", | ||
Args: cobra.ExactArgs(1), | ||
} | ||
|
||
func init() { | ||
logging.InstantiateLoggers(logging.WithDefaultLevel(zap.InfoLevel)) | ||
|
||
fetchCmd := &cobra.Command{ | ||
Use: "fetch", | ||
Short: "fetch blocks from different sources", | ||
Args: cobra.ExactArgs(2), | ||
} | ||
fetchCmd.AddCommand(cmd.NewFetchRPCCmd(logger, tracer, "mantra")) | ||
|
||
rootCmd.AddCommand(fetchCmd) | ||
rootCmd.AddCommand(cmd.NewToolsFixUnknownTypeBlocks(logger, tracer)) | ||
} | ||
|
||
func main() { | ||
if err := rootCmd.Execute(); err != nil { | ||
_, _ = fmt.Fprintf(os.Stderr, "Whoops. There was an error while executing your CLI '%s'", err) | ||
os.Exit(1) | ||
} | ||
} |
Oops, something went wrong.