-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update and modify files for the project
- Added new files: - tests/integration/feed/test_feed.py - Updated files: - src/bee_py/bee.py - src/bee_py/chunk/soc.py - src/bee_py/feed/feed.py - src/bee_py/feed/json.py - src/bee_py/feed/retrievable.py - src/bee_py/modules/bytes.py - src/bee_py/modules/feed.py - src/bee_py/types/type.py - src/bee_py/utils/reference.py - tests/conftest.py - tests/integration/chunk/conftest.py
- Loading branch information
1 parent
3ae90fe
commit 880f718
Showing
12 changed files
with
486 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,103 @@ | ||
# | ||
from ape.types import AddressType | ||
|
||
from bee_py.bee import Bee | ||
from bee_py.feed.feed import Index, get_feed_update_chunk_reference | ||
from bee_py.modules.bytes import read_big_endian | ||
from bee_py.types.type import BeeRequestOptions, Reference, Topic | ||
from bee_py.utils.hex import bytes_to_hex | ||
|
||
|
||
def make_numeric_index(index: Index): | ||
""" | ||
Converts an index to a numeric value. | ||
:param index: The index to convert. | ||
:type index: Index: Union[int, Epoch, bytes, str] | ||
:return: The numeric index. | ||
:rtype: int | ||
:raises TypeError: If the type of the index is unknown. | ||
""" | ||
if isinstance(index, bytes): | ||
return read_big_endian(index) | ||
|
||
if isinstance(index, str): | ||
return int(index) | ||
|
||
if isinstance(index, int): | ||
return index | ||
|
||
msg = "Unknown type of index!" | ||
raise TypeError(msg) | ||
|
||
|
||
def is_chunk_retrievable(bee: Bee, ref: Reference, request_options: BeeRequestOptions) -> bool: | ||
""" | ||
Checks whether a chunk is retrievable by attempting to download it. | ||
The `/stewardship/{reference}` endpoint does not support verifying chunks, only manifest references. | ||
Args: | ||
bee (Bee): The Bee client instance. | ||
ref (Reference): The chunk reference. | ||
request_options (BeeRequestOptions): The request options. | ||
Returns: | ||
bool: True if the chunk is retrievable, False otherwise. | ||
""" | ||
|
||
try: | ||
bee.download_chunk(ref, request_options) | ||
return True | ||
except Exception as e: | ||
if e.response.status_code == 404: # noqa: PLR2004 | ||
return False | ||
raise e | ||
|
||
|
||
def get_all_sequence_update_references(owner: AddressType, topic: Topic, index: Index) -> list[Reference]: | ||
""" | ||
Creates a list of references for all sequence updates chunk up to the given index. | ||
Creates an array of references for all sequence updates up to the given index. | ||
Args: | ||
owner (AddressType): The owner of the feed. | ||
topic (Topic): The topic of the feed. | ||
index (Index): The index of the last sequence update to include. | ||
Returns: | ||
list[Reference] | ||
""" | ||
num_index = make_numeric_index(index) | ||
update_references = [bytes_to_hex(get_feed_update_chunk_reference(owner, topic, i)) for i in range(num_index + 1)] | ||
|
||
return update_references | ||
|
||
|
||
def are_all_sequential_feeds_update_retrievable( | ||
bee: Bee, | ||
owner: AddressType, | ||
topic: Topic, | ||
index: Index, | ||
request_options: BeeRequestOptions, | ||
) -> bool: | ||
""" | ||
Checks whether all sequential feed updates up to the given index are retrievable. | ||
Args: | ||
bee (Bee): The Bee client instance. | ||
owner (AddressType): The owner of the feed. | ||
topic (Topic): The topic of the feed. | ||
index (Index): The index of the last sequence update to check. | ||
request_options (BeeRequestOptions): The request options. | ||
Returns: | ||
bool: True if all sequence updates are retrievable, False otherwise. | ||
""" | ||
|
||
chunk_retrievable_promises = [ | ||
is_chunk_retrievable(bee, ref, request_options) | ||
for ref in get_all_sequence_update_references(owner, topic, index) | ||
] | ||
|
||
return all(chunk_retrievable_promises) |
Oops, something went wrong.