2022-09-30 11:40:22 +03:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2022-01-30 14:25:30 +03:00
|
|
|
from decimal import Decimal
|
2022-05-24 15:24:56 +03:00
|
|
|
from pathlib import Path
|
2022-10-20 01:02:05 +03:00
|
|
|
from typing import Dict, List, Optional
|
2021-09-29 02:37:50 +03:00
|
|
|
|
2022-10-20 01:02:05 +03:00
|
|
|
from chia.cmds.cmds_util import get_any_service_client
|
2022-01-30 14:25:30 +03:00
|
|
|
from chia.cmds.units import units
|
2023-02-28 08:49:47 +03:00
|
|
|
from chia.rpc.data_layer_rpc_client import DataLayerRpcClient
|
2021-09-29 02:37:50 +03:00
|
|
|
from chia.types.blockchain_format.sized_bytes import bytes32
|
|
|
|
from chia.util.byte_types import hexstr_to_bytes
|
2022-10-20 01:02:05 +03:00
|
|
|
from chia.util.ints import uint64
|
2021-10-01 16:41:08 +03:00
|
|
|
|
|
|
|
|
2022-01-30 14:25:30 +03:00
|
|
|
async def create_data_store_cmd(rpc_port: Optional[int], fee: Optional[str]) -> None:
|
2022-10-20 01:02:05 +03:00
|
|
|
final_fee = None if fee is None else uint64(int(Decimal(fee) * units["chia"]))
|
2023-02-28 08:49:47 +03:00
|
|
|
async with get_any_service_client(DataLayerRpcClient, rpc_port) as (client, _, _):
|
2022-10-20 01:02:05 +03:00
|
|
|
if client is not None:
|
2022-01-30 14:25:30 +03:00
|
|
|
res = await client.create_data_store(fee=final_fee)
|
2022-01-26 18:38:26 +03:00
|
|
|
print(res)
|
2021-09-29 02:37:50 +03:00
|
|
|
|
|
|
|
|
2022-09-24 03:43:04 +03:00
|
|
|
async def get_value_cmd(rpc_port: Optional[int], store_id: str, key: str, root_hash: Optional[str]) -> None:
|
2022-01-26 13:03:33 +03:00
|
|
|
store_id_bytes = bytes32.from_hexstr(store_id)
|
2021-10-11 17:30:41 +03:00
|
|
|
key_bytes = hexstr_to_bytes(key)
|
2022-09-24 03:43:04 +03:00
|
|
|
root_hash_bytes = None if root_hash is None else bytes32.from_hexstr(root_hash)
|
2023-02-28 08:49:47 +03:00
|
|
|
async with get_any_service_client(DataLayerRpcClient, rpc_port) as (client, _, _):
|
2022-10-20 01:02:05 +03:00
|
|
|
if client is not None:
|
2022-09-24 03:43:04 +03:00
|
|
|
res = await client.get_value(store_id=store_id_bytes, key=key_bytes, root_hash=root_hash_bytes)
|
2022-01-26 18:38:26 +03:00
|
|
|
print(res)
|
2021-09-29 02:37:50 +03:00
|
|
|
|
|
|
|
|
2022-01-14 18:58:26 +03:00
|
|
|
async def update_data_store_cmd(
|
2021-12-09 20:13:48 +03:00
|
|
|
rpc_port: Optional[int],
|
2022-01-21 15:54:12 +03:00
|
|
|
store_id: str,
|
2022-06-09 22:07:22 +03:00
|
|
|
changelist: List[Dict[str, str]],
|
2022-01-30 14:25:30 +03:00
|
|
|
fee: Optional[str],
|
2022-01-26 18:38:26 +03:00
|
|
|
) -> None:
|
2022-01-26 13:03:33 +03:00
|
|
|
store_id_bytes = bytes32.from_hexstr(store_id)
|
2022-10-20 01:02:05 +03:00
|
|
|
final_fee = None if fee is None else uint64(int(Decimal(fee) * units["chia"]))
|
2023-02-28 08:49:47 +03:00
|
|
|
async with get_any_service_client(DataLayerRpcClient, rpc_port) as (client, _, _):
|
2022-10-20 01:02:05 +03:00
|
|
|
if client is not None:
|
2022-01-30 14:25:30 +03:00
|
|
|
res = await client.update_data_store(store_id=store_id_bytes, changelist=changelist, fee=final_fee)
|
2022-01-26 18:38:26 +03:00
|
|
|
print(res)
|
2022-01-14 18:58:26 +03:00
|
|
|
|
2021-09-29 02:37:50 +03:00
|
|
|
|
2022-07-26 16:14:45 +03:00
|
|
|
async def get_keys_cmd(
|
|
|
|
rpc_port: Optional[int],
|
|
|
|
store_id: str,
|
2022-09-24 03:43:04 +03:00
|
|
|
root_hash: Optional[str],
|
2022-07-26 16:14:45 +03:00
|
|
|
) -> None:
|
|
|
|
store_id_bytes = bytes32.from_hexstr(store_id)
|
2022-09-24 03:43:04 +03:00
|
|
|
root_hash_bytes = None if root_hash is None else bytes32.from_hexstr(root_hash)
|
2023-02-28 08:49:47 +03:00
|
|
|
async with get_any_service_client(DataLayerRpcClient, rpc_port) as (client, _, _):
|
2022-10-20 01:02:05 +03:00
|
|
|
if client is not None:
|
2022-09-24 03:43:04 +03:00
|
|
|
res = await client.get_keys(store_id=store_id_bytes, root_hash=root_hash_bytes)
|
2022-07-26 16:14:45 +03:00
|
|
|
print(res)
|
|
|
|
|
|
|
|
|
2022-01-21 15:54:12 +03:00
|
|
|
async def get_keys_values_cmd(
|
|
|
|
rpc_port: Optional[int],
|
|
|
|
store_id: str,
|
2022-09-24 03:43:04 +03:00
|
|
|
root_hash: Optional[str],
|
2022-01-26 18:38:26 +03:00
|
|
|
) -> None:
|
2022-01-26 13:03:33 +03:00
|
|
|
store_id_bytes = bytes32.from_hexstr(store_id)
|
2022-09-24 03:43:04 +03:00
|
|
|
root_hash_bytes = None if root_hash is None else bytes32.from_hexstr(root_hash)
|
2023-02-28 08:49:47 +03:00
|
|
|
async with get_any_service_client(DataLayerRpcClient, rpc_port) as (client, _, _):
|
2022-10-20 01:02:05 +03:00
|
|
|
if client is not None:
|
2022-09-24 03:43:04 +03:00
|
|
|
res = await client.get_keys_values(store_id=store_id_bytes, root_hash=root_hash_bytes)
|
2022-01-26 18:38:26 +03:00
|
|
|
print(res)
|
2022-01-21 15:54:12 +03:00
|
|
|
|
|
|
|
|
2022-01-14 18:58:26 +03:00
|
|
|
async def get_root_cmd(
|
|
|
|
rpc_port: Optional[int],
|
2022-01-21 15:54:12 +03:00
|
|
|
store_id: str,
|
2022-01-26 18:38:26 +03:00
|
|
|
) -> None:
|
2022-01-26 13:03:33 +03:00
|
|
|
store_id_bytes = bytes32.from_hexstr(store_id)
|
2023-02-28 08:49:47 +03:00
|
|
|
async with get_any_service_client(DataLayerRpcClient, rpc_port) as (client, _, _):
|
2022-10-20 01:02:05 +03:00
|
|
|
if client is not None:
|
2022-01-26 18:38:26 +03:00
|
|
|
res = await client.get_root(store_id=store_id_bytes)
|
|
|
|
print(res)
|
2022-01-30 18:09:09 +03:00
|
|
|
|
|
|
|
|
|
|
|
async def subscribe_cmd(
|
|
|
|
rpc_port: Optional[int],
|
|
|
|
store_id: str,
|
2022-06-08 20:25:09 +03:00
|
|
|
urls: List[str],
|
2022-01-30 18:09:09 +03:00
|
|
|
) -> None:
|
|
|
|
store_id_bytes = bytes32.from_hexstr(store_id)
|
2023-02-28 08:49:47 +03:00
|
|
|
async with get_any_service_client(DataLayerRpcClient, rpc_port) as (client, _, _):
|
2022-10-20 01:02:05 +03:00
|
|
|
if client is not None:
|
2022-08-31 19:34:11 +03:00
|
|
|
res = await client.subscribe(store_id=store_id_bytes, urls=urls)
|
|
|
|
print(res)
|
2022-01-30 18:09:09 +03:00
|
|
|
|
|
|
|
|
|
|
|
async def unsubscribe_cmd(
|
|
|
|
rpc_port: Optional[int],
|
|
|
|
store_id: str,
|
|
|
|
) -> None:
|
|
|
|
store_id_bytes = bytes32.from_hexstr(store_id)
|
2023-02-28 08:49:47 +03:00
|
|
|
async with get_any_service_client(DataLayerRpcClient, rpc_port) as (client, _, _):
|
2022-10-20 01:02:05 +03:00
|
|
|
if client is not None:
|
2022-08-31 19:34:11 +03:00
|
|
|
res = await client.unsubscribe(store_id=store_id_bytes)
|
|
|
|
print(res)
|
2022-02-18 16:26:16 +03:00
|
|
|
|
|
|
|
|
2022-07-28 18:47:15 +03:00
|
|
|
async def remove_subscriptions_cmd(
|
|
|
|
rpc_port: Optional[int],
|
|
|
|
store_id: str,
|
|
|
|
urls: List[str],
|
|
|
|
) -> None:
|
|
|
|
store_id_bytes = bytes32.from_hexstr(store_id)
|
2023-02-28 08:49:47 +03:00
|
|
|
async with get_any_service_client(DataLayerRpcClient, rpc_port) as (client, _, _):
|
2022-10-20 01:02:05 +03:00
|
|
|
if client is not None:
|
2022-08-31 19:34:11 +03:00
|
|
|
res = await client.remove_subscriptions(store_id=store_id_bytes, urls=urls)
|
|
|
|
print(res)
|
2022-07-28 18:47:15 +03:00
|
|
|
|
|
|
|
|
2022-02-18 16:26:16 +03:00
|
|
|
async def get_kv_diff_cmd(
|
|
|
|
rpc_port: Optional[int],
|
|
|
|
store_id: str,
|
|
|
|
hash_1: str,
|
|
|
|
hash_2: str,
|
|
|
|
) -> None:
|
|
|
|
store_id_bytes = bytes32.from_hexstr(store_id)
|
|
|
|
hash_1_bytes = bytes32.from_hexstr(hash_1)
|
|
|
|
hash_2_bytes = bytes32.from_hexstr(hash_2)
|
2023-02-28 08:49:47 +03:00
|
|
|
async with get_any_service_client(DataLayerRpcClient, rpc_port) as (client, _, _):
|
2022-10-20 01:02:05 +03:00
|
|
|
if client is not None:
|
2022-02-18 17:44:39 +03:00
|
|
|
res = await client.get_kv_diff(store_id=store_id_bytes, hash_1=hash_1_bytes, hash_2=hash_2_bytes)
|
|
|
|
print(res)
|
|
|
|
|
|
|
|
|
|
|
|
async def get_root_history_cmd(
|
|
|
|
rpc_port: Optional[int],
|
|
|
|
store_id: str,
|
|
|
|
) -> None:
|
|
|
|
store_id_bytes = bytes32.from_hexstr(store_id)
|
2023-02-28 08:49:47 +03:00
|
|
|
async with get_any_service_client(DataLayerRpcClient, rpc_port) as (client, _, _):
|
2022-10-20 01:02:05 +03:00
|
|
|
if client is not None:
|
2022-02-18 17:44:39 +03:00
|
|
|
res = await client.get_root_history(store_id=store_id_bytes)
|
|
|
|
print(res)
|
2022-05-11 21:59:11 +03:00
|
|
|
|
|
|
|
|
2022-05-24 15:24:56 +03:00
|
|
|
async def add_missing_files_cmd(
|
2022-08-30 10:59:13 +03:00
|
|
|
rpc_port: Optional[int], ids: Optional[List[str]], overwrite: bool, foldername: Optional[Path]
|
2022-05-24 15:24:56 +03:00
|
|
|
) -> None:
|
2023-02-28 08:49:47 +03:00
|
|
|
async with get_any_service_client(DataLayerRpcClient, rpc_port) as (client, _, _):
|
2022-10-20 01:02:05 +03:00
|
|
|
if client is not None:
|
2022-08-31 19:34:11 +03:00
|
|
|
res = await client.add_missing_files(
|
2022-05-24 15:24:56 +03:00
|
|
|
store_ids=(None if ids is None else [bytes32.from_hexstr(id) for id in ids]),
|
2022-08-30 10:59:13 +03:00
|
|
|
overwrite=overwrite,
|
2022-05-24 15:24:56 +03:00
|
|
|
foldername=foldername,
|
2022-05-11 21:59:11 +03:00
|
|
|
)
|
2022-08-31 19:34:11 +03:00
|
|
|
print(res)
|
2022-08-09 22:24:54 +03:00
|
|
|
|
|
|
|
|
2022-08-10 02:30:46 +03:00
|
|
|
async def add_mirror_cmd(
|
|
|
|
rpc_port: Optional[int], store_id: str, urls: List[str], amount: int, fee: Optional[str]
|
|
|
|
) -> None:
|
2022-10-20 01:02:05 +03:00
|
|
|
store_id_bytes = bytes32.from_hexstr(store_id)
|
|
|
|
final_fee = None if fee is None else uint64(int(Decimal(fee) * units["chia"]))
|
2023-02-28 08:49:47 +03:00
|
|
|
async with get_any_service_client(DataLayerRpcClient, rpc_port) as (client, _, _):
|
2022-10-20 01:02:05 +03:00
|
|
|
if client is not None:
|
2022-08-31 19:34:11 +03:00
|
|
|
res = await client.add_mirror(
|
2022-08-09 22:24:54 +03:00
|
|
|
store_id=store_id_bytes,
|
|
|
|
urls=urls,
|
|
|
|
amount=amount,
|
|
|
|
fee=final_fee,
|
|
|
|
)
|
2022-08-31 19:34:11 +03:00
|
|
|
print(res)
|
2022-08-09 22:24:54 +03:00
|
|
|
|
|
|
|
|
2022-08-10 02:30:46 +03:00
|
|
|
async def delete_mirror_cmd(rpc_port: Optional[int], coin_id: str, fee: Optional[str]) -> None:
|
2022-10-20 01:02:05 +03:00
|
|
|
coin_id_bytes = bytes32.from_hexstr(coin_id)
|
|
|
|
final_fee = None if fee is None else uint64(int(Decimal(fee) * units["chia"]))
|
2023-02-28 08:49:47 +03:00
|
|
|
async with get_any_service_client(DataLayerRpcClient, rpc_port) as (client, _, _):
|
2022-10-20 01:02:05 +03:00
|
|
|
if client is not None:
|
2022-08-31 19:34:11 +03:00
|
|
|
res = await client.delete_mirror(
|
2022-08-09 22:34:53 +03:00
|
|
|
coin_id=coin_id_bytes,
|
2022-08-09 22:24:54 +03:00
|
|
|
fee=final_fee,
|
|
|
|
)
|
2022-08-31 19:34:11 +03:00
|
|
|
print(res)
|
2022-08-09 22:24:54 +03:00
|
|
|
|
|
|
|
|
2022-08-10 02:30:46 +03:00
|
|
|
async def get_mirrors_cmd(rpc_port: Optional[int], store_id: str) -> None:
|
2022-10-20 01:02:05 +03:00
|
|
|
store_id_bytes = bytes32.from_hexstr(store_id)
|
2023-02-28 08:49:47 +03:00
|
|
|
async with get_any_service_client(DataLayerRpcClient, rpc_port) as (client, _, _):
|
2022-10-20 01:02:05 +03:00
|
|
|
if client is not None:
|
2022-08-09 22:24:54 +03:00
|
|
|
res = await client.get_mirrors(store_id=store_id_bytes)
|
|
|
|
print(res)
|
2022-08-25 15:17:08 +03:00
|
|
|
|
|
|
|
|
|
|
|
async def get_subscriptions_cmd(rpc_port: Optional[int]) -> None:
|
2023-02-28 08:49:47 +03:00
|
|
|
async with get_any_service_client(DataLayerRpcClient, rpc_port) as (client, _, _):
|
2022-10-20 01:02:05 +03:00
|
|
|
if client is not None:
|
2022-08-25 15:17:08 +03:00
|
|
|
res = await client.get_subscriptions()
|
|
|
|
print(res)
|
|
|
|
|
|
|
|
|
|
|
|
async def get_owned_stores_cmd(rpc_port: Optional[int]) -> None:
|
2023-02-28 08:49:47 +03:00
|
|
|
async with get_any_service_client(DataLayerRpcClient, rpc_port) as (client, _, _):
|
2022-10-20 01:02:05 +03:00
|
|
|
if client is not None:
|
2022-08-25 15:17:08 +03:00
|
|
|
res = await client.get_owned_stores()
|
|
|
|
print(res)
|
2022-10-28 23:05:03 +03:00
|
|
|
|
|
|
|
|
|
|
|
async def get_sync_status_cmd(
|
|
|
|
rpc_port: Optional[int],
|
|
|
|
store_id: str,
|
|
|
|
) -> None:
|
|
|
|
store_id_bytes = bytes32.from_hexstr(store_id)
|
2023-02-28 08:49:47 +03:00
|
|
|
async with get_any_service_client(DataLayerRpcClient, rpc_port) as (client, _, _):
|
2022-10-28 23:05:03 +03:00
|
|
|
if client is not None:
|
|
|
|
res = await client.get_sync_status(store_id=store_id_bytes)
|
|
|
|
print(res)
|