From da7f4e884189cba053eef3474802c7cd821dd57f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Duchesneau?= Date: Wed, 13 Dec 2023 13:24:06 -0500 Subject: [PATCH] adjust info printing and separate loadManifest from validateManifest --- cmd/substreams/info.go | 25 +++++++++++++++++++++++++ manifest/package.go | 37 ++++++++++++++++++++++--------------- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/cmd/substreams/info.go b/cmd/substreams/info.go index f000e3de6..ae4600150 100644 --- a/cmd/substreams/info.go +++ b/cmd/substreams/info.go @@ -97,6 +97,31 @@ func runInfo(cmd *cobra.Command, args []string) error { fmt.Println("") } + if info.Network != "" { + fmt.Printf("Network: %s\n", info.Network) + fmt.Println("") + } + + if info.Networks != nil { + fmt.Println("Networks:") + for network, params := range info.Networks { + fmt.Printf(" %s:\n", network) + if params.InitialBlocks != nil { + fmt.Println(" Initial Blocks:") + } + for mod, start := range params.InitialBlocks { + fmt.Printf(" - %s: %d\n", mod, start) + } + if params.Params != nil { + fmt.Println(" Params:") + } + for mod, p := range params.Params { + fmt.Printf(" - %s: %q\n", mod, p) + } + fmt.Println("") + } + } + if outputModule != "" { stages := info.ExecutionStages for i, layers := range stages { diff --git a/manifest/package.go b/manifest/package.go index bf6627d10..3aa7cf513 100644 --- a/manifest/package.go +++ b/manifest/package.go @@ -26,25 +26,24 @@ func newManifestConverter(inputPath string, skipSourceCodeImportValidation bool) } func (r *manifestConverter) Convert(manif *Manifest) (*pbsubstreams.Package, []*desc.FileDescriptor, *dynamic.Message, error) { - loadedManifest, err := r.loadManifest(manif, r.inputPath) - if err != nil { + + if err := r.expandManifestVariables(manif); err != nil { + return nil, nil, nil, err + } + + if err := r.validateManifest(manif); err != nil { return nil, nil, nil, fmt.Errorf("unable to load manifest: %w", err) } - return r.manifestToPkg(loadedManifest) + return r.manifestToPkg(manif) } -func (r *manifestConverter) loadManifest(manif *Manifest, inputPath string) (*Manifest, error) { +func (r *manifestConverter) expandManifestVariables(manif *Manifest) error { abs, err := filepath.Abs(r.inputPath) if err != nil { - return nil, fmt.Errorf("unable to get working dir: %w", err) + return fmt.Errorf("unable to get working dir: %w", err) } manif.Workdir = path.Dir(abs) - - if manif.SpecVersion != "v0.1.0" { - return nil, fmt.Errorf("invalid 'specVersion', must be v0.1.0") - } - // Allow environment variables in `imports` element for i, moduleImport := range manif.Imports { manif.Imports[i][1] = os.ExpandEnv(moduleImport[1]) @@ -54,6 +53,14 @@ func (r *manifestConverter) loadManifest(manif *Manifest, inputPath string) (*Ma for i := range manif.Protobuf.ImportPaths { manif.Protobuf.ImportPaths[i] = os.ExpandEnv(manif.Protobuf.ImportPaths[i]) } + return nil +} + +func (r *manifestConverter) validateManifest(manif *Manifest) error { + + if manif.SpecVersion != "v0.1.0" { + return fmt.Errorf("invalid 'specVersion', must be v0.1.0") + } // TODO: put some limits on the NUMBER of modules (max 50 ?) // TODO: put a limit on the SIZE of the WASM payload (max 10MB per binary?) @@ -64,24 +71,24 @@ func (r *manifestConverter) loadManifest(manif *Manifest, inputPath string) (*Ma switch s.Kind { case ModuleKindMap: if s.Output.Type == "" { - return nil, fmt.Errorf("stream %q: missing 'output.type' for kind 'map'", s.Name) + return fmt.Errorf("stream %q: missing 'output.type' for kind 'map'", s.Name) } case ModuleKindStore: if err := validateStoreBuilder(s); err != nil { - return nil, fmt.Errorf("stream %q: %w", s.Name, err) + return fmt.Errorf("stream %q: %w", s.Name, err) } default: - return nil, fmt.Errorf("stream %q: invalid kind %q", s.Name, s.Kind) + return fmt.Errorf("stream %q: invalid kind %q", s.Name, s.Kind) } for idx, input := range s.Inputs { if err := input.parse(); err != nil { - return nil, fmt.Errorf("module %q: invalid input [%d]: %w", s.Name, idx, err) + return fmt.Errorf("module %q: invalid input [%d]: %w", s.Name, idx, err) } } } - return manif, nil + return nil } func (r *manifestConverter) manifestToPkg(manif *Manifest) (*pbsubstreams.Package, []*desc.FileDescriptor, *dynamic.Message, error) {