Skip to content

Commit 5890846

Browse files
authored
Merge pull request #1427 from njgheorghita/ethpm-bugfix
[ethPM] Fix bug in package id and release id fetching strategy
2 parents e2c6fce + 3be068f commit 5890846

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

web3/pm.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
to_text,
2727
to_tuple,
2828
)
29-
from eth_utils.toolz import (
30-
concat,
31-
)
3229

3330
from ethpm import (
3431
ASSETS_DIR,
@@ -217,6 +214,9 @@ def deploy_new_instance(cls, w3):
217214
pass
218215

219216

217+
BATCH_SIZE = 100
218+
219+
220220
class SimpleRegistry(ERC1319Registry):
221221
"""
222222
This class represents an instance of the `Solidity Reference Registry implementation
@@ -245,29 +245,34 @@ def _get_package_name(self, package_id: bytes) -> str:
245245
@to_tuple
246246
def _get_all_package_ids(self) -> Iterable[Tuple[bytes]]:
247247
num_packages = self._num_package_ids()
248-
# Logic here b/c Solidity Reference Registry implementation returns ids in reverse order
249-
package_ids = [
250-
self.registry.functions.getAllPackageIds(index, (index + 4)).call()[0]
251-
for index in range(0, num_packages, 4)
252-
]
253-
for package_id in concat([x[::-1] for x in package_ids]):
254-
yield package_id
248+
pointer = 0
249+
while pointer < num_packages:
250+
new_ids, new_pointer = self.registry.functions.getAllPackageIds(
251+
pointer,
252+
(pointer + BATCH_SIZE)
253+
).call()
254+
if not new_pointer > pointer:
255+
break
256+
yield from reversed(new_ids)
257+
pointer = new_pointer
255258

256259
def _get_release_id(self, package_name: str, version: str) -> bytes:
257260
return self.registry.functions.getReleaseId(package_name, version).call()
258261

259262
@to_tuple
260263
def _get_all_release_ids(self, package_name: str) -> Iterable[Tuple[bytes]]:
261264
num_releases = self._num_release_ids(package_name)
262-
# Logic here b/c Solidity Reference Registry implementation returns ids in reverse order
263-
release_ids = [
264-
self.registry.functions.getAllReleaseIds(
265-
package_name, index, (index + 4)
266-
).call()[0]
267-
for index in range(0, num_releases, 4)
268-
]
269-
for release_id in concat([x[::-1] for x in release_ids]):
270-
yield release_id
265+
pointer = 0
266+
while pointer < num_releases:
267+
new_ids, new_pointer = self.registry.functions.getAllReleaseIds(
268+
package_name,
269+
pointer,
270+
(pointer + BATCH_SIZE)
271+
).call()
272+
if not new_pointer > pointer:
273+
break
274+
yield from reversed(new_ids)
275+
pointer = new_pointer
271276

272277
@to_tuple
273278
def _get_release_data(self, release_id: bytes) -> Iterable[Tuple[str]]:

0 commit comments

Comments
 (0)