Skip to content

Commit

Permalink
Update substreams-powered-subgraphs.mdx (#666)
Browse files Browse the repository at this point in the history
* Update substreams-powered-subgraphs.mdx

Annotation of `rust` block of codes with the `rust` field in the code snippet

* Run `pnpm check:fix`

---------

Co-authored-by: Eduard Voiculescu <[email protected]>
  • Loading branch information
benface and Eduard-Voiculescu authored May 7, 2024
1 parent 41e66f6 commit 0a7047b
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions website/pages/en/cookbook/substreams-powered-subgraphs.mdx
Original file line number Diff line number Diff line change
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`:

```
```yaml
specVersion: v0.1.0
package:
name: 'substreams_test' # the name to be used in the .spkg
Expand Down Expand Up @@ -124,7 +124,6 @@ modules: # specify modules with their inputs and outputs.
- map: map_contract
output:
type: proto:substreams.entity.v1.EntityChanges # this type can be consumed by Graph Node
```
You can check the overall "flow" from a Block, to `map_contract` to `graph_out` by running `substreams graph`:
Expand Down

0 comments on commit 0a7047b

Please sign in to comment.