Skip to content

Commit

Permalink
Update and modify files for the project
Browse files Browse the repository at this point in the history
- Updated files:
  - README.md
  - src/bee_py/bee.py
  • Loading branch information
Aviksaikat committed Jan 10, 2024
1 parent f24744f commit 28834de
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
- [✨ Features](#-features)
- [📋 Requirements](#-requirements)
- [🚀 Testing Locally](#-testing-locally)
- [🛠️ Installation](#%EF%B8%8F-installation)
- [🛠️ Installation](#-installation)
- [🚀 Usage](#-usage)
- [🐝 Bee Endpoint](#-bee-endpoint)
- [🚀 Bee Debug Endpoint](#-bee-debug-endpoint)
Expand Down Expand Up @@ -105,7 +105,7 @@ print(data)
>>> Data(data=b'Bee is Awesome!')

# Data can be converted into json format, hex, bytes or plain-text
print(data.json())
print(data.to_json())
>>> '{"data":"Bee is Awesome!"}'

print(data.text())
Expand Down
24 changes: 23 additions & 1 deletion src/bee_py/bee.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from time import sleep
from typing import Optional, Union

import websockets
Expand Down Expand Up @@ -1498,7 +1499,6 @@ def __upload(postage_batch_id: Union[str, BatchId], identifier: Identifier, data
signer=canonical_signer,
)

# TODO: Look into it
return SOCWriter(owner=reader.owner, download=reader.download, upload=__upload)

def check_connection(self, options: Optional[BeeRequestOptions] = None) -> None:
Expand Down Expand Up @@ -1536,6 +1536,28 @@ def is_connected(self, options: Optional[BeeRequestOptions] = None) -> bool:
return False
return True

def wait_for_usable_postage_stamp(self, batch_id: Union[BatchId, str], timeout: int = 120_000) -> None:
"""Waits for a postage stamp with the given batch ID to become usable.
Args:
batch_id: The ID of the postage batch to wait for.
timeout: The maximum time in milliseconds to wait before raising a timeout error.
Raises:
BeeError: If the timeout is reached before the stamp becomes usable.
"""

# * Check every 1.5 seconds
TIME_STEP = 1500 # noqa: N806
for _ in range(0, timeout, TIME_STEP):
stamp = self.get_postage_batch(batch_id)
if stamp.usable:
return
sleep(TIME_STEP / 1000)

msg = "Timeout on waiting for postage stamp to become usable"
raise BeeError(msg)

def create_postage_batch(
self,
amount: Union[NumberString, str],
Expand Down

0 comments on commit 28834de

Please sign in to comment.