From 823aa1829c68fcd23f1a9ca232c1a79486ffea6f Mon Sep 17 00:00:00 2001 From: arnaudberger Date: Thu, 8 Aug 2024 00:21:09 -0400 Subject: [PATCH] fix evm-minimal and sol-minimal --- ethfull/convo.go | 7 +++++ ethfull/helpers_test.go | 7 +++-- evm-minimal/generate.go | 17 +++++------- evm-minimal/templates/Makefile.gotmpl | 29 ++++++++++++++++++++ evm-minimal/templates/src/lib.rs.gotmpl | 10 ++++--- evm-minimal/templates/substreams.yaml.gotmpl | 11 ++++---- registry.go | 1 + sol-minimal/convo.go | 5 +--- sol-minimal/generate.go | 17 +++++------- sol-minimal/templates/Cargo.toml.gotmpl | 5 ++-- sol-minimal/templates/Makefile.gotmpl | 29 ++++++++++++++++++++ sol-minimal/templates/src/lib.rs.gotmpl | 17 ++++++------ sol-minimal/templates/substreams.yaml.gotmpl | 15 ++-------- 13 files changed, 109 insertions(+), 61 deletions(-) create mode 100644 evm-minimal/templates/Makefile.gotmpl create mode 100644 sol-minimal/templates/Makefile.gotmpl diff --git a/ethfull/convo.go b/ethfull/convo.go index 472495c..7feee91 100644 --- a/ethfull/convo.go +++ b/ethfull/convo.go @@ -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") diff --git a/ethfull/helpers_test.go b/ethfull/helpers_test.go index f5f20c8..448d308 100644 --- a/ethfull/helpers_test.go +++ b/ethfull/helpers_test.go @@ -1,8 +1,9 @@ package ethfull import ( - "github.com/stretchr/testify/require" "testing" + + "github.com/stretchr/testify/require" ) func TestSanitizeStructABI(t *testing.T) { @@ -21,7 +22,7 @@ func TestSanitizeStructABI(t *testing.T) { }, { inputStructAbiName: "__foo_bar", - expectedName: "_u_foo_bar", + expectedName: "u_u_foo_bar", }, { inputStructAbiName: "foobar__", @@ -29,7 +30,7 @@ func TestSanitizeStructABI(t *testing.T) { }, { inputStructAbiName: "__foobar", - expectedName: "_u_foobar", + expectedName: "u_u_foobar", }, } diff --git a/evm-minimal/generate.go b/evm-minimal/generate.go index 751f85a..950e2e0 100644 --- a/evm-minimal/generate.go +++ b/evm-minimal/generate.go @@ -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 { diff --git a/evm-minimal/templates/Makefile.gotmpl b/evm-minimal/templates/Makefile.gotmpl new file mode 100644 index 0000000..9c748c9 --- /dev/null +++ b/evm-minimal/templates/Makefile.gotmpl @@ -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 diff --git a/evm-minimal/templates/src/lib.rs.gotmpl b/evm-minimal/templates/src/lib.rs.gotmpl index db6f532..e65ad22 100644 --- a/evm-minimal/templates/src/lib.rs.gotmpl +++ b/evm-minimal/templates/src/lib.rs.gotmpl @@ -1,4 +1,3 @@ -mod abi; mod pb; use hex_literal::hex; use pb::mydata::v1 as mydata; @@ -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; @@ -18,7 +17,10 @@ use substreams::scalar::BigDecimal; substreams_ethereum::init!(); -fn map_my_data(blk: ð::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 }} diff --git a/evm-minimal/templates/substreams.yaml.gotmpl b/evm-minimal/templates/substreams.yaml.gotmpl index 566a4a8..3ed7cdc 100644 --- a/evm-minimal/templates/substreams.yaml.gotmpl +++ b/evm-minimal/templates/substreams.yaml.gotmpl @@ -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: @@ -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 diff --git a/registry.go b/registry.go index 567273f..d12c69a 100644 --- a/registry.go +++ b/registry.go @@ -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 } diff --git a/sol-minimal/convo.go b/sol-minimal/convo.go index 0d681eb..35d3889 100644 --- a/sol-minimal/convo.go +++ b/sol-minimal/convo.go @@ -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), @@ -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{}) diff --git a/sol-minimal/generate.go b/sol-minimal/generate.go index d5ac366..6864ef9 100644 --- a/sol-minimal/generate.go +++ b/sol-minimal/generate.go @@ -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 { diff --git a/sol-minimal/templates/Cargo.toml.gotmpl b/sol-minimal/templates/Cargo.toml.gotmpl index 02931ed..bee04ef 100644 --- a/sol-minimal/templates/Cargo.toml.gotmpl +++ b/sol-minimal/templates/Cargo.toml.gotmpl @@ -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" @@ -25,7 +25,6 @@ getrandom = { version = "0.2", features = ["custom"] } [build-dependencies] anyhow = "1" -substreams-ethereum = "0.9" regex = "1.8" [profile.release] diff --git a/sol-minimal/templates/Makefile.gotmpl b/sol-minimal/templates/Makefile.gotmpl new file mode 100644 index 0000000..9c748c9 --- /dev/null +++ b/sol-minimal/templates/Makefile.gotmpl @@ -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 diff --git a/sol-minimal/templates/src/lib.rs.gotmpl b/sol-minimal/templates/src/lib.rs.gotmpl index 0f27057..18d9af0 100644 --- a/sol-minimal/templates/src/lib.rs.gotmpl +++ b/sol-minimal/templates/src/lib.rs.gotmpl @@ -1,14 +1,10 @@ -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)] @@ -16,10 +12,13 @@ use num_traits::cast::ToPrimitive; use std::str::FromStr; use substreams::scalar::BigDecimal; -substreams_ethereum::init!(); - -fn map_my_data(blk: ð::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 }} + diff --git a/sol-minimal/templates/substreams.yaml.gotmpl b/sol-minimal/templates/substreams.yaml.gotmpl index 6766365..1a4b0fd 100644 --- a/sol-minimal/templates/substreams.yaml.gotmpl +++ b/sol-minimal/templates/substreams.yaml.gotmpl @@ -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 @@ -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