Skip to content

Commit

Permalink
Merge pull request #352 from YaroShkvorets/fix/numbers_in_abi
Browse files Browse the repository at this point in the history
Fix numbers in ABI types
  • Loading branch information
maoueh authored Dec 5, 2023
2 parents 33b7039 + e99ab72 commit 6f9b0cd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
14 changes: 7 additions & 7 deletions codegen/templates/ethereum_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"text/template"

"github.com/gertd/go-pluralize"
"github.com/iancoleman/strcase"
"github.com/huandu/xstrings"
"github.com/streamingfast/eth-go"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -154,7 +154,7 @@ func (p *EthereumProject) Render() (map[string][]byte, error) {

name := p.name
if finalFileName == "subgraph.yaml.gotmpl" {
name = strcase.ToKebab(p.name)
name = xstrings.ToKebabCase(p.name)
}

model := map[string]any{
Expand Down Expand Up @@ -218,16 +218,16 @@ func BuildEventModels(contract *EthereumContract, multipleContracts bool) (out [
rustABIStructName = name + strconv.FormatUint(uint64(i+1), 10)
}

protoFieldName := strcase.ToSnake(pluralizer.Plural(rustABIStructName))
protoFieldName := xstrings.ToSnakeCase(pluralizer.Plural(rustABIStructName))
// prost will do a to_lower_camel_case() on any struct name
rustGeneratedStructName := strcase.ToCamel(strcase.ToSnake(rustABIStructName))
rustGeneratedStructName := xstrings.ToCamelCase(xstrings.ToSnakeCase(rustABIStructName))

codegenEvent := codegenEvent{
Rust: &rustEventModel{
ABIStructName: rustGeneratedStructName,
ProtoMessageName: rustGeneratedStructName,
ProtoOutputModuleFieldName: protoFieldName,
TableChangeEntityName: strcase.ToSnake(rustABIStructName),
TableChangeEntityName: xstrings.ToSnakeCase(rustABIStructName),
},

Proto: &protoEventModel{
Expand Down Expand Up @@ -285,7 +285,7 @@ func (e *rustEventModel) populateFields(log *eth.LogEventDef, multipleContracts
fmt.Printf(" Generating ABI Events for %s (%s)\n", log.Name, strings.Join(paramNames, ","))

for _, parameter := range log.Parameters {
name := strcase.ToSnake(parameter.Name)
name := xstrings.ToSnakeCase(parameter.Name)
name = sanitizeProtoFieldName(name)

toProtoCode := generateFieldTransformCode(parameter.Type, "event."+name)
Expand Down Expand Up @@ -613,7 +613,7 @@ func (e *protoEventModel) populateFields(log *eth.LogEventDef) error {

e.Fields = make([]protoField, 0, len(log.Parameters))
for _, parameter := range log.Parameters {
fieldName := strcase.ToSnake(parameter.Name)
fieldName := xstrings.ToSnakeCase(parameter.Name)
fieldName = sanitizeProtoFieldName(fieldName)
fieldType := getProtoFieldType(parameter.Type)
if fieldType == SKIP_FIELD {
Expand Down
6 changes: 6 additions & 0 deletions docs/release-notes/change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Fixed

* Bug in `substreams init` with numbers in ABI types

## v1.1.22

### alpha service deployments
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ require (
github.com/dustin/go-humanize v1.0.1
github.com/gertd/go-pluralize v0.2.1
github.com/google/uuid v1.3.0
github.com/iancoleman/strcase v0.2.0
github.com/huandu/xstrings v1.4.0
github.com/ipfs/go-ipfs-api v0.6.0
github.com/itchyny/gojq v0.12.12
github.com/lithammer/dedent v1.1.0
Expand Down Expand Up @@ -79,6 +79,7 @@ require (
github.com/bufbuild/connect-grpchealth-go v1.1.1 // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/iancoleman/strcase v0.2.0 // indirect
github.com/mattn/go-sqlite3 v1.14.16 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T
github.com/holiman/uint256 v1.2.0 h1:gpSYcPLWGv4sG43I2mVLiDZCNDh/EpGjSk8tmtxitHM=
github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU=
github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0=
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down

0 comments on commit 6f9b0cd

Please sign in to comment.