-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/multiple-contracts-code-gen' into develop
- Loading branch information
Showing
33 changed files
with
1,657 additions
and
158 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package codegen | ||
|
||
//go:generate go-enum -f=$GOFILE --marshal --names --nocase | ||
|
||
// ENUM( | ||
// | ||
// No | ||
// Db | ||
// Graph | ||
// | ||
// ) | ||
type SinkChoice int |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use anyhow::{Ok, Result}; | ||
use regex::Regex; | ||
use substreams_ethereum::Abigen; | ||
use std::fs; | ||
use std::fs::File; | ||
use std::io::Write; | ||
|
||
fn main() -> Result<(), anyhow::Error> { | ||
{{- $numberOfContracts := len .ethereumContracts }} | ||
let file_names = [ | ||
{{- range $i, $contract := .ethereumContracts }} | ||
"abi/{{ $contract.GetName }}{{ if eq $numberOfContracts 1 }}{{ else }}_{{ end }}contract.abi.json", | ||
{{- end }} | ||
]; | ||
let file_output_names = [ | ||
{{- range $i, $contract := .ethereumContracts }} | ||
"src/abi/{{ $contract.GetName }}{{ if eq $numberOfContracts 1 }}{{ else }}_{{ end }}contract.rs", | ||
{{- end }} | ||
]; | ||
|
||
let mut i = 0; | ||
for f in file_names { | ||
let contents = fs::read_to_string(f) | ||
.expect("Should have been able to read the file"); | ||
|
||
// sanitize fields and attributes starting with an underscore | ||
let regex = Regex::new(r#"("\w+"\s?:\s?")_(\w+")"#).unwrap(); | ||
let sanitized_abi_file = regex.replace_all(contents.as_str(), "${1}u_${2}"); | ||
|
||
// do not modify the original abi | ||
let mut file = File::create("/tmp/contract.abi.json")?; | ||
file.write_all(sanitized_abi_file.as_bytes())?; | ||
|
||
Abigen::new("Contract", "/tmp/contract.abi.json")? | ||
.generate()? | ||
.write_to_file(file_output_names[i])?; | ||
|
||
i = i+1; | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[package] | ||
name = "substreams-init-test" | ||
version = "0.0.1" | ||
edition = "2021" | ||
|
||
[lib] | ||
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" | ||
substreams-ethereum = "0.9" | ||
substreams-database-change = "1" | ||
|
||
# Required so that ethabi > ethereum-types build correctly under wasm32-unknown-unknown | ||
[target.wasm32-unknown-unknown.dependencies] | ||
getrandom = { version = "0.2", features = ["custom"] } | ||
|
||
[build-dependencies] | ||
anyhow = "1" | ||
substreams-ethereum = "0.9" | ||
regex = "1.8" | ||
|
||
[profile.release] | ||
lto = true | ||
opt-level = 's' | ||
strip = "debuginfo" |
Oops, something went wrong.