From c934a828ac42d5d3050fa7da38a943ec67ff663e Mon Sep 17 00:00:00 2001 From: Denis Carriere Date: Sun, 22 Sep 2024 22:24:35 -0400 Subject: [PATCH] init cosmos block --- .github/workflows/push.yml | 36 ++ .gitignore | 810 ++++++++++++++++++++++++++++++- .rustfmt.toml | 1 + Cargo.toml | 25 + README.md | 99 +++- core/Cargo.toml | 27 ++ core/Makefile | 7 + core/buf.gen.yaml | 15 + core/src/lib.rs | 5 + core/src/pb/mod.rs | 12 + core/src/pb/sf.cosmos.type.v2.rs | 317 ++++++++++++ rust-toolchain.toml | 4 + substreams-cosmos/Cargo.toml | 22 + substreams-cosmos/src/lib.rs | 1 + 14 files changed, 1372 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/push.yml create mode 100644 .rustfmt.toml create mode 100644 Cargo.toml create mode 100644 core/Cargo.toml create mode 100644 core/Makefile create mode 100644 core/buf.gen.yaml create mode 100644 core/src/lib.rs create mode 100644 core/src/pb/mod.rs create mode 100644 core/src/pb/sf.cosmos.type.v2.rs create mode 100644 rust-toolchain.toml create mode 100644 substreams-cosmos/Cargo.toml create mode 100644 substreams-cosmos/src/lib.rs diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000..7d25a87 --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,36 @@ +name: Push +on: [push, pull_request] + +jobs: + check: + name: Check + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Run cargo check + run: cargo check + + test: + name: Test Suite + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Run cargo test + run: cargo test + + lints: + name: Lints + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Run cargo fmt + run: cargo fmt --all -- --check + + - name: Run cargo clippy + run: cargo clippy -- -D warnings \ No newline at end of file diff --git a/.gitignore b/.gitignore index d01bd1a..964d319 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,24 @@ +### Substreams template +.envrc +/substreams-examples/*/*.yaml.pb +localirr +localblocks +rpc-cache +localdata +*.spkg + +### VisualStudioCode template +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +### Rust template # Generated by Cargo # will have compiled files and executables debug/ @@ -10,12 +31,787 @@ Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk -# MSVC Windows builds of rustc generate these, which store debugging information +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Linux template +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### VisualStudio template +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch *.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +### Windows template +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +### macOS template +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Node template +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +### Go template +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +### Python template +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ -# RustRover -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ \ No newline at end of file +yarn.lock +adapters/**/*.csv +adapters/**/*.jsonl diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..8449be0 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1 @@ +max_width = 140 diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..2e626d7 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,25 @@ +[workspace] +resolver = "2" +members = ["core", "substreams-cosmos"] + +[profile.release] +lto = true +opt-level = 's' +strip = "debuginfo" + +[workspace.package] +version = "0.1.0" +edition = "2021" +description = "Substreams development kit for Cosmos chains, contains Firehose Block model and helpers." +authors = ["Denis ", "Yaro "] +homepage = "https://github.com/pinax-network/substreams-cosmos" +repository = "https://github.com/pinax-network/substreams-cosmos" +readme = "README.md" +keywords = ["substreams", "cosmos", "pinax", "firehose", "thegraph"] +categories = ["api-bindings", "external-ffi-bindings", "wasm"] +license = "MIT" +rust-version = "1.76" + +[workspace.dependencies] +substreams-cosmos = { version = "0.1.*", path = "./substreams-cosmos" } +substreams-cosmos-core = { version = "0.1.*", path = "./core" } diff --git a/README.md b/README.md index 0a2466f..fe112fe 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,97 @@ -# substreams-injective -Substreams Injective +# [`Substreams`](https://substreams.streamingfast.io/) for [**Cosmos**](https://cosmos.network/) + +[github](https://github.com/pinax-network/substreams-cosmos) +[crates.io](https://crates.io/crates/substreams-cosmos) +[docs.rs](https://docs.rs/substreams-cosmos) +[GitHub Workflow Status](https://github.com/pinax-network/substreams-cosmos/actions?query=branch%3Adevelop) + +> This library contains the generated Rust protobuf bindings for [Cosmos blocks](https://github.com/pinax-network/firehose-cosmos/blob/develop/proto/sf/cosmos/type/v1/type.proto) as well as helper methods to extract and parse block data. + +## 📖 Documentation + +### + +### Further resources + +- [Substreams documentation](https://substreams.streamingfast.io) + +## Install + +``` +cargo add substreams-cosmos +``` + +## Usage + +Refer to [Docs.rs](https://docs.rs/substreams-cosmos/latest/substreams_cosmos/struct.Block.html#implementations) for helper methods on `Block` that extract action and transaction iterators from the Cosmos block. + +**Cargo.toml** + +```toml +[dependencies] +substreams = "0.5" +substreams-cosmos = "0.5" +``` + +**src/lib.rs** + +```rust +use substreams::errors::Error; +use substreams_cosmos::pb::{Block, EventList}; + +#[substreams::handlers::map] +fn map_events(block: Block) -> Result { + let mut events = vec![]; + + for tx in block.tx_results { + for event in tx.events { + events.push(event); + } + } + Ok(EventList { events }) +} +``` + +Or, using `actions()` helper method to filter all actions of `Statelog` type from `myaccount` account. As a parameter you can specify a list of contract account names to include actions from, that can be empty if you want actions with this signature from any contract account. + +**src/lib.rs** + +```rust +#[substreams::handlers::map] +fn map_actions(param_account: String, block: substreams_cosmos::Block) -> Result { + Ok(Actions { + transfers: block.actions::(&["eosio.token"]) + .map(|(action, trace)| Transfer { + // action.to, action.from, action.memo, action.quantity are available here. + }) + .collect(), + }) +} +``` + +## Using Abigen + +To generate ABI bindings for your smart contract you can add `abi/contract.abi.json` file containing the smart contract ABI, as well as the following `build.rs` file to the root of your project. This will ensure that `src/abi/contract.rs` module containing Rust bindings for your smart contract is always generated in your project: + +**build.rs** + +```rust +fn main() { + substreams_cosmos::Abigen::new("Contract", "abi/eosio.token.json") + .expect("failed to load abi") + .generate() + .expect("failed to generate contract") + .write_to_file("src/abi/eosio.token.rs") + .expect("failed to write contract"); +} +``` + +## Release + +- Run `gen.sh` if there were changes in protobufs +- Bump up version in workspace `Cargo.toml` +- Commit changes +- Tag a release: +- Publish packages in this order: `core`, `abigen`, `substreams-cosmos`. + +TODO: automate releases with github actions diff --git a/core/Cargo.toml b/core/Cargo.toml new file mode 100644 index 0000000..a277a8a --- /dev/null +++ b/core/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "substreams-cosmos-core" +version.workspace = true +description.workspace = true +edition.workspace = true +homepage.workspace = true +repository.workspace = true +license.workspace = true +keywords.workspace = true +categories.workspace = true +rust-version.workspace = true +readme = "../README.md" + +[badges] +maintenance = { status = "actively-developed" } + +[dependencies] +prost = "0.11" +prost-types = "0.11" +substreams = "^0.5.0" + +[build-dependencies] +prost-build = "0.11" + +[dev-dependencies] +anyhow = "1" +pretty_assertions = "1.2.1" diff --git a/core/Makefile b/core/Makefile new file mode 100644 index 0000000..4b3018d --- /dev/null +++ b/core/Makefile @@ -0,0 +1,7 @@ +.PHONY: all +all: + make protogen + +.PHONY: protogen +protogen: + buf generate \ No newline at end of file diff --git a/core/buf.gen.yaml b/core/buf.gen.yaml new file mode 100644 index 0000000..143e1b5 --- /dev/null +++ b/core/buf.gen.yaml @@ -0,0 +1,15 @@ +version: v2 +plugins: + - remote: buf.build/community/neoeinstein-prost:v0.2.2 + out: ./src/pb + opt: + - file_descriptor_set=false + + - remote: buf.build/community/neoeinstein-prost-crate:v0.3.1 + out: ./src/pb + opt: + - no_features + +inputs: + - module: buf.build/enoldev/injective-core + - module: buf.build/streamingfast/firehose-cosmos \ No newline at end of file diff --git a/core/src/lib.rs b/core/src/lib.rs new file mode 100644 index 0000000..6a7c04e --- /dev/null +++ b/core/src/lib.rs @@ -0,0 +1,5 @@ +/// Modules for generated protobuffer +#[path = "pb/sf.cosmos.type.v2.rs"] +#[rustfmt::skip] +#[allow(dead_code)] +pub mod pb; diff --git a/core/src/pb/mod.rs b/core/src/pb/mod.rs new file mode 100644 index 0000000..92ee3be --- /dev/null +++ b/core/src/pb/mod.rs @@ -0,0 +1,12 @@ +// @generated +pub mod sf { + pub mod cosmos { + pub mod r#type { + // @@protoc_insertion_point(attribute:sf.cosmos.type.v2) + pub mod v2 { + include!("sf.cosmos.type.v2.rs"); + // @@protoc_insertion_point(sf.cosmos.type.v2) + } + } + } +} diff --git a/core/src/pb/sf.cosmos.type.v2.rs b/core/src/pb/sf.cosmos.type.v2.rs new file mode 100644 index 0000000..4c13422 --- /dev/null +++ b/core/src/pb/sf.cosmos.type.v2.rs @@ -0,0 +1,317 @@ +// @generated +/// Firehose-centric Block +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Block { + #[prost(bytes="vec", tag="1")] + pub hash: ::prost::alloc::vec::Vec, + #[prost(int64, tag="2")] + pub height: i64, + #[prost(message, optional, tag="3")] + pub time: ::core::option::Option<::prost_types::Timestamp>, + #[prost(message, optional, tag="4")] + pub header: ::core::option::Option
, + #[prost(message, repeated, tag="6")] + pub misbehavior: ::prost::alloc::vec::Vec, + #[prost(message, repeated, tag="7")] + pub events: ::prost::alloc::vec::Vec, + #[prost(bytes="vec", repeated, tag="8")] + pub txs: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec>, + #[prost(message, repeated, tag="9")] + pub tx_results: ::prost::alloc::vec::Vec, + #[prost(message, repeated, tag="10")] + pub validator_updates: ::prost::alloc::vec::Vec, + #[prost(message, optional, tag="11")] + pub consensus_param_updates: ::core::option::Option, +} +/// Header defines the structure of a block header. +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Header { + /// basic block info + #[prost(message, optional, tag="1")] + pub version: ::core::option::Option, + #[prost(string, tag="2")] + pub chain_id: ::prost::alloc::string::String, + #[prost(int64, tag="3")] + pub height: i64, + #[prost(message, optional, tag="4")] + pub time: ::core::option::Option<::prost_types::Timestamp>, + /// prev block info + #[prost(message, optional, tag="5")] + pub last_block_id: ::core::option::Option, + /// hashes of block data + /// + /// commit from validators from the last block + #[prost(bytes="vec", tag="6")] + pub last_commit_hash: ::prost::alloc::vec::Vec, + /// transactions + #[prost(bytes="vec", tag="7")] + pub data_hash: ::prost::alloc::vec::Vec, + /// hashes from the app output from the prev block + /// + /// validators for the current block + #[prost(bytes="vec", tag="8")] + pub validators_hash: ::prost::alloc::vec::Vec, + /// validators for the next block + #[prost(bytes="vec", tag="9")] + pub next_validators_hash: ::prost::alloc::vec::Vec, + /// consensus params for current block + #[prost(bytes="vec", tag="10")] + pub consensus_hash: ::prost::alloc::vec::Vec, + /// state after txs from the previous block + #[prost(bytes="vec", tag="11")] + pub app_hash: ::prost::alloc::vec::Vec, + /// root hash of all results from the txs from the previous block + #[prost(bytes="vec", tag="12")] + pub last_results_hash: ::prost::alloc::vec::Vec, + /// consensus info + /// + /// evidence included in the block + #[prost(bytes="vec", tag="13")] + pub evidence_hash: ::prost::alloc::vec::Vec, + /// original proposer of the block + #[prost(bytes="vec", tag="14")] + pub proposer_address: ::prost::alloc::vec::Vec, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Consensus { + #[prost(uint64, tag="1")] + pub block: u64, + #[prost(uint64, tag="2")] + pub app: u64, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct BlockId { + #[prost(bytes="vec", tag="1")] + pub hash: ::prost::alloc::vec::Vec, + #[prost(message, optional, tag="2")] + pub part_set_header: ::core::option::Option, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PartSetHeader { + #[prost(uint32, tag="1")] + pub total: u32, + #[prost(bytes="vec", tag="2")] + pub hash: ::prost::alloc::vec::Vec, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Misbehavior { + #[prost(enumeration="MisbehaviorType", tag="1")] + pub r#type: i32, + /// The offending validator + #[prost(message, optional, tag="2")] + pub validator: ::core::option::Option, + /// The height when the offense occurred + #[prost(int64, tag="3")] + pub height: i64, + /// The corresponding time where the offense occurred + #[prost(message, optional, tag="4")] + pub time: ::core::option::Option<::prost_types::Timestamp>, + /// Total voting power of the validator set in case the ABCI application does + /// not store historical validators. + /// + #[prost(int64, tag="5")] + pub total_voting_power: i64, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Validator { + /// The first 20 bytes of SHA256(public key) + #[prost(bytes="vec", tag="1")] + pub address: ::prost::alloc::vec::Vec, + /// The voting power + #[prost(int64, tag="3")] + pub power: i64, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Event { + #[prost(string, tag="1")] + pub r#type: ::prost::alloc::string::String, + #[prost(message, repeated, tag="2")] + pub attributes: ::prost::alloc::vec::Vec, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct EventAttribute { + #[prost(string, tag="1")] + pub key: ::prost::alloc::string::String, + /// bool index = 3; // nondeterministic + #[prost(string, tag="2")] + pub value: ::prost::alloc::string::String, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct EventBytes { + #[prost(string, tag="1")] + pub r#type: ::prost::alloc::string::String, + #[prost(message, repeated, tag="2")] + pub attributes: ::prost::alloc::vec::Vec, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct EventAttributeBytes { + #[prost(bytes="vec", tag="1")] + pub key: ::prost::alloc::vec::Vec, + /// bool index = 3; // nondeterministic + #[prost(bytes="vec", tag="2")] + pub value: ::prost::alloc::vec::Vec, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct TxResults { + #[prost(uint32, tag="1")] + pub code: u32, + #[prost(bytes="vec", tag="2")] + pub data: ::prost::alloc::vec::Vec, + /// nondeterministic + #[prost(string, tag="3")] + pub log: ::prost::alloc::string::String, + /// nondeterministic + #[prost(string, tag="4")] + pub info: ::prost::alloc::string::String, + #[prost(int64, tag="5")] + pub gas_wanted: i64, + #[prost(int64, tag="6")] + pub gas_used: i64, + /// nondeterministic + #[prost(message, repeated, tag="7")] + pub events: ::prost::alloc::vec::Vec, + #[prost(string, tag="8")] + pub codespace: ::prost::alloc::string::String, +} +/// ValidatorUpdate +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct ValidatorUpdate { + #[prost(message, optional, tag="1")] + pub pub_key: ::core::option::Option, + #[prost(int64, tag="2")] + pub power: i64, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PublicKey { + #[prost(oneof="public_key::Sum", tags="1, 2")] + pub sum: ::core::option::Option, +} +/// Nested message and enum types in `PublicKey`. +pub mod public_key { + #[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Oneof)] + pub enum Sum { + #[prost(bytes, tag="1")] + Ed25519(::prost::alloc::vec::Vec), + #[prost(bytes, tag="2")] + Secp256k1(::prost::alloc::vec::Vec), + } +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct ConsensusParams { + #[prost(message, optional, tag="1")] + pub block: ::core::option::Option, + #[prost(message, optional, tag="2")] + pub evidence: ::core::option::Option, + #[prost(message, optional, tag="3")] + pub validator: ::core::option::Option, + #[prost(message, optional, tag="4")] + pub version: ::core::option::Option, +} +/// BlockParams contains limits on the block size. +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct BlockParams { + /// Max block size, in bytes. + /// Note: must be greater than 0 + #[prost(int64, tag="1")] + pub max_bytes: i64, + /// Max gas per block. + /// Note: must be greater or equal to -1 + #[prost(int64, tag="2")] + pub max_gas: i64, +} +/// EvidenceParams determine how we handle evidence of malfeasance. +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct EvidenceParams { + /// Max age of evidence, in blocks. + /// + /// The basic formula for calculating this is: MaxAgeDuration / {average block + /// time}. + #[prost(int64, tag="1")] + pub max_age_num_blocks: i64, + /// Max age of evidence, in time. + /// + /// It should correspond with an app's "unbonding period" or other similar + /// mechanism for handling [Nothing-At-Stake + /// attacks](). + #[prost(message, optional, tag="2")] + pub max_age_duration: ::core::option::Option<::prost_types::Duration>, + /// This sets the maximum size of total evidence in bytes that can be committed in a single block. + /// and should fall comfortably under the max block bytes. + /// Default is 1048576 or 1MB + #[prost(int64, tag="3")] + pub max_bytes: i64, +} +/// ValidatorParams restrict the public key types validators can use. +/// NOTE: uses ABCI pubkey naming, not Amino names. +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct ValidatorParams { + #[prost(string, repeated, tag="1")] + pub pub_key_types: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, +} +/// VersionParams contains the ABCI application version. +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct VersionParams { + #[prost(uint64, tag="1")] + pub app: u64, +} +/// HashedParams is a subset of ConsensusParams. +/// +/// It is hashed into the Header.ConsensusHash. +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct HashedParams { + #[prost(int64, tag="1")] + pub block_max_bytes: i64, + #[prost(int64, tag="2")] + pub block_max_gas: i64, +} +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum MisbehaviorType { + Unknown = 0, + DuplicateVote = 1, + LightClientAttack = 2, +} +impl MisbehaviorType { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + MisbehaviorType::Unknown => "UNKNOWN", + MisbehaviorType::DuplicateVote => "DUPLICATE_VOTE", + MisbehaviorType::LightClientAttack => "LIGHT_CLIENT_ATTACK", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "UNKNOWN" => Some(Self::Unknown), + "DUPLICATE_VOTE" => Some(Self::DuplicateVote), + "LIGHT_CLIENT_ATTACK" => Some(Self::LightClientAttack), + _ => None, + } + } +} +// @@protoc_insertion_point(module) diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..45bb8d6 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "1.76" +components = ["rustfmt", "clippy"] +targets = ["wasm32-unknown-unknown"] diff --git a/substreams-cosmos/Cargo.toml b/substreams-cosmos/Cargo.toml new file mode 100644 index 0000000..5fbd64f --- /dev/null +++ b/substreams-cosmos/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "substreams-cosmos" +version.workspace = true +description.workspace = true +edition.workspace = true +homepage.workspace = true +repository.workspace = true +license.workspace = true +keywords.workspace = true +categories.workspace = true +rust-version.workspace = true +readme = "../README.md" + +[badges] +maintenance = { status = "actively-developed" } + +[dependencies] +substreams = "^0.5" +substreams-cosmos-core = { version = "0.*", path = "../core" } + +[dev-dependencies] +anyhow = "1" diff --git a/substreams-cosmos/src/lib.rs b/substreams-cosmos/src/lib.rs new file mode 100644 index 0000000..2bfa239 --- /dev/null +++ b/substreams-cosmos/src/lib.rs @@ -0,0 +1 @@ +pub use substreams_cosmos_core::{pb, pb::Block};