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

avoid $ at begging in ```sh codeblocks, require codeblock have language #358

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .remarkrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ module.exports = {
['remark-lint-restrict-elements', { type: 'heading', depth: 1 }],
'remark-lint-heading-increment',
['remark-lint-no-heading-punctuation', '\\.,;:'],
'remark-lint-no-shell-dollars',
'remark-lint-fenced-code-flag',
],
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"pre-commit": "lint-staged --concurrent false",
"pre-push": "pnpm build",
"prepare": "husky install && chmod +x .husky/*",
"prettier": "prettier . --loglevel warn --write",
"prettier:check": "prettier . --loglevel warn --check",
Comment on lines -19 to -20
Copy link
Contributor

@benface benface Apr 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I previously added --loglevel warn because it lists all the files otherwise, even the ones that are correctly formatted, and I felt like it was uselessly verbose. Do you like that behavior, or does adding --cache and --list-different change it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't list all files, it updates only last line with linted file
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, so I just realized that --loglevel warn was only necessary if --check wasn't present (my bad for missing that), and that --list-different basically does the same thing, but it's even better because it looks like something's happening by updating that last line like you said. Awesome, thank you!

"prettier": "prettier . --cache --write --list-different",
"prettier:check": "prettier . --cache --check",
"start": "pnpm --filter @graphprotocol/docs start",
"typecheck": "pnpm --filter @graphprotocol/docs typecheck"
},
Expand All @@ -30,9 +30,11 @@
"prettier": "^2.8.8",
"prettier-plugin-pkg": "^0.17.1",
"remark-frontmatter": "^4.0.1",
"remark-lint-fenced-code-flag": "^3.1.1",
"remark-lint-first-heading-level": "^3.1.1",
"remark-lint-heading-increment": "^3.1.1",
"remark-lint-no-heading-punctuation": "^3.1.1",
"remark-lint-no-shell-dollars": "^3.1.1",
"remark-lint-restrict-elements": "workspace:*",
"typescript": "5.0.4"
},
Expand Down
27 changes: 27 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 54 additions & 48 deletions website/pages/en/cookbook/arweave.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ This is the logic that determines how data should be retrieved and stored when s

During subgraph development there are two key commands:

```
$ graph codegen # generates types from the schema file identified in the manifest
$ graph build # generates Web Assembly from the AssemblyScript files, and prepares all the subgraph files in a /build folder
```sh
graph codegen # generates types from the schema file identified in the manifest
graph build # generates Web Assembly from the AssemblyScript files, and prepares all the subgraph files in a /build folder
```

## Subgraph Manifest Definition
Expand Down Expand Up @@ -84,18 +84,18 @@ dataSources:

- Arweave subgraphs introduce a new kind of data source (`arweave`)
- The network should correspond to a network on the hosting Graph Node. On the Hosted Service, Arweave's mainnet is `arweave-mainnet`
- Arweave data sources introduce an optional source.owner field, which is the public key of an Arweave wallet
- Arweave data sources introduce an optional `source.owner` field, which is the public key of an Arweave wallet

Arweave data sources support two types of handlers:

- `blockHandlers` - Run on every new Arweave block. No source.owner is required.
- `transactionHandlers` - Run on every transaction where the data source's `source.owner` is the owner. Currently an owner is required for `transactionHandlers`, if users want to process all transactions they should provide "" as the `source.owner`
- `blockHandlers` - Run on every new Arweave block. No `source.owner` is required.
- `transactionHandlers` - Run on every transaction where the data source's `source.owner` is the owner. Currently, an owner is required for `transactionHandlers`, if users want to process all transactions they should provide "" as the `source.owner`

> The source.owner can be the owner's address, or their Public Key.
> The `source.owner` can be the owner's address, or their Public Key.

> Transactions are the building blocks of the Arweave permaweb and they are objects created by end-users.

> Note: [Bundlr](https://bundlr.network/) transactions are not supported yet.
> **Note:** [Bundlr](https://bundlr.network/) transactions are not supported yet.

## Schema Definition

Expand Down Expand Up @@ -184,56 +184,62 @@ This is not currently supported.

### How can I filter transactions to a specific account?

The source.owner can be the user's public key or account address.
The `source.owner` can be the user's public key or account address.

### What is the current encryption format?

Data is generally passed into the mappings as Bytes, which if stored directly is returned in the subgraph in a `hex` format (ex. block and transaction hashes). You may want to convert to a `base64` or `base64 URL`-safe format in your mappings, in order to match what is displayed in block explorers like [Arweave Explorer](https://viewblock.io/arweave/).

The following `bytesToBase64(bytes: Uint8Array, urlSafe: boolean): string` helper function can be used, and will be added to `graph-ts`:

```
```ts
// prettier-ignore
const base64Alphabet = [
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/"
];

'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/',
]

// prettier-ignore
const base64UrlAlphabet = [
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-", "_"
];
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_',
]

function bytesToBase64(bytes: Uint8Array, urlSafe: boolean): string {
let alphabet = urlSafe? base64UrlAlphabet : base64Alphabet;

let result = '', i: i32, l = bytes.length;
for (i = 2; i < l; i += 3) {
result += alphabet[bytes[i - 2] >> 2];
result += alphabet[((bytes[i - 2] & 0x03) << 4) | (bytes[i - 1] >> 4)];
result += alphabet[((bytes[i - 1] & 0x0F) << 2) | (bytes[i] >> 6)];
result += alphabet[bytes[i] & 0x3F];
}
if (i === l + 1) { // 1 octet yet to write
result += alphabet[bytes[i - 2] >> 2];
result += alphabet[(bytes[i - 2] & 0x03) << 4];
if (!urlSafe) {
result += "==";
}
}
if (!urlSafe && i === l) { // 2 octets yet to write
result += alphabet[bytes[i - 2] >> 2];
result += alphabet[((bytes[i - 2] & 0x03) << 4) | (bytes[i - 1] >> 4)];
result += alphabet[(bytes[i - 1] & 0x0F) << 2];
if (!urlSafe) {
result += "=";
}
}
return result;
let alphabet = urlSafe ? base64UrlAlphabet : base64Alphabet

let result = '',
i: i32,
l = bytes.length
for (i = 2; i < l; i += 3) {
result += alphabet[bytes[i - 2] >> 2]
result += alphabet[((bytes[i - 2] & 0x03) << 4) | (bytes[i - 1] >> 4)]
result += alphabet[((bytes[i - 1] & 0x0f) << 2) | (bytes[i] >> 6)]
result += alphabet[bytes[i] & 0x3f]
}
if (i === l + 1) {
// 1 octet yet to write
result += alphabet[bytes[i - 2] >> 2]
result += alphabet[(bytes[i - 2] & 0x03) << 4]
if (!urlSafe) {
result += '=='
}
}
if (!urlSafe && i === l) {
// 2 octets yet to write
result += alphabet[bytes[i - 2] >> 2]
result += alphabet[((bytes[i - 2] & 0x03) << 4) | (bytes[i - 1] >> 4)]
result += alphabet[(bytes[i - 1] & 0x0f) << 2]
if (!urlSafe) {
result += '='
}
}
return result
}
```
18 changes: 9 additions & 9 deletions website/pages/en/cookbook/base-testnet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,27 @@ Before you can deploy your subgraph, you will need to authenticate with the Subg

Authenticate the subgraph on studio

```
```sh
graph auth --studio <DEPLOY_KEY>
```

Next, enter your subgraph's directory.

```
cd <SUBGRAPH_DIRECTORY>
```sh
cd <SUBGRAPH_DIRECTORY>
```

Build your subgraph with the following command:

```
graph codegen && graph build
```
```sh
graph codegen && graph build
```

Finally, you can deploy your subgraph using this command:

```
graph deploy --studio <SUBGRAPH_SLUG>
```
```sh
graph deploy --studio <SUBGRAPH_SLUG>
```

### 5. Query your subgraph

Expand Down
4 changes: 2 additions & 2 deletions website/pages/en/cookbook/cosmos.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ An example of how to decode message data in a subgraph can be found [here](https
The first step before starting to write the subgraph mappings is to generate the type bindings based on the entities that have been defined in the subgraph schema file (`schema.graphql`). This will allow the mapping functions to create new objects of those types and save them to the store. This is done by using the `codegen` CLI command:

```bash
$ graph codegen
graph codegen
```

Once the mappings are ready, the subgraph needs to be built. This step will highlight any errors the manifest or the mappings might have. A subgraph needs to build successfully in order to be deployed to the Graph Node. It can be done using the `build` CLI command:

```bash
$ graph build
graph build
```

## Deploying a Cosmos subgraph
Expand Down
4 changes: 2 additions & 2 deletions website/pages/en/cookbook/grafting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ The `base` and `block` values can be found by deploying two subgraphs: one for t

It returns something like this:

```
```json
{
"data": {
"withdrawals": [
Expand Down Expand Up @@ -145,7 +145,7 @@ The graft replacement subgraph.yaml will have a new contract address. This could

It should return the following:

```
```json
{
"data": {
"withdrawals": [
Expand Down
8 changes: 4 additions & 4 deletions website/pages/en/cookbook/near.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ There are three aspects of subgraph definition:
During subgraph development there are two key commands:

```bash
$ graph codegen # generates types from the schema file identified in the manifest
$ graph build # generates Web Assembly from the AssemblyScript files, and prepares all the subgraph files in a /build folder
graph codegen # generates types from the schema file identified in the manifest
graph build # generates Web Assembly from the AssemblyScript files, and prepares all the subgraph files in a /build folder
```

### Subgraph Manifest Definition
Expand Down Expand Up @@ -187,8 +187,8 @@ As a quick primer - the first step is to "create" your subgraph - this only need
Once your subgraph has been created, you can deploy your subgraph by using the `graph deploy` CLI command:

```sh
$ graph create --node <graph-node-url> subgraph/name # creates a subgraph on a local Graph Node (on the Hosted Service, this is done via the UI)
$ graph deploy --node <graph-node-url> --ipfs https://api.thegraph.com/ipfs/ # uploads the build files to a specified IPFS endpoint, and then deploys the subgraph to a specified Graph Node based on the manifest IPFS hash
graph create --node <graph-node-url> subgraph/name # creates a subgraph on a local Graph Node (on the Hosted Service, this is done via the UI)
graph deploy --node <graph-node-url> --ipfs https://api.thegraph.com/ipfs/ # uploads the build files to a specified IPFS endpoint, and then deploys the subgraph to a specified Graph Node based on the manifest IPFS hash
```

The node configuration will depend on where the subgraph is being deployed.
Expand Down
12 changes: 6 additions & 6 deletions website/pages/en/cookbook/quick-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ On your local machine, run one of the following commands:

```sh
# NPM
$ npm install -g @graphprotocol/graph-cli
npm install -g @graphprotocol/graph-cli

# Yarn
$ yarn global add @graphprotocol/graph-cli
yarn global add @graphprotocol/graph-cli
```

## 3. Initialize your Subgraph
Expand Down Expand Up @@ -74,15 +74,15 @@ For more information on how to write your subgraph, see [Creating a Subgraph](/d
Once your subgraph is written, run the following commands:

```sh
$ graph codegen
$ graph build
graph codegen
graph build
```

- Authenticate and deploy your subgraph. The deploy key can be found on the Subgraph page in Subgraph Studio.

```sh
$ graph auth --studio <DEPLOY_KEY>
$ graph deploy --studio <SUBGRAPH_SLUG>
graph auth --studio <DEPLOY_KEY>
graph deploy --studio <SUBGRAPH_SLUG>
```

You will be asked for a version label. It's strongly recommended to use [semver](https://semver.org/) for versioning like `0.0.1`. That said, you are free to choose any string as version such as:`v1`, `version1`, `asdf`.
Expand Down
16 changes: 8 additions & 8 deletions website/pages/en/cookbook/subgraph-debug-forking.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ And I answer:
2. Forking is easy, no need to sweat:

```bash
$ graph deploy <subgraph-name> --debug-fork <subgraph-id> --ipfs http://localhost:5001 --node http://localhost:8020
graph deploy <subgraph-name> --debug-fork <subgraph-id> --ipfs http://localhost:5001 --node http://localhost:8020
```

Also, don't forget to set the `dataSources.source.startBlock` field in the subgraph manifest to the number of the problematic block, so you can skip indexing unnecessary blocks and take advantage of the fork!
Expand All @@ -82,19 +82,19 @@ So, here is what I do:

0. I spin-up a local graph node ([here is how to do it](https://github.com/graphprotocol/graph-node#running-a-local-graph-node)) with the `fork-base` option set to: `https://api.thegraph.com/subgraphs/id/`, since I will fork a subgraph, the buggy one I deployed earlier, from the [HostedService](https://thegraph.com/hosted-service/).

```
$ cargo run -p graph-node --release -- \
--postgres-url postgresql://USERNAME[:PASSWORD]@localhost:5432/graph-node \
--ethereum-rpc NETWORK_NAME:[CAPABILITIES]:URL \
--ipfs 127.0.0.1:5001
--fork-base https://api.thegraph.com/subgraphs/id/
```sh
cargo run -p graph-node --release -- \
--postgres-url postgresql://USERNAME[:PASSWORD]@localhost:5432/graph-node \
--ethereum-rpc NETWORK_NAME:[CAPABILITIES]:URL \
--ipfs 127.0.0.1:5001
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
--ipfs 127.0.0.1:5001
--ipfs 127.0.0.1:5001 \

i think?

--fork-base https://api.thegraph.com/subgraphs/id/
```

1. After careful inspection I notice that there is a mismatch in the `id` representations used when indexing `Gravatar`s in my two handlers. While `handleNewGravatar` converts it to a hex (`event.params.id.toHex()`), `handleUpdatedGravatar` uses an int32 (`event.params.id.toI32()`) which causes the `handleUpdatedGravatar` to panic with "Gravatar not found!". I make them both convert the `id` to a hex.
2. After I made the changes I deploy my subgraph to the local Graph node, **_forking the failing subgraph_** and setting `dataSources.source.startBlock` to `6190343` in `subgraph.yaml`:

```bash
$ graph deploy gravity --debug-fork QmNp169tKvomnH3cPXTfGg4ZEhAHA6kEq5oy1XDqAxqHmW --ipfs http://localhost:5001 --node http://localhost:8020
graph deploy gravity --debug-fork QmNp169tKvomnH3cPXTfGg4ZEhAHA6kEq5oy1XDqAxqHmW --ipfs http://localhost:5001 --node http://localhost:8020
```

3. I inspect the logs produced by the local Graph node and, Hooray!, everything seems to be working.
Expand Down
2 changes: 1 addition & 1 deletion website/pages/en/deploying/hosted-service.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The `<GITHUB_USER>` in this case is your GitHub user or organization name, `<SUB

The second mode `graph init` supports is creating a new project from an example subgraph. The following command does this:

```
```sh
graph init --from-example --product hosted-service <GITHUB_USER>/<SUBGRAPH_NAME> [<DIRECTORY>]
```

Expand Down
Loading