Skip to content

Commit 0566e61

Browse files
Add subscription to big_map updates (#45)
1 parent dec5bab commit 0566e61

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

src/demo_tezos_domains_big_map/dipdup.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,19 @@ contracts:
99
edo_name_registry:
1010
address: KT1JJbWfW8CHUY95hG9iq2CEMma1RiKhMHDR
1111
typename: name_registry
12+
mainnet_name_registry:
13+
address: KT1GBZmSxmnKJXGMdMLbugPfLyUPmuLSMwKS
14+
typename: name_registry
1215

1316
datasources:
1417
tzkt_staging_edo:
1518
kind: tzkt
1619
url: ${TZKT_URL:-https://staging.api.edo2net.tzkt.io}
1720

21+
tzkt_staging_mainnet:
22+
kind: tzkt
23+
url: ${TZKT_URL:-https://staging.api.tzkt.io}
24+
1825
templates:
1926
tezos_domains_big_map:
2027
kind: big_map
@@ -33,3 +40,9 @@ indexes:
3340
values:
3441
datasource: tzkt_staging_edo
3542
name_registry: edo_name_registry
43+
44+
tezos_domains_big_map_mainnet:
45+
template: tezos_domains_big_map
46+
values:
47+
datasource: tzkt_staging_mainnet
48+
name_registry: mainnet_name_registry

src/dipdup/config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,10 @@ def __post_init_post_parse__(self):
565565

566566
elif isinstance(index_config, BigMapIndexConfig):
567567
if isinstance(index_config.datasource, str):
568-
index_config.datasource = self.datasources[index_config.datasource]
568+
try:
569+
index_config.datasource = self.datasources[index_config.datasource]
570+
except KeyError as e:
571+
raise ConfigurationError(f'Datasource `{index_config.datasource}` not found in `datasources` config section') from e
569572

570573
for handler in index_config.handlers:
571574
callback_patterns[handler.callback].append(handler.pattern)

src/dipdup/datasources/tzkt/datasource.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,7 @@ async def on_connect(self):
330330
for address, types in self._operation_subscriptions.items():
331331
await self.subscribe_to_operations(address, types)
332332
for address, paths in self._big_map_subscriptions.items():
333-
for path in paths:
334-
await self.subscribe_to_big_maps(address, paths)
333+
await self.subscribe_to_big_maps(address, paths)
335334

336335
def on_error(self, message: CompletionMessage):
337336
raise Exception(message.error)
@@ -352,8 +351,22 @@ async def subscribe_to_operations(self, address: str, types: List[OperationType]
352351
],
353352
)
354353

355-
async def subscribe_to_big_maps(self, address: Address, path: Path) -> None:
356-
self._logger.info('Subscribing to %s, %s', address, path)
354+
async def subscribe_to_big_maps(self, address: Address, paths: List[Path]) -> None:
355+
self._logger.info('Subscribing to big map updates of %s, %s', address, paths)
356+
357+
while self._get_client().transport.state != ConnectionState.connected:
358+
await asyncio.sleep(0.1)
359+
360+
for path in paths:
361+
await self._get_client().send(
362+
'SubscribeToBigMaps',
363+
[
364+
{
365+
'address': address,
366+
'path': path,
367+
}
368+
],
369+
)
357370

358371
async def fetch_operations(self, index_config: OperationIndexConfig, last_level: int) -> None:
359372
self._logger.info('Fetching operations prior to level %s', last_level)
@@ -561,7 +574,7 @@ async def add_operation_subscription(self, address: str, types: Optional[List[Op
561574
async def add_big_map_subscription(self, address: str, path: str) -> None:
562575
if address not in self._big_map_subscriptions:
563576
self._big_map_subscriptions[address] = []
564-
self._big_map_subscriptions[address].append('path')
577+
self._big_map_subscriptions[address].append(path)
565578

566579
async def on_operation_match(
567580
self,

0 commit comments

Comments
 (0)