From 52a68bdfbad378c33de143181aca4edd70eba0b8 Mon Sep 17 00:00:00 2001 From: George Danezis Date: Thu, 6 Jun 2024 12:13:26 +0100 Subject: [PATCH] Clean up and system object script --- .gitignore | 4 ++ examples/CONFIG/config_dir/client_config.yaml | 34 ++++++++++++++ examples/python/hello_walrus_jsonapi.py | 2 +- examples/python/hello_walrus_sui_system.py | 45 +++++++++++++++++++ examples/python/hello_walrus_webapi.py | 2 +- 5 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 examples/CONFIG/config_dir/client_config.yaml create mode 100644 examples/python/hello_walrus_sui_system.py diff --git a/.gitignore b/.gitignore index 750e099..0e83442 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,10 @@ # mdBook build/ +# Python +__pycache__/ +*.pyc + # Misc *.key .env diff --git a/examples/CONFIG/config_dir/client_config.yaml b/examples/CONFIG/config_dir/client_config.yaml new file mode 100644 index 0000000..85393f0 --- /dev/null +++ b/examples/CONFIG/config_dir/client_config.yaml @@ -0,0 +1,34 @@ +system_pkg: 0x17108fb344dbea0d315e6f44cdd3af12a028cd568bafcbfb7f7a7b152719d15d +system_object: 0x3fb18e675ad41158f59acbdb7f574136a198cbd83be9b968c0fdeaa139c312f9 +wallet_config: null + +# Default values for the client are commented out. +# +# There is no risk in playing aroud with these values. +# Worst case, you may not be able to store/read from Walrus. + +# communication_config: +# max_concurrent_writes: null +# max_concurrent_sliver_reads: null +# max_concurrent_metadata_reads: 3 +# reqwest_config: +# total_timeout: +# secs: 180 +# nanos: 0 +# pool_idle_timeout: null +# http2_keep_alive_timeout: +# secs: 5 +# nanos: 0 +# http2_keep_alive_interval: +# secs: 30 +# nanos: 0 +# http2_keep_alive_while_idle: true +# request_rate_config: +# max_node_connections: 10 +# max_retries: 5 +# min_backoff: +# secs: 2 +# nanos: 0 +# max_backoff: +# secs: 60 +# nanos: 0 diff --git a/examples/python/hello_walrus_jsonapi.py b/examples/python/hello_walrus_jsonapi.py index ec0f28e..a52b795 100644 --- a/examples/python/hello_walrus_jsonapi.py +++ b/examples/python/hello_walrus_jsonapi.py @@ -24,7 +24,7 @@ from utils import num_to_blob_id PATH_TO_WALRUS = "../CONFIG/bin/walrus" -PATH_TO_WALRUS_CONFIG = "../CONFIG/working_dir/client_config.yaml" +PATH_TO_WALRUS_CONFIG = "../CONFIG/config_dir/client_config.yaml" try: diff --git a/examples/python/hello_walrus_sui_system.py b/examples/python/hello_walrus_sui_system.py new file mode 100644 index 0000000..bab048d --- /dev/null +++ b/examples/python/hello_walrus_sui_system.py @@ -0,0 +1,45 @@ +# Example of querying the Walrus system object on Sui +# +# Prerequisites: +# +# - Configure Walrus +# see: TODO +# +# - Update the paths PATH_TO_WALRUS_CONFIG below +# + +# Std lib imports +import requests +import re + +PATH_TO_WALRUS_CONFIG = "../CONFIG/config_dir/client_config.yaml" + +system_object_id = re.findall(r"system_object:[ ]*(.*)", open(PATH_TO_WALRUS_CONFIG).read())[0] +print(f'System object ID: {system_object_id}') + # Part 3. Check the availability of the blob +request = { +"jsonrpc": "2.0", +"id": 1, +"method": "sui_getObject", +"params": [ + system_object_id, + { + "showType": True, + "showOwner": False, + "showPreviousTransaction": True, + "showDisplay": False, + "showContent": True, + "showBcs": False, + "showStorageRebate": False + } +] +} +response = requests.post("https://fullnode.testnet.sui.io:443", json=request) +system_object_content = response.json()["result"]["data"]["content"]["fields"] +committee = system_object_content["current_committee"]["fields"]["bls_committee"]["fields"] + +print(f'Current walrus epoch: {system_object_content["current_committee"]["fields"]["epoch"]}') +print(f'Number of members: {len(committee["members"])} Number of shards: {committee["n_shards"]}') +print(f'Price per unit size: {system_object_content["price_per_unit_size"]} MIST') +print(f'Total capacity size: {system_object_content["total_capacity_size"]} bytes') +print(f'Used capacity size: {system_object_content["used_capacity_size"]} bytes') \ No newline at end of file diff --git a/examples/python/hello_walrus_webapi.py b/examples/python/hello_walrus_webapi.py index 680a2fd..2258260 100644 --- a/examples/python/hello_walrus_webapi.py +++ b/examples/python/hello_walrus_webapi.py @@ -10,7 +10,7 @@ # see: TODO # # - Run the Walrus client in daemon mode: -# $ walrus --config working_dir/client_config.yaml daemon -b 127.0.0.1:8899 +# $ walrus --config config_dir/client_config.yaml daemon -b 127.0.0.1:8899 # # Std lib imports