Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color Rust code snippets in substreams-powered subgraphs docs #530

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions website/pages/en/cookbook/substreams-powered-subgraphs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ title: Substreams-powered subgraphs

This cookbook requires [yarn](https://yarnpkg.com/), [the dependencies necessary for local Substreams development](https://substreams.streamingfast.io/developers-guide/installation-requirements), and the latest version of Graph CLI (>=0.52.0):

```
```sh
npm install -g @graphprotocol/graph-cli
```

## Get the cookbook

> This cookbook uses this [Substreams-powered subgraph as a reference](https://github.com/graphprotocol/graph-tooling/tree/main/examples/substreams-powered-subgraph).

```
```sh
graph init --from-example substreams-powered-subgraph
```

Expand Down Expand Up @@ -45,7 +45,7 @@ message Contract {

The core logic of the Substreams package is a `map_contract` module in `lib.rs`, which processes every block, filtering for Create calls which did not revert, returning `Contracts`:

```
```rust
#[substreams::handlers::map]
fn map_contract(block: eth::v2::Block) -> Result<Contracts, substreams::errors::Error> {
let contracts = block
Expand All @@ -71,7 +71,7 @@ A Substreams package can be used by a subgraph as long as it has a module which

> The `substreams_entity_change` crate also has a dedicated `Tables` function for simply generating entity changes ([documentation](https://docs.rs/substreams-entity-change/1.2.2/substreams_entity_change/tables/index.html)). The Entity Changes generated must be compatible with the `schema.graphql` entities defined in the `subgraph.graphql` of the corresponding subgraph.

```
```rust
#[substreams::handlers::map]
pub fn graph_out(contracts: Contracts) -> Result<EntityChanges, substreams::errors::Error> {
// hash map of name to a table
Expand All @@ -90,7 +90,7 @@ pub fn graph_out(contracts: Contracts) -> Result<EntityChanges, substreams::erro

These types and modules are pulled together in `substreams.yaml`:

```
```yml
hasparus marked this conversation as resolved.
Show resolved Hide resolved
specVersion: v0.1.0
package:
name: 'substreams_test' # the name to be used in the .spkg
Expand Down
Loading