Skip to content

Commit d2c527a

Browse files
xiaoch05sxlwar
andauthored
add crab <> crab parachain (#51)
* add crab parachain * crab->crabparachain * update genesis hash * repair token * update subql url * some config * enable crab parachain * filter event * repair target hash Co-authored-by: sxlwar <[email protected]>
1 parent 7595fe5 commit d2c527a

File tree

23 files changed

+6880
-28
lines changed

23 files changed

+6880
-28
lines changed

apollo/.env.prod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
SUBSTRATE_SUBSTRATE_BACKING=https://api.subquery.network/sq/helix-bridge/darwinia
22
SUBSTRATE_SUBSTRATE_ISSUING=https://crab-thegraph.darwinia.network/subgraphs/name/wormhole/Sub2SubMappingTokenFactory
33
SUBSTRATE_DVM_ENDPOINT=https://api.subquery.network/sq/helix-bridge/crab
4-
CHAIN_TYPE=formal
4+
SUBSTRATE_TO_PARACHAIN_BACKING=https://api.subquery.network/sq/helix-bridge/crab
5+
SUBSTRATE_TO_PARACHAIN_ISSUING=https://api.subquery.network/sq/helix-bridge/cpchain
6+
CHAIN_TYPE=formal
7+
PARACHAIN_LOCK_FEE_TOKEN=Crab

apollo/src/substrate2parachain/substrate2parachain.service.ts

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Injectable, Logger, OnModuleInit } from '@nestjs/common';
22
import { ConfigService } from '@nestjs/config';
33
import axios from 'axios';
4-
import { last } from 'lodash';
54
import { AggregationService } from '../aggregation/aggregation.service';
65
import { RecordsService } from '../base/RecordsService';
76
import { Transfer, TransferAction } from '../base/TransferService';
@@ -44,10 +43,6 @@ export class Substrate2parachainService extends RecordsService implements OnModu
4443
}
4544

4645
async onModuleInit() {
47-
if (this.configService.get('CHAIN_TYPE') === 'formal') {
48-
return;
49-
}
50-
5146
this.transferService.transfers.forEach((item, index) => {
5247
this.taskService.addInterval(
5348
`${item.backing.chain}-parachain-fetch_history_data`,
@@ -118,13 +113,17 @@ export class Substrate2parachainService extends RecordsService implements OnModu
118113
bridgeDispatchError: '',
119114
});
120115

116+
if (!this.needSyncLock[index] && isLock) {
117+
this.needSyncLock[index] = true;
118+
} else if (!this.needSyncBurn[index] && !isLock) {
119+
this.needSyncBurn[index] = true;
120+
}
121+
121122
if (node.result === 0) {
122123
if (!this.needSyncLockConfirmed[index] && isLock) {
123124
this.needSyncLockConfirmed[index] = true;
124-
this.needSyncLock[index] = true;
125125
} else if (!this.needSyncBurnConfirmed && !isLock) {
126126
this.needSyncBurnConfirmed[index] = true;
127-
this.needSyncBurn[index] = true;
128127
}
129128
}
130129
}
@@ -173,28 +172,14 @@ export class Substrate2parachainService extends RecordsService implements OnModu
173172
return;
174173
}
175174

176-
const dispatchLaneId = '726f6c69';
177-
const recordLaneId = '70616c69';
178-
179-
const pickId = (id: string) => {
180-
const target = last(id.split('-'));
181-
182-
return action === 'lock' ? target : target.replace(recordLaneId, dispatchLaneId);
183-
};
184-
185-
const ids = uncheckedRecords.map((item) => `"${pickId(item.id)}"`).join(',');
175+
const ids = uncheckedRecords.map((item) => `"${item.id.split('-')[3]}"`).join(',');
186176

187177
const nodes = await axios
188178
.post(to.url, {
189179
query: `query { bridgeDispatchEvents (filter: {id: {in: [${ids}]}}) { nodes {id, method, block }}}`,
190180
variables: null,
191181
})
192-
.then((res) =>
193-
res.data?.data?.bridgeDispatchEvents?.nodes.map(({ id, ...rest }) => ({
194-
...rest,
195-
id: id.replace(dispatchLaneId, recordLaneId),
196-
}))
197-
);
182+
.then((res) => res.data?.data?.bridgeDispatchEvents?.nodes);
198183

199184
if (nodes && nodes.length > 0) {
200185
for (const node of nodes) {

subql/crab-parachain/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT LICENSE
2+
3+
Copyright 2020-2021 OnFinality Limited authors & contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

subql/crab-parachain/README.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# SubQuery - Starter Package
2+
3+
4+
The Starter Package is an example that you can use as a starting point for developing your SubQuery project.
5+
A SubQuery package defines which data The SubQuery will index from the Substrate blockchain, and how it will store it.
6+
7+
## Preparation
8+
9+
#### Environment
10+
11+
- [Typescript](https://www.typescriptlang.org/) are required to compile project and define types.
12+
13+
- Both SubQuery CLI and generated Project have dependencies and require [Node](https://nodejs.org/en/).
14+
15+
16+
#### Install the SubQuery CLI
17+
18+
Install SubQuery CLI globally on your terminal by using NPM:
19+
20+
```
21+
npm install -g @subql/cli
22+
```
23+
24+
Run help to see available commands and usage provide by CLI
25+
```
26+
subql help
27+
```
28+
29+
## Initialize the starter package
30+
31+
Inside the directory in which you want to create the SubQuery project, simply replace `project-name` with your project name and run the command:
32+
```
33+
subql init --starter project-name
34+
```
35+
Then you should see a folder with your project name has been created inside the directory, you can use this as the start point of your project. And the files should be identical as in the [Directory Structure](https://doc.subquery.network/directory_structure.html).
36+
37+
Last, under the project directory, run following command to install all the dependency.
38+
```
39+
yarn install
40+
```
41+
42+
43+
## Configure your project
44+
45+
In the starter package, we have provided a simple example of project configuration. You will be mainly working on the following files:
46+
47+
- The Manifest in `project.yaml`
48+
- The GraphQL Schema in `schema.graphql`
49+
- The Mapping functions in `src/mappings/` directory
50+
51+
For more information on how to write the SubQuery,
52+
check out our doc section on [Define the SubQuery](https://doc.subquery.network/define_a_subquery.html)
53+
54+
#### Code generation
55+
56+
In order to index your SubQuery project, it is mandatory to build your project first.
57+
Run this command under the project directory.
58+
59+
````
60+
yarn codegen
61+
````
62+
63+
## Build the project
64+
65+
In order to deploy your SubQuery project to our hosted service, it is mandatory to pack your configuration before upload.
66+
Run pack command from root directory of your project will automatically generate a `your-project-name.tgz` file.
67+
68+
```
69+
yarn build
70+
```
71+
72+
## Indexing and Query
73+
74+
#### Run required systems in docker
75+
76+
77+
Under the project directory run following command:
78+
79+
```
80+
docker-compose pull && docker-compose up
81+
```
82+
#### Query the project
83+
84+
Open your browser and head to `http://localhost:3000`.
85+
86+
Finally, you should see a GraphQL playground is showing in the explorer and the schemas that ready to query.
87+
88+
For the `subql-starter` project, you can try to query with the following code to get a taste of how it works.
89+
90+
````graphql
91+
{
92+
query{
93+
starterEntities(first:10){
94+
nodes{
95+
field1,
96+
field2,
97+
field3
98+
}
99+
}
100+
}
101+
}
102+
````
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
version: '3'
2+
3+
services:
4+
postgres:
5+
image: postgres:12-alpine
6+
ports:
7+
- 5432:5432
8+
volumes:
9+
- .data/postgres:/var/lib/postgresql/data
10+
environment:
11+
POSTGRES_PASSWORD: postgres
12+
healthcheck:
13+
test: ['CMD-SHELL', 'pg_isready -U postgres']
14+
interval: 5s
15+
timeout: 5s
16+
retries: 10
17+
18+
subquery-node:
19+
image: onfinality/subql-node:v0.27.2-0
20+
depends_on:
21+
'postgres':
22+
condition: service_healthy
23+
restart: always
24+
environment:
25+
DB_USER: postgres
26+
DB_PASS: postgres
27+
DB_DATABASE: postgres
28+
DB_HOST: postgres
29+
DB_PORT: 5432
30+
volumes:
31+
- ./:/app
32+
command:
33+
- -f=/app
34+
- --db-schema=app
35+
healthcheck:
36+
test: ['CMD', 'curl', '-f', 'http://subquery-node:3000/ready']
37+
interval: 3s
38+
timeout: 5s
39+
retries: 10
40+
41+
graphql-engine:
42+
image: onfinality/subql-query:v0.10.1-0
43+
ports:
44+
- 3000:3000
45+
depends_on:
46+
'postgres':
47+
condition: service_healthy
48+
'subquery-node':
49+
condition: service_healthy
50+
restart: always
51+
environment:
52+
DB_USER: postgres
53+
DB_PASS: postgres
54+
DB_DATABASE: postgres
55+
DB_HOST: postgres
56+
DB_PORT: 5432
57+
command:
58+
- --name=app
59+
- --playground
60+
- --indexer=http://subquery-node:3000

subql/crab-parachain/package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "crab-parachain",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "dist/index.js",
6+
"scripts": {
7+
"build": "tsc -b",
8+
"prepack": "rm -rf dist && npm build",
9+
"test": "jest",
10+
"start": "docker-compose pull && docker-compose up --remove-orphans",
11+
"codegen": "./node_modules/.bin/subql codegen"
12+
},
13+
"homepage": "https://github.com/subquery/subql-starter",
14+
"repository": "github:subquery/subql-starter",
15+
"resolutions": {
16+
"ipfs-unixfs": "6.0.6"
17+
},
18+
"files": [
19+
"dist",
20+
"schema.graphql",
21+
"project.yaml"
22+
],
23+
"author": "xiaoch05",
24+
"license": "MIT",
25+
"devDependencies": {
26+
"@polkadot/api": "^8",
27+
"@subql/types": "latest",
28+
"typescript": "^4.2.4",
29+
"@subql/cli": "latest"
30+
}
31+
}

subql/crab-parachain/project.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
specVersion: 0.2.0
2+
name: helix-crab-parachain
3+
version: 1.0.0
4+
description: ''
5+
repository: [email protected]:helix-bridge/indexer.git
6+
7+
schema:
8+
file: ./schema.graphql
9+
10+
network:
11+
genesisHash: '0xeac895d7768b17837a9c3a9f0280c01502c3ef40193df923490a0fa9c60ea076'
12+
endpoint: wss://crab-parachain-rpc.darwinia.network
13+
chaintypes:
14+
file: ./types.yaml
15+
16+
dataSources:
17+
- kind: substrate/Runtime
18+
startBlock: 535900
19+
mapping:
20+
file: ./dist/index.js
21+
handlers:
22+
- handler: handleEvent
23+
kind: substrate/EventHandler
24+
filter:
25+
module: bridgeCrabDispatch
26+
method: MessageVersionSpecMismatch
27+
28+
- handler: handleEvent
29+
kind: substrate/EventHandler
30+
filter:
31+
module: bridgeCrabDispatch
32+
method: MessageWeightMismatch
33+
34+
- handler: handleEvent
35+
kind: substrate/EventHandler
36+
filter:
37+
module: bridgeCrabDispatch
38+
method: MessageDispatched
39+
40+
- handler: handleEvent
41+
kind: substrate/EventHandler
42+
filter:
43+
module: bridgeCrabDispatch
44+
method: MessageCallValidateFailed
45+
46+
- handler: handleEvent
47+
kind: substrate/EventHandler
48+
filter:
49+
module: fromCrabIssuing
50+
method: TokenBurnAndRemoteUnlocked
51+
52+
- handler: handleEvent
53+
kind: substrate/EventHandler
54+
filter:
55+
module: fromCrabIssuing
56+
method: TokenUnlockedConfirmed
57+

0 commit comments

Comments
 (0)