Skip to content

Commit

Permalink
info: basic and extended versions of info
Browse files Browse the repository at this point in the history
  • Loading branch information
colindickson committed Sep 20, 2023
1 parent ffd191a commit 5266d08
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 52 deletions.
7 changes: 1 addition & 6 deletions cmd/substreams/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ func runInfo(cmd *cobra.Command, args []string) error {
outputModule = args[1]
}

var infoOptions []info.InfoOption
if outputModule != "" {
infoOptions = append(infoOptions, info.WithOutputModule(outputModule))
}

info, err := info.Info(manifestPath, infoOptions...)
info, err := info.Extended(manifestPath, outputModule)
if err != nil {
return err
}
Expand Down
77 changes: 35 additions & 42 deletions info/info.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
package info

import (
"encoding/json"
"fmt"
"github.com/streamingfast/substreams/manifest"
"github.com/streamingfast/substreams/pipeline/outputmodules"
"strings"

"github.com/streamingfast/substreams/manifest"
pbsubstreams "github.com/streamingfast/substreams/pb/sf/substreams/v1"
"google.golang.org/protobuf/types/descriptorpb"
)

type ManifestInfo struct {
type BasicInfo struct {
Name string `json:"name"`
Version string `json:"version"`
Documentation *string `json:"documentation,omitempty"`
Modules []ModulesInfo `json:"modules"`
ProtoFiles []ProtoFileInfo `json:"proto_files"`
}

type ExtendedInfo struct {
*BasicInfo

ExecutionStages [][][]string `json:"execution_stages,omitempty"`
}
Expand Down Expand Up @@ -48,24 +51,7 @@ type ModuleInput struct {
Mode *string `json:"mode,omitempty"` //for store inputs
}

type InfoConfig struct {
OutputModule *string
}

type InfoOption func(*InfoConfig)

func WithOutputModule(outputModule string) InfoOption {
return func(options *InfoConfig) {
options.OutputModule = strPtr(outputModule)
}
}

func Info(manifestPath string, opts ...InfoOption) (*ManifestInfo, error) {
config := &InfoConfig{}
for _, opt := range opts {
opt(config)
}

func Basic(manifestPath string) (*BasicInfo, error) {
reader, err := manifest.NewReader(manifestPath)
if err != nil {
return nil, fmt.Errorf("manifest reader: %w", err)
Expand All @@ -76,7 +62,7 @@ func Info(manifestPath string, opts ...InfoOption) (*ManifestInfo, error) {
return nil, fmt.Errorf("read manifest %q: %w", manifestPath, err)
}

manifestInfo := &ManifestInfo{
manifestInfo := &BasicInfo{
Name: pkg.PackageMeta[0].Name,
Version: pkg.PackageMeta[0].Version,
}
Expand Down Expand Up @@ -159,9 +145,30 @@ func Info(manifestPath string, opts ...InfoOption) (*ManifestInfo, error) {
})
}

manifestInfo.Modules = modules
manifestInfo.ProtoFiles = protoFiles

return manifestInfo, nil
}

func Extended(manifestPath string, outputModule string) (*ExtendedInfo, error) {
basicInfo, err := Basic(manifestPath)
if err != nil {
return nil, err
}

reader, err := manifest.NewReader(manifestPath)
if err != nil {
return nil, fmt.Errorf("manifest reader: %w", err)
}

pkg, err := reader.Read()
if err != nil {
return nil, fmt.Errorf("read manifest %q: %w", manifestPath, err)
}

var stages [][][]string
if config.OutputModule != nil && *config.OutputModule != "" {
outputModule := *config.OutputModule
if outputModule != "" {
outputGraph, err := outputmodules.NewOutputModuleGraph(outputModule, true, pkg.Modules)
if err != nil {
return nil, fmt.Errorf("creating output module graph: %w", err)
Expand All @@ -180,24 +187,10 @@ func Info(manifestPath string, opts ...InfoOption) (*ManifestInfo, error) {
}
}

manifestInfo.Modules = modules
manifestInfo.ProtoFiles = protoFiles
manifestInfo.ExecutionStages = stages

return manifestInfo, nil
}

func InfoJson(manifestPath string, opts ...InfoOption) (string, error) {
info, err := Info(manifestPath, opts...)
if err != nil {
return "", err
}

res, err := json.MarshalIndent(info, "", " ")
if err != nil {
return "", err
}
return string(res), nil
return &ExtendedInfo{
BasicInfo: basicInfo,
ExecutionStages: stages,
}, nil
}

func strPtr(s string) *string {
Expand Down
8 changes: 4 additions & 4 deletions info/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"testing"
)

func TestInfo(t *testing.T) {
info, err := Info("https://github.com/streamingfast/substreams-uniswap-v3/releases/download/v0.2.8/substreams.spkg")
func TestBasicInfo(t *testing.T) {
info, err := Basic("https://github.com/streamingfast/substreams-uniswap-v3/releases/download/v0.2.8/substreams.spkg")
require.NoError(t, err)

r, err := json.MarshalIndent(info, "", " ")
Expand All @@ -17,8 +17,8 @@ func TestInfo(t *testing.T) {
fmt.Println(string(r))
}

func TestInfoWithOutputModule(t *testing.T) {
info, err := Info("https://github.com/streamingfast/substreams-uniswap-v3/releases/download/v0.2.8/substreams.spkg", WithOutputModule("graph_out"))
func TestExtendedInfo(t *testing.T) {
info, err := Extended("https://github.com/streamingfast/substreams-uniswap-v3/releases/download/v0.2.8/substreams.spkg", "graph_out")
require.NoError(t, err)

r, err := json.MarshalIndent(info, "", " ")
Expand Down

0 comments on commit 5266d08

Please sign in to comment.