Skip to content

Commit

Permalink
remove zip files
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBger committed Jul 29, 2024
1 parent 72efb19 commit b9b006f
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 100 deletions.
39 changes: 23 additions & 16 deletions ethfull/convo.go
Original file line number Diff line number Diff line change
Expand Up @@ -978,24 +978,31 @@ message {{.Proto.MessageName}} {{.Proto.OutputModuleFieldName}} {
)
}

c.state.sourceZip = msg.SubstreamsSourceZip
c.state.projectZip = msg.ProjectZip
c.state.sourceFiles = msg.SourceFiles
c.state.projectFiles = msg.ProjectFiles
c.state.generatedCodeCompleted = true

return loop.Seq(c.msg().Messagef("Code generation complete!").Cmd(),
c.action(codegen.InputSourceDownloaded{}).
DownloadFiles().
AddFile(
"project.zip",
msg.ProjectZip,
"application/x-zip+extract",
"\nProject files, schemas, dev environment....\n",
).AddFile(
"substreams_src.zip",
msg.SubstreamsSourceZip,
"application/x-zip+extract",
"\nGenerated source code ready to compile.\nThis module is a Rust-based module, and you can compile it with \"make all\" in the root directory.\n",
).Cmd())
downloadCmd := c.action(codegen.InputSourceDownloaded{}).DownloadFiles()

for fileName, fileContent := range msg.SourceFiles {
fileDescription := ""
if _, ok := codegen.FileDescriptions[fileName]; ok {
fileDescription = codegen.FileDescriptions[fileName]
}

downloadCmd.AddFile(fileName, fileContent, "text/plain", fileDescription)
}

for fileName, fileContent := range msg.ProjectFiles {
fileDescription := ""
if _, ok := codegen.FileDescriptions[fileName]; ok {
fileDescription = codegen.FileDescriptions[fileName]
}

downloadCmd.AddFile(fileName, fileContent, "text/plain", fileDescription)
}

return loop.Seq(c.msg().Messagef("Code generation complete!").Cmd(), downloadCmd.Cmd())

case codegen.InputSourceDownloaded:
return c.NextStep()
Expand Down
33 changes: 13 additions & 20 deletions ethfull/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ var templatesFS embed.FS

func cmdGenerate(p *Project, outType outputType) loop.Cmd {
return func() loop.Msg {
substreamsZip, projectZip, err := p.generate(outType)
srcFiles, projFiles, err := p.generate(outType)
if err != nil {
return codegen.ReturnGenerate{Err: err}
}
return codegen.ReturnGenerate{
SubstreamsSourceZip: substreamsZip,
ProjectZip: projectZip,
SourceFiles: srcFiles,
ProjectFiles: projFiles,
}
}
}
Expand Down Expand Up @@ -69,7 +69,7 @@ func cmdBuildCompleted(content *codegen.RemoteBuildState) loop.Cmd {
}
}

func (p *Project) generate(outType outputType) (substreamsZip, projectZip []byte, err error) {
func (p *Project) generate(outType outputType) (srcFiles, projFiles map[string][]byte, err error) {
// TODO: before doing any generation, we'll want to validate
// all data points that are going into source code.
// We don't want some weird things getting into `build.rs`
Expand All @@ -78,25 +78,11 @@ func (p *Project) generate(outType outputType) (substreamsZip, projectZip []byte
// TODO: add some checking to make sure `ParentContractName` of DynamicContract
// do match a Contract that exists here.

srcFiles, projFiles, err := p.Render(outType)
srcFiles, projFiles, err = p.Render(outType)
if err != nil {
return nil, nil, fmt.Errorf("rendering template: %w", err)
}

if len(srcFiles) != 0 {
substreamsZip, err = codegen.ZipFiles(srcFiles)
if err != nil {
return nil, nil, fmt.Errorf("zipping: %w", err)
}
}

if len(projFiles) != 0 {
projectZip, err = codegen.ZipFiles(projFiles)
if err != nil {
return nil, nil, fmt.Errorf("zipping: %w", err)
}
}

return
}

Expand Down Expand Up @@ -135,10 +121,17 @@ func (p *Project) build(remoteBuildContentChan chan<- *codegen.RemoteBuildState)
}
}()

projectZip, err := codegen.ZipFiles(p.projectFiles)
if err != nil {
remoteBuildContentChan <- &codegen.RemoteBuildState{
Error: err.Error(),
}
}

client := pbbuild.NewBuildServiceClient(conn)
res, err := client.Build(context.Background(),
&pbbuild.BuildRequest{
SourceCode: p.sourceZip,
SourceCode: projectZip,
CollectPattern: "*.spkg",
Subfolder: "substreams",
},
Expand Down
11 changes: 6 additions & 5 deletions ethfull/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/codemodus/kace"
"github.com/golang-cz/textcase"
"github.com/huandu/xstrings"
"math"
"regexp"
"strings"
"time"

"github.com/codemodus/kace"
"github.com/golang-cz/textcase"
"github.com/huandu/xstrings"

"github.com/streamingfast/eth-go"
)

Expand All @@ -30,8 +31,8 @@ type Project struct {
confirmDownloadOnly bool
generatedCodeCompleted bool
compilingBuild bool
sourceZip []byte
projectZip []byte
sourceFiles map[string][]byte
projectFiles map[string][]byte

buildStarted time.Time

Expand Down
33 changes: 23 additions & 10 deletions injective-events/convo.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,18 +404,31 @@ func (c *InjectiveConvo) Update(msg loop.Msg) loop.Cmd {
)
}

c.state.projectZip = msg.ProjectZip
c.state.sourceZip = msg.SubstreamsSourceZip
c.state.projectFiles = msg.ProjectFiles
c.state.sourceFiles = msg.SourceFiles
c.state.generatedCodeCompleted = true

var cmds []loop.Cmd
cmds = append(cmds, c.msg().Message("Code generation complete!").Cmd())
cmds = append(cmds, c.action(codegen.RunBuild{}).DownloadFiles().
AddFile("project.zip", msg.ProjectZip, "application/x-zip+extract", "\nProject files, schemas, dev environment...").
AddFile("substreams_src.zip", msg.SubstreamsSourceZip, "application/x-zip+extract", "").
Cmd())
downloadCmd := c.action(codegen.InputSourceDownloaded{}).DownloadFiles()

c.state.generatedCodeCompleted = true
return loop.Seq(cmds...)
for fileName, fileContent := range msg.SourceFiles {
fileDescription := ""
if _, ok := codegen.FileDescriptions[fileName]; ok {
fileDescription = codegen.FileDescriptions[fileName]
}

downloadCmd.AddFile(fileName, fileContent, "text/plain", fileDescription)
}

for fileName, fileContent := range msg.ProjectFiles {
fileDescription := ""
if _, ok := codegen.FileDescriptions[fileName]; ok {
fileDescription = codegen.FileDescriptions[fileName]
}

downloadCmd.AddFile(fileName, fileContent, "text/plain", fileDescription)
}

return loop.Seq(c.msg().Messagef("Code generation complete!").Cmd(), downloadCmd.Cmd())

case codegen.RunBuild:
return cmdBuild(c.state)
Expand Down
29 changes: 13 additions & 16 deletions injective-events/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,13 @@ func (p *Project) Render(outType outputType) (substreamsFiles map[string][]byte,
return
}

func (p *Project) generate(outType outputType) ([]byte, []byte, error) {
func (p *Project) generate(outType outputType) (map[string][]byte, map[string][]byte, error) {
srcFiles, projectFiles, err := p.Render(outType)
if err != nil {
return nil, nil, fmt.Errorf("rendering template: %w", err)
}

substreamsZip, err := codegen.ZipFiles(srcFiles)
if err != nil {
return nil, nil, fmt.Errorf("zipping: %w", err)
}

projectZip, err := codegen.ZipFiles(projectFiles)
if err != nil {
return nil, nil, fmt.Errorf("zipping: %w", err)
}

return projectZip, substreamsZip, nil
return projectFiles, srcFiles, nil
}

func (p *Project) build(remoteBuildContentChan chan<- *codegen.RemoteBuildState) {
Expand Down Expand Up @@ -173,10 +163,17 @@ func (p *Project) build(remoteBuildContentChan chan<- *codegen.RemoteBuildState)
}
}()

projectZip, err := codegen.ZipFiles(p.projectFiles)
if err != nil {
remoteBuildContentChan <- &codegen.RemoteBuildState{
Error: err.Error(),
}
}

client := pbbuild.NewBuildServiceClient(conn)
res, err := client.Build(context.Background(),
&pbbuild.BuildRequest{
SourceCode: p.sourceZip,
SourceCode: projectZip,
CollectPattern: "*.spkg",
Subfolder: "substreams",
},
Expand Down Expand Up @@ -229,13 +226,13 @@ func cmdGenerate(p *Project, outType outputType) loop.Cmd {
p.buildStarted = time.Now()

return func() loop.Msg {
projectZip, substreamsZip, err := p.generate(outType)
projectFiles, sourceFiles, err := p.generate(outType)
if err != nil {
return codegen.ReturnGenerate{Err: err}
}
return codegen.ReturnGenerate{
ProjectZip: projectZip,
SubstreamsSourceZip: substreamsZip,
ProjectFiles: projectFiles,
SourceFiles: sourceFiles,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions injective-events/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ type Project struct {

generatedCodeCompleted bool
compilingBuild bool
projectZip []byte
sourceZip []byte
projectFiles map[string][]byte
sourceFiles map[string][]byte

buildStarted time.Time

Expand Down
12 changes: 12 additions & 0 deletions registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,15 @@ func ListConversationHandlers() []*ConversationHandler {
})
return handlers
}

var FileDescriptions = map[string]string{
"contract.proto": "File containing the contract proto definition",
"build.rs": "File containing the build script for the project",
"Cargo.toml": "Cargo manifest file, a configuration file which defines the project",
"substreams.yaml": "Substreams manifest, a configuration file which defines the different modules",
"rust-toolchain.toml": "File containing the rust toolchain version",
"lib.rs": "Substreams modules definition code in Rust",
".gitignore": "File containing the gitignore rules",
"mod.rs": "Rust module definitions file",
"contract.abi.json": "File containing the contract ABI definition",
}
33 changes: 23 additions & 10 deletions starknet/convo.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,31 @@ func (c *Convo) Update(msg loop.Msg) loop.Cmd {
)
}

c.state.projectZip = msg.ProjectZip
c.state.sourceZip = msg.SubstreamsSourceZip
c.state.projectFiles = msg.ProjectFiles
c.state.sourceFiles = msg.SourceFiles
c.state.generatedCodeCompleted = true

var cmds []loop.Cmd
cmds = append(cmds, c.msg().Message("Code generation complete!").Cmd())
cmds = append(cmds, c.action(codegen.RunBuild{}).DownloadFiles().
AddFile("project.zip", msg.ProjectZip, "application/x-zip+extract", "\nProject files, schemas, dev environment...").
AddFile("substreams_src.zip", msg.SubstreamsSourceZip, "application/zip", "").
Cmd())
downloadCmd := c.action(codegen.InputSourceDownloaded{}).DownloadFiles()

c.state.generatedCodeCompleted = true
return loop.Seq(cmds...)
for fileName, fileContent := range msg.SourceFiles {
fileDescription := ""
if _, ok := codegen.FileDescriptions[fileName]; ok {
fileDescription = codegen.FileDescriptions[fileName]
}

downloadCmd.AddFile(fileName, fileContent, "text/plain", fileDescription)
}

for fileName, fileContent := range msg.ProjectFiles {
fileDescription := ""
if _, ok := codegen.FileDescriptions[fileName]; ok {
fileDescription = codegen.FileDescriptions[fileName]
}

downloadCmd.AddFile(fileName, fileContent, "text/plain", fileDescription)
}

return loop.Seq(c.msg().Messagef("Code generation complete!").Cmd(), downloadCmd.Cmd())

case codegen.RunBuild:
return cmdBuild(c.state)
Expand Down
29 changes: 13 additions & 16 deletions starknet/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,13 @@ func (p *Project) Render(outType outputType) (substreamsFiles map[string][]byte,
return
}

func (p *Project) generate(outType outputType) ([]byte, []byte, error) {
func (p *Project) generate(outType outputType) (map[string][]byte, map[string][]byte, error) {
srcFiles, projectFiles, err := p.Render(outType)
if err != nil {
return nil, nil, fmt.Errorf("rendering template: %w", err)
}

substreamsZip, err := codegen.ZipFiles(srcFiles)
if err != nil {
return nil, nil, fmt.Errorf("zipping: %w", err)
}

projectZip, err := codegen.ZipFiles(projectFiles)
if err != nil {
return nil, nil, fmt.Errorf("zipping: %w", err)
}

return projectZip, substreamsZip, nil
return projectFiles, srcFiles, nil
}

func (p *Project) build(remoteBuildContentChan chan<- *codegen.RemoteBuildState) {
Expand Down Expand Up @@ -133,10 +123,17 @@ func (p *Project) build(remoteBuildContentChan chan<- *codegen.RemoteBuildState)
}
}()

projectZip, err := codegen.ZipFiles(p.projectFiles)
if err != nil {
remoteBuildContentChan <- &codegen.RemoteBuildState{
Error: err.Error(),
}
}

client := pbbuild.NewBuildServiceClient(conn)
res, err := client.Build(context.Background(),
&pbbuild.BuildRequest{
SourceCode: p.sourceZip,
SourceCode: projectZip,
CollectPattern: "*.spkg",
Subfolder: "substreams",
},
Expand Down Expand Up @@ -189,13 +186,13 @@ func cmdGenerate(p *Project, outType outputType) loop.Cmd {
p.buildStarted = time.Now()

return func() loop.Msg {
projectZip, substreamsZip, err := p.generate(outType)
projectFiles, sourceFiles, err := p.generate(outType)
if err != nil {
return codegen.ReturnGenerate{Err: err}
}
return codegen.ReturnGenerate{
ProjectZip: projectZip,
SubstreamsSourceZip: substreamsZip,
ProjectFiles: projectFiles,
SourceFiles: sourceFiles,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions starknet/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ type Project struct {
generatedCodeCompleted bool

compilingBuild bool
projectZip []byte
sourceZip []byte
projectFiles map[string][]byte
sourceFiles map[string][]byte

buildStarted time.Time

Expand Down
Loading

0 comments on commit b9b006f

Please sign in to comment.