Skip to content

Commit

Permalink
fix evm-minimal and sol-minimal
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBger committed Aug 8, 2024
1 parent 6e16f95 commit 823aa18
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 61 deletions.
7 changes: 7 additions & 0 deletions ethfull/convo.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ func (c *Convo) validate() error {
}

switch c.outputType {
case outputTypeSubstreams:
if c.state.SqlOutputFlavor != "" {
return fmt.Errorf("cannot have SqlOutputFlavor set on this code generator")
}
if c.state.SubgraphOutputFlavor != "" {
return fmt.Errorf("cannot have SubgraphOutputFlavor set on this code generator")
}
case outputTypeSQL:
if c.state.SubgraphOutputFlavor != "" {
return fmt.Errorf("cannot have SubgraphOutputFlavor set on this code generator")
Expand Down
7 changes: 4 additions & 3 deletions ethfull/helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package ethfull

import (
"github.com/stretchr/testify/require"
"testing"

"github.com/stretchr/testify/require"
)

func TestSanitizeStructABI(t *testing.T) {
Expand All @@ -21,15 +22,15 @@ func TestSanitizeStructABI(t *testing.T) {
},
{
inputStructAbiName: "__foo_bar",
expectedName: "_u_foo_bar",
expectedName: "u_u_foo_bar",
},
{
inputStructAbiName: "foobar__",
expectedName: "foobar_u_",
},
{
inputStructAbiName: "__foobar",
expectedName: "_u_foobar",
expectedName: "u_u_foobar",
},
}

Expand Down
17 changes: 7 additions & 10 deletions evm-minimal/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,13 @@ func (p *Project) Render() (projectFiles map[string][]byte, err error) {
}

templateFiles := map[string]string{
"proto/contract.proto.gotmpl": "proto/contract.proto",
"src/abi/mod.rs.gotmpl": "src/abi/mod.rs",
"src/pb/mod.rs.gotmpl": "src/pb/mod.rs",
"src/lib.rs.gotmpl": "src/lib.rs",
"build.rs.gotmpl": "build.rs",
"Cargo.toml.gotmpl": "Cargo.toml",
"rust-toolchain.toml": "rust-toolchain.toml",
".gitignore": ".gitignore",
"substreams.yaml.gotmpl": "substreams.yaml",
"entities/Makefile.gotmpl": "Makefile",
"proto/mydata.proto.gotmpl": "proto/mydata.proto",
"src/pb/mod.rs.gotmpl": "src/pb/mod.rs",
"src/lib.rs.gotmpl": "src/lib.rs",
"Cargo.toml.gotmpl": "Cargo.toml",
".gitignore": ".gitignore",
"substreams.yaml.gotmpl": "substreams.yaml",
"Makefile.gotmpl": "Makefile",
}

for templateFile, finalFileName := range templateFiles {
Expand Down
29 changes: 29 additions & 0 deletions evm-minimal/templates/Makefile.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
CARGO_VERSION := $(shell cargo version 2>/dev/null)

.PHONY: protogen
protogen:
substreams protogen ./substreams.yaml --exclude-paths="sf/substreams,google"

.PHONY: build
build: protogen
ifdef CARGO_VERSION
cargo build --target wasm32-unknown-unknown --release
else
@echo "Building substreams target using Docker. To speed up this step, install a Rust development environment."
docker run --rm -ti --init -v ${PWD}:/usr/src --workdir /usr/src/ rust:bullseye cargo build --target wasm32-unknown-unknown --release
endif

.PHONY: run
run: build
substreams run substreams.yaml $(if $(MODULE),$(MODULE),map_events) $(if $(START_BLOCK),-s $(START_BLOCK)) $(if $(STOP_BLOCK),-t $(STOP_BLOCK))

.PHONY: gui
gui: build
substreams gui substreams.yaml $(if $(MODULE),$(MODULE),map_events) $(if $(START_BLOCK),-s $(START_BLOCK)) $(if $(STOP_BLOCK),-t $(STOP_BLOCK))

.PHONY: all
all: protogen build package

.PHONY: package
package: build
substreams pack substreams.yaml
10 changes: 6 additions & 4 deletions evm-minimal/templates/src/lib.rs.gotmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod abi;
mod pb;
use hex_literal::hex;
use pb::mydata::v1 as mydata;
Expand All @@ -7,7 +6,7 @@ use pb::mydata::v1 as mydata;
// use substreams::store;

use substreams::Hex;
use substreams_ethereum::pb::eth::v2 as eth;
use substreams_ethereum::pb::eth::v2::Block as Block;
// use substreams_ethereum::Event;


Expand All @@ -18,7 +17,10 @@ use substreams::scalar::BigDecimal;

substreams_ethereum::init!();

fn map_my_data(blk: &eth::Block) -> mydata::MyData {
#[substreams::handlers::map]
fn map_my_data(blk: Block) -> mydata::MyData {
let mut my_data = mydata::MyData::default();
my_data.counter = blk.number;

return my_data
}
{{- end }}
11 changes: 6 additions & 5 deletions evm-minimal/templates/substreams.yaml.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package:
version: v0.1.0

imports:
eth: spkg.io/streamingfast/ethereum-common-latest # CHANGE ME
# eth: spkg.io/streamingfast/ethereum-common-latest # CHANGE ME

protobuf:
files:
Expand All @@ -23,15 +23,16 @@ binaries:
modules:
- name: map_my_data
kind: map
input:
- map: eth:filtered_transactions
TODO: fill in
inputs:
- source: sf.ethereum.type.v2.Block
output :
type: proto:mydata.v1.MyData

# Uncomment to get the raw feed of all events and calls
#
# - name: map_my_data
# kind: map
# input:
# inputs:
# - map: eth:all_events_calls
# TODO: fill in

Expand Down
1 change: 1 addition & 0 deletions registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func ListConversationHandlers() []*ConversationHandler {
sort.Slice(handlers, func(i, j int) bool {
return handlers[i].Weight > handlers[j].Weight // heighest weight first
})

return handlers
}

Expand Down
5 changes: 1 addition & 4 deletions sol-minimal/convo.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Convo struct {

func init() {
codegen.RegisterConversation(
"evm-minimal",
"sol-minimal",
"Simplest Substreams to get you started on solana",
`This will .`,
codegen.ConversationFactory(New),
Expand Down Expand Up @@ -67,9 +67,6 @@ func (p *Project) NextStep() (out loop.Cmd) {
if p.Name == "" {
return cmd(codegen.AskProjectName{})
}
if p.ChainName == "" {
return cmd(codegen.AskChainName{})
}

if !p.generatedCodeCompleted {
return cmd(codegen.RunGenerate{})
Expand Down
17 changes: 7 additions & 10 deletions sol-minimal/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,13 @@ func (p *Project) Render() (projectFiles map[string][]byte, err error) {
}

templateFiles := map[string]string{
"proto/contract.proto.gotmpl": "proto/contract.proto",
"src/abi/mod.rs.gotmpl": "src/abi/mod.rs",
"src/pb/mod.rs.gotmpl": "src/pb/mod.rs",
"src/lib.rs.gotmpl": "src/lib.rs",
"build.rs.gotmpl": "build.rs",
"Cargo.toml.gotmpl": "Cargo.toml",
"rust-toolchain.toml": "rust-toolchain.toml",
".gitignore": ".gitignore",
"substreams.yaml.gotmpl": "substreams.yaml",
"entities/Makefile.gotmpl": "Makefile",
"proto/mydata.proto.gotmpl": "proto/mydata.proto",
"src/pb/mod.rs.gotmpl": "src/pb/mod.rs",
"src/lib.rs.gotmpl": "src/lib.rs",
"Cargo.toml.gotmpl": "Cargo.toml",
".gitignore": ".gitignore",
"substreams.yaml.gotmpl": "substreams.yaml",
"Makefile.gotmpl": "Makefile",
}

for templateFile, finalFileName := range templateFiles {
Expand Down
5 changes: 2 additions & 3 deletions sol-minimal/templates/Cargo.toml.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ name = "substreams"
crate-type = ["cdylib"]

[dependencies]
ethabi = "17"
hex-literal = "0.3.4"
num-bigint = "0.4"
num-traits = "0.2.15"
prost = "0.11"
prost-types = "0.11"
substreams = "0.5.21"
substreams-ethereum = "0.9"
substreams-solana = "0.11.1"
substreams-solana-program-instructions = "0.1"
substreams-database-change = "1"
substreams-entity-change = "1"

Expand All @@ -25,7 +25,6 @@ getrandom = { version = "0.2", features = ["custom"] }

[build-dependencies]
anyhow = "1"
substreams-ethereum = "0.9"
regex = "1.8"

[profile.release]
Expand Down
29 changes: 29 additions & 0 deletions sol-minimal/templates/Makefile.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
CARGO_VERSION := $(shell cargo version 2>/dev/null)

.PHONY: protogen
protogen:
substreams protogen ./substreams.yaml --exclude-paths="sf/substreams,google"

.PHONY: build
build: protogen
ifdef CARGO_VERSION
cargo build --target wasm32-unknown-unknown --release
else
@echo "Building substreams target using Docker. To speed up this step, install a Rust development environment."
docker run --rm -ti --init -v ${PWD}:/usr/src --workdir /usr/src/ rust:bullseye cargo build --target wasm32-unknown-unknown --release
endif

.PHONY: run
run: build
substreams run substreams.yaml $(if $(MODULE),$(MODULE),map_events) $(if $(START_BLOCK),-s $(START_BLOCK)) $(if $(STOP_BLOCK),-t $(STOP_BLOCK))

.PHONY: gui
gui: build
substreams gui substreams.yaml $(if $(MODULE),$(MODULE),map_events) $(if $(START_BLOCK),-s $(START_BLOCK)) $(if $(STOP_BLOCK),-t $(STOP_BLOCK))

.PHONY: all
all: protogen build package

.PHONY: package
package: build
substreams pack substreams.yaml
17 changes: 8 additions & 9 deletions sol-minimal/templates/src/lib.rs.gotmpl
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
mod abi;
mod pb;
use hex_literal::hex;
use pb::mydata::v1 as mydata;

// use substreams::prelude::*;
// use substreams::store;

use substreams::Hex;
use substreams_ethereum::pb::eth::v2 as eth;
// use substreams_ethereum::Event;
use substreams_solana::pb::sf::solana::r#type::v1::Block;


#[allow(unused_imports)]
use num_traits::cast::ToPrimitive;
use std::str::FromStr;
use substreams::scalar::BigDecimal;

substreams_ethereum::init!();

fn map_my_data(blk: &eth::Block) -> mydata::MyData {
#[substreams::handlers::map]
fn map_my_data(blk: Block) -> mydata::MyData {
let mut my_data = mydata::MyData::default();
if let Some(block_height) = blk.block_height {
my_data.counter = block_height.block_height;
}

return my_data
}
{{- end }}

15 changes: 2 additions & 13 deletions sol-minimal/templates/substreams.yaml.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package:
name: {{ .ModuleName }}
version: v0.1.0

imports:
eth: spkg.io/streamingfast/ethereum-common-latest # CHANGE ME

protobuf:
files:
- mydata.proto
Expand All @@ -23,17 +20,9 @@ binaries:
modules:
- name: map_my_data
kind: map
input:
inputs:
- source: sf.solana.type.v1.Block
output:
type:

# Uncomment to get the raw feed of all events and calls
#
# - name: map_my_data
# kind: map
# input:
# - map: eth:all_events_calls
# TODO: fill in
type: proto:mydata.v1.MyData

network: solana

0 comments on commit 823aa18

Please sign in to comment.