Skip to content

Commit

Permalink
Inital work on 3.0 migration guide (#425)
Browse files Browse the repository at this point in the history
* Inital work on 3.0 migration guide

* Cosmos chaintypes

* draft (#421)

* Update historic manifest

* Add sections for TS

* Update Ts Manifest

* Update Manifest More

* Update project.ts

* Typescript Final Updates

---------

Co-authored-by: Jay Ji <[email protected]>
  • Loading branch information
jamesbayly and jiqiang90 authored Oct 12, 2023
1 parent 69cbc59 commit 8d19a5e
Show file tree
Hide file tree
Showing 138 changed files with 4,185 additions and 2,550 deletions.
4 changes: 4 additions & 0 deletions docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export default defineUserConfig({
"/subquery_network/indexers/indexer-security-guide.html",
"/subquery_network/indexers/ssl-configuration.html":
"/subquery_network/indexers/indexer-security-guide.html",
"/build/manifest/terra.html": "/build/manifest/cosmos.html",
"/build/mapping/terra.html": "/build/mapping/cosmos.html",
"/build/quickstart/quickstart_chains/terra.html":
"/build/quickstart/quickstart_chains/cosmos.html",
},
}),
],
Expand Down
2 changes: 1 addition & 1 deletion docs/bg/build/graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type Title @entity {
INSERT INTO titles (id, name) VALUES ('id_1', 'Captain')
```

```typescript
```ts
// Манипулатор във функция за съпоставяне
import { User } from "../types/models/User";
import { Title } from "../types/models/Title";
Expand Down
2 changes: 1 addition & 1 deletion docs/bg/build/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ yarn codegen

`console.log` метод **вече не се поддържа**. Вместо това `logger` модул е инжектиран в types, което означава, че можем да поддържаме регистратор, приемащ различни нива на логване.

```typescript
```ts
logger.info("Info level message");
logger.debug("Debugger level message");
logger.warn("Warning level message");
Expand Down
4 changes: 2 additions & 2 deletions docs/bg/build/mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export async function handleCall(extrinsic: SubstrateExtrinsic): Promise<void> {
Документите в [JSON-RPC](https://polkadot.js.org/docs/substrate/rpc/#rpc) предоставят някои методи, които приема `BlockHash` като входен параметър (например `at?: BlockHash`), който вече е разрешен. Ние също така променихме тези методи, за да приемем хеш на текущия индексиращ блок по подразбиране.
```typescript
```ts
// Да приемем, че в момента индексираме блок с този хеш номер
const blockhash = `0x844047c4cf1719ba6d54891e92c071a41e3dfe789d064871148e9d41ef086f6a`;

Expand Down Expand Up @@ -275,7 +275,7 @@ yarn generate:meta

Сега във функцията за преобразуване можем да покажем как метаданните и типовете всъщност декорират API. RPC крайната точка ще поддържа модулите и методите, които декларирахме по-горе. И за да използвате персонализирано rpc повикване, моля, вижте раздел [Персонализирани верижни rpc повиквания](#custom-chain-rpc-calls)

```typescript
```ts
export async function kittyApiHandler(): Promise<void> {
//return the KittyIndex type
const nextKittyId = await api.query.kitties.nextKittyId();
Expand Down
87 changes: 45 additions & 42 deletions docs/build/cosmos-evm.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,48 +136,51 @@ export async function handleEthermintEvmCall(

## Data Source Example

This is an extract from the `project.yaml` manifest file.

```yaml
dataSources:
- kind: cosmos/EthermintEvm
startBlock: 1474211
processor:
file: "./node_modules/@subql/ethermint-evm-processor/dist/bundle.js"
options:
abi: erc20
address: "0xD4949664cD82660AaE99bEdc034a0deA8A0bd517" # wevmos
assets:
erc20:
file: "./erc20.abi.json"
mapping:
file: "./dist/index.js"
handlers:
# Using block handlers slows your project down as they can be executed with each and every block. Only use if you need to
# - handler: handleBlock
# kind: cosmos/BlockHandler
- handler: handleEthermintEvmEvent
kind: cosmos/EthermintEvmEvent
filter:
topics:
# The topics filter follows the Ethereum JSON-PRC log filters
# https://docs.ethers.io/v5/concepts/events
# Example valid values:
# - '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
# - Transfer(address,address,u256)
# - Transfer(address from,address to,uint256 value)
- Transfer(address indexed src, address indexed dst, uint256 wad)
- null
- null
- null
- handler: handleEthermintEvmCall
kind: cosmos/EthermintEvmCall
filter:
# Either Function Signature strings or the function `sighash` to filter the function called on the contract
# ](https://docs.ethers.io/v5/api/utils/abi/fragments/#FunctionFragment)
method: approve(address guy, uint256 wad)
# The transaction sender
from: "0x86ed94fb8fffe265caf38cbefb0431d2fbf862c1"
This is an extract from the `project.ts` manifest file.

```ts
{
dataSources: [
{
kind: "cosmos/EthermintEvm",
startBlock: 446,
processor: {
file: "./node_modules/@subql/ethermint-evm-processor/dist/bundle.js",
options: {
abi: "erc20",
address: "0x5c7f8a570d578ed84e63fdfa7b1ee72deae1ae23", // Wrapped CRO
},
},
assets: new Map([["erc20", { file: "./erc20.abi.json" }]]),
mapping: {
file: "./dist/index.js",
handlers: [
{
handler: "handleEthermintEvmCall",
kind: "cosmos/EthermintEvmCall",
filter: {
// Either Function Signature strings or the function `sighash` to filter the function called on the contract
// https://docs.ethers.io/v5/api/utils/abi/fragments/#FunctionFragment
method: "approve(address guy, uint256 wad)",
},
},
{
handler: "handleEthermintEvmEvent",
kind: "cosmos/EthermintEvmEvent",
filter: {
// The topics filter follows the Ethereum JSON-PRC log filters
// https://docs.ethers.io/v5/concepts/events
// Example valid values:
// - '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
// - Transfer(address,address,u256)
topics: ["Transfer(address src, address dst, uint256 wad)"],
},
},
],
},
},
],
}
```

## Known Limitations
Expand Down
67 changes: 65 additions & 2 deletions docs/build/graph-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ The manifest file contains the largest set of differences, but once you understa

**Notable differences include:**

- SubQuery has moved to by default offering a Typescript based manifest file for better type safety and feature discoverability. SubQuery does however allow you to define your manifest in YAML if you wish to do so.
- SubQuery has a section in the manifest for the `network:`. This is where you define what network your SubQuery project indexes, and the RPC endpoints (non-pruned archive nodes) that it connects to in order to retrieve the data. Make sure to include the `dictionary:` endpoint in this section as it will speed up the indexing speed of your SubQuery project.
- Both SubGraphs and SubQuery projects use the `dataSources:` section to list the mapping files.
- Similarly, you can define the contract ABI information for the smart contract that you are indexing.
Expand Down Expand Up @@ -113,7 +114,69 @@ dataSources:
file: ./src/mapping.ts
```
@tab:active SubQuery
@tab:active SubQuery (TS)
```ts
const project: EthereumProject = {
specVersion: "1.0.0",
version: "0.0.1",
name: "subquery-example-gravatar",
description:
"This project can be use as a starting point for developing your new Ethereum SubQuery project, it indexes all Gravatars on Ethereum",
repository: "https://github.com/subquery/ethereum-subql-starter",
runner: {
node: {
name: "@subql/node-ethereum",
version: ">=3.0.0",
},
query: {
name: "@subql/query",
version: "*",
},
},
schema: {
file: "./schema.graphql",
},
network: {
chainId: "1",
endpoint: ["https://eth.api.onfinality.io/public"],
dictionary: "https://gx.api.subquery.network/sq/subquery/eth-dictionary",
},
dataSources: [
{
kind: EthereumDatasourceKind.Runtime,
startBlock: 6175243,
options: {
abi: "gravity",
address: "0x2E645469f354BB4F5c8a05B3b30A929361cf77eC",
},
assets: new Map([["gravity", { file: "./abis/Gravity.json" }]]),
mapping: {
file: "./dist/index.js",
handlers: [
{
kind: EthereumHandlerKind.Event,
handler: "handleNewGravatar",
filter: {
topics: ["NewGravatar(uint256,address,string,string)"],
},
},
{
kind: EthereumHandlerKind.Event,
handler: "handleUpdatedGravatar",
filter: {
topics: ["UpdatedGravatar(uint256,address,string,string)"],
},
},
],
},
},
],
};
export default project;
```

@tab SubQuery (YAML)

```yaml
# ******* SubQuery *******
Expand Down Expand Up @@ -175,7 +238,7 @@ All GraphQL entities will have generated entity classes that provide type-safe e
import { Gravatar } from "../types";
```

For ABI's registered in the `project.yaml`, similar type safe entities will be generated using `npx typechain --target=ethers-v5` command, allowing you to bind these contracts to specific addresses in the mappings and call read-only contract methods against the block being processed. It will also generate a class for every contract event to provide easy access to event parameters, as well as the block and transaction the event originated from. All of these types are written to `src/types` directory. In the example [Gravatar SubQuery project](../quickstart/quickstart_chains/ethereum-gravatar.md), you would import these types like so.
For ABI's registered in the `project.ts`, similar type safe entities will be generated using `npx typechain --target=ethers-v5` command, allowing you to bind these contracts to specific addresses in the mappings and call read-only contract methods against the block being processed. It will also generate a class for every contract event to provide easy access to event parameters, as well as the block and transaction the event originated from. All of these types are written to `src/types` directory. In the example [Gravatar SubQuery project](../quickstart/quickstart_chains/ethereum-gravatar.md), you would import these types like so.

```ts
import {
Expand Down
2 changes: 1 addition & 1 deletion docs/build/graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ which both can directly be accessed in the mapping function.
INSERT INTO titles (id, name) VALUES ('id_1', 'Captain')
```
```typescript
```ts
// Handler in mapping function
import { User } from "../types/models/User";
import { Title } from "../types/models/Title";
Expand Down
Loading

0 comments on commit 8d19a5e

Please sign in to comment.