Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Releases prior to 7.0 has been removed from this file to declutter search result

- database: Fix exception when creating connections with aiosqlite==0.22.0.
- evm.node: Retry JSON-RPC requests on "invalid block range params" error.
- substrate.subscan: Pass `X-API-Key` header when `api_key` is configured.

## [8.5.1] - 2025-11-03

Expand Down
4 changes: 2 additions & 2 deletions docs/3.datasources/9.substrate_subscan.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ To use this datasource, add the following section in config:
datasources:
subscan:
kind: substrate.subscan
url: ${ETHERSCAN_URL:-https://api.subscan.io/api}
api_key: ${ETHERSCAN_API_KEY:-''}
url: ${SUBSCAN_URL:-https://api.subscan.io/api}
api_key: ${SUBSCAN_API_KEY:-''}
```

During initialization, DipDup will use this datasource to fetch contract ABIs. If your config contains definitions for multiple networks, you can assign the datasource explicitly in `substrate.subsquid` index definitions:
Expand Down
1 change: 1 addition & 0 deletions src/demo_substrate_events/dipdup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ datasources:
subscan:
kind: substrate.subscan
url: https://assethub-polkadot.api.subscan.io/api
api_key: ${SUBSCAN_API_KEY:-}
node:
kind: substrate.node
url: https://statemint.api.onfinality.io/rpc?apikey=${ONFINALITY_API_KEY:-''}
Expand Down
7 changes: 7 additions & 0 deletions src/dipdup/datasources/substrate_subscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,24 @@ async def get_abi(self, address: str) -> AbiJson:
async def run(self) -> None:
pass

def _api_key_headers(self) -> dict[str, str]:
if self._config.api_key:
return {'X-API-Key': self._config.api_key}
return {}

async def get_runtime_list(self) -> list[dict[str, Any]]:
res = await self.request(
'post',
'scan/runtime/list',
headers=self._api_key_headers(),
)
return cast('list[dict[str, Any]]', res['data']['list'])

async def get_runtime_metadata(self, spec_version: int) -> list[dict[str, Any]]:
res = await self.request(
'post',
'scan/runtime/metadata',
headers=self._api_key_headers(),
json={'spec': spec_version},
)
return cast('list[dict[str, Any]]', res['data']['info']['metadata'])
1 change: 1 addition & 0 deletions src/dipdup/projects/demo_substrate_events/dipdup.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ datasources:
subscan:
kind: substrate.subscan
url: https://assethub-polkadot.api.subscan.io/api
api_key: ${SUBSCAN_API_KEY:-}
node:
kind: substrate.node
url: https://statemint.api.onfinality.io/rpc?apikey=${ONFINALITY_API_KEY:-''}
Expand Down
11 changes: 9 additions & 2 deletions src/dipdup/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from shutil import which
from typing import TYPE_CHECKING
from typing import Any
from typing import cast

from dipdup.config import DipDupConfig
from dipdup.config import HasuraConfig
Expand Down Expand Up @@ -98,7 +99,10 @@ async def run_postgres_container() -> PostgresDatabaseConfig:
)
atexit.register(postgres_container.stop)
postgres_container.reload()
postgres_ip = postgres_container.attrs['NetworkSettings']['IPAddress']

network_settings = postgres_container.attrs['NetworkSettings']
ip = network_settings.get('IPAddress') or next(iter(network_settings['Networks'].values()))['IPAddress']
postgres_ip = cast('str', ip)

while not postgres_container.exec_run('pg_isready').exit_code == 0:
await asyncio.sleep(0.1)
Expand Down Expand Up @@ -126,7 +130,10 @@ async def run_hasura_container(postgres_ip: str) -> HasuraConfig:
)
atexit.register(hasura_container.stop)
hasura_container.reload()
hasura_ip = hasura_container.attrs['NetworkSettings']['IPAddress']

network_settings = hasura_container.attrs['NetworkSettings']
ip = network_settings.get('IPAddress') or next(iter(network_settings['Networks'].values()))['IPAddress']
hasura_ip = cast('str', ip)

return HasuraConfig(
url=f'http://{hasura_ip}:8080',
Expand Down
1 change: 1 addition & 0 deletions tests/configs/common_substrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ datasources:
subscan:
kind: substrate.subscan
url: https://assethub-polkadot.api.subscan.io/api
api_key: ${SUBSCAN_API_KEY:-}
node:
kind: substrate.node
url: https://statemint.api.onfinality.io/rpc?apikey=${ONFINALITY_API_KEY:-''}
Expand Down
2 changes: 2 additions & 0 deletions tests/test_demos.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ async def test_run_init(
pytest.skip('Starknet tests require ALCHEMY_API_KEY environment variable')
if 'substrate' in config and not {'ONFINALITY_API_KEY'} <= set(os.environ):
pytest.skip('Substrate tests require ONFINALITY_API_KEY environment variable')
if 'substrate' in config and cmd == 'init' and not {'SUBSCAN_API_KEY'} <= set(os.environ):
pytest.skip('Substrate init tests require SUBSCAN_API_KEY environment variable')

async with AsyncExitStack() as stack:
tmp_package_path, env = await stack.enter_async_context(
Expand Down
Loading