Skip to content

Commit e7d992c

Browse files
authored
Merge pull request #4 from ideal-lab5/cm/idn-indexer-setup
Focus indexer on Ideal Network
2 parents 9ef45b8 + 10ca464 commit e7d992c

File tree

28 files changed

+133
-908
lines changed

28 files changed

+133
-908
lines changed

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"rust-analyzer.rustfmt.extraArgs": ["+nightly"],
4+
"rust-analyzer.checkOnSave.command": "clippy"
5+
}

Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
resolver = "2"
33

44
members = [
5-
"polkadot-metadata",
6-
"kusama-metadata",
7-
"rococo-metadata",
8-
"westend-metadata",
9-
"ideal-network-local-metadata",
5+
"ideal-metadata",
106
"indexer",
117
]

README.md

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@ Event indexer for the Ideal Network.
88

99
IDN Indexer uses the [Hybrid Indexer](https://github.com/hybrid-explorer/hybrid-indexer) Rust library. It can be accessed using [Hybrid Dapp](https://github.com/hybrid-explorer/hybrid-dapp).
1010

11+
## Configuration
12+
13+
The indexer requires two key configuration values that can be set via environment variables:
14+
15+
- `IDN_GENESIS_HASH`: The genesis hash of your Ideal Network chain (hex format without 0x prefix)
16+
- `IDN_WS_URL`: WebSocket URL of your Ideal Network node
17+
18+
Example configuration:
19+
```sh
20+
export IDN_GENESIS_HASH="af97825bf72091072a08b9dbff88d6664e2061bcb4e28a90f17bd85572d8f8ae"
21+
export IDN_WS_URL="ws://127.0.0.1:1234"
22+
```
23+
24+
If not set, the indexer will use default values suitable for local development.
25+
1126
## Building
1227

1328
Ideal Network Indexer can be built using `cargo build`, however it is necessary to use the nightly `rustc`.
@@ -25,11 +40,14 @@ Compiling `metadata` can take a very long time.
2540
Usage: ideal-indexer [OPTIONS]
2641
2742
Options:
28-
-c, --chain <CHAIN> Chain to index [default: ideal] [possible values: ideal,polkadot, kusama, rococo, westend]
43+
-c, --chain <CHAIN> Chain to index [default: ideal]
2944
-d, --db-path <DB_PATH> Database path
3045
-u, --url <URL> URL of Substrate node to connect to
3146
-b, --block-number <BLOCK_NUMBER> Block number to start indexing from
47+
--db-mode <DB_MODE> Database mode [default: lowspace] [possible values: lowspace, highthroughput]
48+
--db-cache-capacity <SIZE> Maximum size in bytes for the system page cache [default: 1024.00 MiB]
3249
--queue-depth <QUEUE_DEPTH> Maximum number of concurrent requests to the chain [default: 64]
50+
-i, --index-variant Index event variants
3351
-p, --port <PORT> Port to open for WebSocket queries [default: 8172]
3452
-v, --verbose... More output per occurrence
3553
-q, --quiet... Less output per occurrence
@@ -45,24 +63,10 @@ First build the docker image:
4563
docker build .
4664
```
4765

48-
Run the docker image for each chain in a separate tab (replace `[image_hash]` with the hash of the docker image displayed at the end of the build):
49-
50-
```sh
51-
docker run --rm -p 8172:8172 [image_hash] -c ideal -b 16730000 -p 8172
52-
```
53-
54-
```sh
55-
docker run --rm -p 8172:8172 [image_hash] -c polkadot -b 16730000 -p 8172
56-
```
66+
Run the docker image:
5767

5868
```sh
59-
docker run --rm -p 8172:8172 [image_hash] -c kusama -b 16730000 -p 8172
60-
```
61-
62-
```sh
63-
docker run --rm -p 8174:8174 [image_hash] -c rococo -b 6550000 -p 8174
64-
```
65-
66-
```sh
67-
docker run --rm -p 8175:8175 [image_hash] -c westend -b 16940000 -p 8175
68-
```
69+
docker run --rm -p 8172:8172 \
70+
-e IDN_GENESIS_HASH="your_genesis_hash_here" \
71+
-e IDN_WS_URL="ws://your.node.url:port" \
72+
[image_hash] -p 8172

ideal-network-local-metadata/Cargo.toml renamed to ideal-metadata/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "ideal-network-local-metadata"
2+
name = "ideal-metadata"
33
version = "0.1.0"
44
edition = "2021"
55

File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#[subxt::subxt(runtime_metadata_path = "ideal.scale")]
2-
pub mod ideal_network_local_metadata {}
2+
pub mod ideal_metadata {}

indexer/Cargo.toml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
[package]
2-
name = "acuity-index-polkadot"
3-
version = "0.2.2"
2+
name = "acuity-index-ideal"
3+
version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
polkadot-metadata = { path = "../polkadot-metadata" }
8-
kusama-metadata = { path = "../kusama-metadata" }
9-
rococo-metadata = { path = "../rococo-metadata" }
10-
westend-metadata = { path = "../westend-metadata" }
11-
ideal-network-local-metadata = { path = "../ideal-network-local-metadata" }
12-
tokio = { version = "1.28.2", features = ["macros", "rt", "rt-multi-thread"] }
13-
subxt = "0.35.3"
14-
clap = { version = "4.3.19", features = ["derive"] }
15-
hex-literal = "0.4.1"
16-
clap-verbosity-flag = "2.0.1"
17-
sled = { version = "0.34.7", default-features = false }
7+
ideal-metadata = { path = "../ideal-metadata" }
8+
acuity-index-substrate = { git = "https://github.com/ideal-lab5/idn-acuity-index-substrate", version = "=0.6.2" }
189
byte-unit = "4.0.19"
19-
serde = { version = "1.0.162", features = ["derive"] }
20-
zerocopy = "0.7.8"
10+
clap = { version = "4.5.1", features = ["derive"] }
11+
clap-verbosity-flag = "2.2.0"
12+
serde = { version = "1.0.130", features = ["derive"] }
13+
serde_json = "1.0.68"
14+
sled = "0.34.7"
15+
subxt = "0.35.3"
16+
tokio = { version = "1.35.1", features = ["full"] }
17+
tracing = "0.1.40"
2118
tracing-log = "0.2.0"
22-
acuity-index-substrate = { git = "https://github.com/ideal-lab5/idn-acuity-index-substrate", version = "=0.6.2" }
19+
zerocopy = "0.7.32"
20+
hex = "0.4.3"
21+
hex-literal = "0.4.1"
22+
lazy_static = "1.4.0"

indexer/src/config.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use lazy_static::lazy_static;
2+
use std::env;
3+
4+
lazy_static! {
5+
pub static ref GENESIS_HASH: [u8; 32] = {
6+
let hash = env::var("IDN_GENESIS_HASH").unwrap_or_else(|_| {
7+
"af97825bf72091072a08b9dbff88d6664e2061bcb4e28a90f17bd85572d8f8ae".to_string()
8+
});
9+
let mut bytes = [0u8; 32];
10+
hex::decode_to_slice(hash, &mut bytes)
11+
.expect("Invalid genesis hash format in IDN_GENESIS_HASH");
12+
bytes
13+
};
14+
pub static ref DEFAULT_URL: String =
15+
env::var("IDN_WS_URL").unwrap_or_else(|_| "ws://127.0.0.1:1234".to_string());
16+
}

indexer/src/ideal.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use ideal_network_local_metadata::ideal_network_local_metadata::{
1+
use ideal_metadata::ideal_metadata::{
22
runtime_types::{
33
frame_system::pallet::Event as SystemEvent,
44
pallet_balances::pallet::Event as BalancesEvent,
@@ -7,9 +7,11 @@ use ideal_network_local_metadata::ideal_network_local_metadata::{
77
Event,
88
};
99

10-
use crate::*;
10+
use crate::{
11+
config::{DEFAULT_URL, GENESIS_HASH},
12+
*,
13+
};
1114
use acuity_index_substrate::*;
12-
use hex_literal::hex;
1315

1416
pub struct IdealIndexer;
1517

@@ -22,16 +24,15 @@ impl acuity_index_substrate::shared::RuntimeIndexer for IdealIndexer {
2224
}
2325

2426
fn get_genesis_hash() -> <Self::RuntimeConfig as subxt::Config>::Hash {
25-
// Replace with your chain's genesis hash
26-
hex!["af97825bf72091072a08b9dbff88d6664e2061bcb4e28a90f17bd85572d8f8ae"].into() // Temporary placeholder
27+
(*GENESIS_HASH).into()
2728
}
2829

2930
fn get_versions() -> &'static [u32] {
3031
&[0]
3132
}
3233

3334
fn get_default_url() -> &'static str {
34-
"ws://127.0.0.1:1234" // Replace with your actual endpoint
35+
&DEFAULT_URL
3536
}
3637

3738
fn process_event(

indexer/src/kusama.rs

Lines changed: 0 additions & 188 deletions
This file was deleted.

0 commit comments

Comments
 (0)