-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from nadineloepfe/imports
topic info and message query
- Loading branch information
Showing
65 changed files
with
2,102 additions
and
340 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,4 +49,4 @@ jobs: | |
PUBLIC_KEY: ${{ steps.solo.outputs.publicKey }} | ||
NETWORK: solo | ||
run: | | ||
python test.py | ||
python test.py |
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 |
---|---|---|
|
@@ -24,3 +24,11 @@ src/hedera_sdk_python/hapi | |
|
||
# Mac OS X Files | ||
.DS_Store | ||
|
||
# Intellij | ||
.idea | ||
|
||
# Pytest | ||
.pytest_cache | ||
|
||
uv.lock |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import os | ||
from dotenv import load_dotenv | ||
from hedera_sdk_python.client.network import Network | ||
from hedera_sdk_python.client.client import Client | ||
from hedera_sdk_python.consensus.topic_id import TopicId | ||
from hedera_sdk_python.query.topic_info_query import TopicInfoQuery | ||
from hedera_sdk_python.account.account_id import AccountId | ||
from hedera_sdk_python.crypto.private_key import PrivateKey | ||
|
||
def query_topic_info(): | ||
operator_id = AccountId.from_string(os.getenv('OPERATOR_ID')) | ||
operator_key = PrivateKey.from_string(os.getenv('OPERATOR_KEY')) | ||
topic_id = TopicId.from_string(os.getenv('TOPIC_ID')) | ||
|
||
network = Network(network='testnet') | ||
client = Client(network) | ||
client.set_operator(operator_id, operator_key) | ||
|
||
query = TopicInfoQuery().set_topic_id(topic_id) | ||
|
||
topic_info = query.execute(client) | ||
print("Topic Info:", topic_info) | ||
|
||
if __name__ == "__main__": | ||
query_topic_info() |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import os | ||
import time | ||
from datetime import datetime | ||
from dotenv import load_dotenv | ||
|
||
from hedera_sdk_python.client.network import Network | ||
from hedera_sdk_python.client.client import Client | ||
from hedera_sdk_python.query.topic_message_query import TopicMessageQuery | ||
|
||
load_dotenv() | ||
|
||
def query_topic_messages(): | ||
network = Network(network='testnet') | ||
client = Client(network) | ||
|
||
def on_message_handler(topic_message): | ||
print(f"Received topic message: {topic_message}") | ||
|
||
def on_error_handler(e): | ||
print(f"Subscription error: {e}") | ||
if "Stream removed" in str(e): | ||
print("Reconnecting due to stream removal...") | ||
query_topic_messages() | ||
|
||
query = ( | ||
TopicMessageQuery() | ||
.set_topic_id(os.getenv('TOPIC_ID')) | ||
.set_start_time(datetime.utcnow()) | ||
.set_chunking_enabled(True) | ||
.set_limit(0) | ||
) | ||
|
||
query.subscribe( | ||
client, | ||
on_message=on_message_handler, | ||
on_error=on_error_handler | ||
) | ||
|
||
print("Subscription started. Waiting for messages...") | ||
while True: | ||
time.sleep(10) | ||
|
||
if __name__ == "__main__": | ||
query_topic_messages() |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os | ||
import sys | ||
from dotenv import load_dotenv | ||
|
||
from hedera_sdk_python.client.client import Client | ||
from hedera_sdk_python.account.account_id import AccountId | ||
from hedera_sdk_python.consensus.topic_id import TopicId | ||
from hedera_sdk_python.crypto.private_key import PrivateKey | ||
from hedera_sdk_python.client.network import Network | ||
from hedera_sdk_python.consensus.topic_delete_transaction import TopicDeleteTransaction | ||
|
||
load_dotenv() | ||
|
||
def delete_topic(): | ||
network = Network(network='testnet') | ||
client = Client(network) | ||
|
||
operator_id = AccountId.from_string(os.getenv('OPERATOR_ID')) | ||
operator_key = PrivateKey.from_string(os.getenv('OPERATOR_KEY')) | ||
topic_id = TopicId.from_string(os.getenv('TOPIC_ID')) | ||
|
||
client.set_operator(operator_id, operator_key) | ||
|
||
transaction = ( | ||
TopicDeleteTransaction(topic_id=topic_id) | ||
.freeze_with(client) | ||
.sign(operator_key) | ||
) | ||
|
||
try: | ||
receipt = transaction.execute(client) | ||
print(f"Topic {topic_id} deleted successfully.") | ||
except Exception as e: | ||
print(f"Topic deletion failed: {str(e)}") | ||
sys.exit(1) | ||
|
||
if __name__ == "__main__": | ||
delete_topic() |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os | ||
import sys | ||
from dotenv import load_dotenv | ||
|
||
from hedera_sdk_python.client.client import Client | ||
from hedera_sdk_python.account.account_id import AccountId | ||
from hedera_sdk_python.consensus.topic_id import TopicId | ||
from hedera_sdk_python.crypto.private_key import PrivateKey | ||
from hedera_sdk_python.client.network import Network | ||
from hedera_sdk_python.consensus.topic_message_submit_transaction import TopicMessageSubmitTransaction | ||
|
||
load_dotenv() | ||
|
||
def submit_message(message): | ||
network = Network(network='testnet') | ||
client = Client(network) | ||
|
||
operator_id = AccountId.from_string(os.getenv('OPERATOR_ID')) | ||
operator_key = PrivateKey.from_string(os.getenv('OPERATOR_KEY')) | ||
topic_id = TopicId.from_string(os.getenv('TOPIC_ID')) | ||
|
||
client.set_operator(operator_id, operator_key) | ||
|
||
transaction = ( | ||
TopicMessageSubmitTransaction(topic_id=topic_id, message=message) | ||
.freeze_with(client) | ||
.sign(operator_key) | ||
) | ||
|
||
try: | ||
receipt = transaction.execute(client) | ||
print(f"Message submitted to topic {topic_id}: {message}") | ||
except Exception as e: | ||
print(f"Message submission failed: {str(e)}") | ||
sys.exit(1) | ||
|
||
if __name__ == "__main__": | ||
submit_message("Hello, Hedera!") |
Oops, something went wrong.