Skip to content

Commit

Permalink
adjust info printing and separate loadManifest from validateManifest
Browse files Browse the repository at this point in the history
  • Loading branch information
sduchesneau committed Dec 13, 2023
1 parent af53ace commit da7f4e8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
25 changes: 25 additions & 0 deletions cmd/substreams/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
37 changes: 22 additions & 15 deletions manifest/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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?)
Expand All @@ -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) {
Expand Down

0 comments on commit da7f4e8

Please sign in to comment.