diff --git a/chia/_tests/core/data_layer/test_data_rpc.py b/chia/_tests/core/data_layer/test_data_rpc.py index 42c5cd1be9eb..622e441b8f56 100644 --- a/chia/_tests/core/data_layer/test_data_rpc.py +++ b/chia/_tests/core/data_layer/test_data_rpc.py @@ -264,7 +264,7 @@ async def test_create_insert_get( changelist: List[Dict[str, str]] = [{"action": "insert", "key": key.hex(), "value": value.hex()}] res = await data_rpc_api.create_data_store({}) assert res is not None - store_id = bytes32(hexstr_to_bytes(res["id"])) + store_id = bytes32.from_hexstr(res["id"]) await farm_block_check_singleton(data_layer, full_node_api, ph, store_id, wallet=wallet_rpc_api.service) res = await data_rpc_api.batch_update({"id": store_id.hex(), "changelist": changelist}) update_tx_rec0 = res["tx_id"] @@ -369,7 +369,7 @@ async def test_create_double_insert( data_rpc_api = DataLayerRpcApi(data_layer) res = await data_rpc_api.create_data_store({}) assert res is not None - store_id = bytes32(hexstr_to_bytes(res["id"])) + store_id = bytes32.from_hexstr(res["id"]) await farm_block_check_singleton(data_layer, full_node_api, ph, store_id, wallet=wallet_rpc_api.service) key1 = b"a" value1 = b"\x01\x02" @@ -407,7 +407,7 @@ async def test_keys_values_ancestors( data_rpc_api = DataLayerRpcApi(data_layer) res = await data_rpc_api.create_data_store({}) assert res is not None - store_id = bytes32(hexstr_to_bytes(res["id"])) + store_id = bytes32.from_hexstr(res["id"]) await farm_block_check_singleton(data_layer, full_node_api, ph, store_id, wallet=wallet_rpc_api.service) key1 = b"a" value1 = b"\x01\x02" @@ -482,12 +482,12 @@ async def test_get_roots( data_rpc_api = DataLayerRpcApi(data_layer) res = await data_rpc_api.create_data_store({}) assert res is not None - store_id1 = bytes32(hexstr_to_bytes(res["id"])) + store_id1 = bytes32.from_hexstr(res["id"]) await farm_block_check_singleton(data_layer, full_node_api, ph, store_id1, wallet=wallet_rpc_api.service) res = await data_rpc_api.create_data_store({}) assert res is not None - store_id2 = bytes32(hexstr_to_bytes(res["id"])) + store_id2 = bytes32.from_hexstr(res["id"]) await farm_block_check_singleton(data_layer, full_node_api, ph, store_id2, wallet=wallet_rpc_api.service) key1 = b"a" @@ -535,7 +535,7 @@ async def test_get_root_history( data_rpc_api = DataLayerRpcApi(data_layer) res = await data_rpc_api.create_data_store({}) assert res is not None - store_id1 = bytes32(hexstr_to_bytes(res["id"])) + store_id1 = bytes32.from_hexstr(res["id"]) await farm_block_check_singleton(data_layer, full_node_api, ph, store_id1, wallet=wallet_rpc_api.service) key1 = b"a" value1 = b"\x01\x02" @@ -589,7 +589,7 @@ async def test_get_kv_diff( data_rpc_api = DataLayerRpcApi(data_layer) res = await data_rpc_api.create_data_store({}) assert res is not None - store_id1 = bytes32(hexstr_to_bytes(res["id"])) + store_id1 = bytes32.from_hexstr(res["id"]) await farm_block_check_singleton(data_layer, full_node_api, ph, store_id1, wallet=wallet_rpc_api.service) key1 = b"a" value1 = b"\x01\x02" @@ -656,7 +656,7 @@ async def test_batch_update_matches_single_operations( data_rpc_api = DataLayerRpcApi(data_layer) res = await data_rpc_api.create_data_store({}) assert res is not None - store_id = bytes32(hexstr_to_bytes(res["id"])) + store_id = bytes32.from_hexstr(res["id"]) await farm_block_check_singleton(data_layer, full_node_api, ph, store_id, wallet=wallet_rpc_api.service) key = b"a" @@ -2435,7 +2435,7 @@ async def test_mirrors( data_rpc_api = DataLayerRpcApi(data_layer) res = await data_rpc_api.create_data_store({}) assert res is not None - store_id = bytes32(hexstr_to_bytes(res["id"])) + store_id = bytes32.from_hexstr(res["id"]) await farm_block_check_singleton(data_layer, full_node_api, ph, store_id, wallet=wallet_rpc_api.service) urls = ["http://127.0.0.1/8000", "http://127.0.0.1/8001"] @@ -2660,7 +2660,7 @@ async def test_dl_proof_errors( fakeroot = bytes32([4] * 32) res = await data_rpc_api.create_data_store({}) assert res is not None - store_id = bytes32(hexstr_to_bytes(res["id"])) + store_id = bytes32.from_hexstr(res["id"]) await farm_block_check_singleton(data_layer, full_node_api, ph, store_id, wallet=wallet_rpc_api.service) with pytest.raises(ValueError, match="no root"): @@ -2769,7 +2769,7 @@ async def test_pagination_rpcs( data_rpc_api = DataLayerRpcApi(data_layer) res = await data_rpc_api.create_data_store({}) assert res is not None - store_id = bytes32(hexstr_to_bytes(res["id"])) + store_id = bytes32.from_hexstr(res["id"]) await farm_block_check_singleton(data_layer, full_node_api, ph, store_id, wallet=wallet_rpc_api.service) key1 = b"aa" value1 = b"\x01\x02" @@ -3035,7 +3035,7 @@ async def test_pagination_cmds( res = await data_rpc_api.create_data_store({}) assert res is not None - store_id = bytes32(hexstr_to_bytes(res["id"])) + store_id = bytes32.from_hexstr(res["id"]) await farm_block_check_singleton(data_layer, full_node_api, ph, store_id, wallet=wallet_rpc_api.service) key = b"aa" @@ -3271,7 +3271,7 @@ async def test_unsubmitted_batch_update( res = await data_rpc_api.create_data_store({}) assert res is not None - store_id = bytes32(hexstr_to_bytes(res["id"])) + store_id = bytes32.from_hexstr(res["id"]) await farm_block_check_singleton(data_layer, full_node_api, ph, store_id, wallet=wallet_rpc_api.service) to_insert = [(b"a", b"\x00\x01"), (b"b", b"\x00\x02"), (b"c", b"\x00\x03")] @@ -3725,7 +3725,7 @@ class ModifiedStatus(IntEnum): res = await data_rpc_api.create_data_store({}) assert res is not None - store_id = bytes32(hexstr_to_bytes(res["id"])) + store_id = bytes32.from_hexstr(res["id"]) await farm_block_check_singleton(data_layer, full_node_api, ph, store_id, wallet=wallet_rpc_api.service) m.setattr("chia.data_layer.data_layer_util.Status", OldStatus) diff --git a/chia/cmds/plotnft_funcs.py b/chia/cmds/plotnft_funcs.py index f55c075837ef..d0663ee0840c 100644 --- a/chia/cmds/plotnft_funcs.py +++ b/chia/cmds/plotnft_funcs.py @@ -310,7 +310,7 @@ async def join_pool( func = functools.partial( wallet_client.pw_join_pool, wallet_id, - bytes32(hexstr_to_bytes(json_dict["target_puzzle_hash"])), + bytes32.from_hexstr(json_dict["target_puzzle_hash"]), pool_url, json_dict["relative_lock_height"], fee, diff --git a/chia/pools/pool_wallet_info.py b/chia/pools/pool_wallet_info.py index cf42aa8dacde..f42580f08f37 100644 --- a/chia/pools/pool_wallet_info.py +++ b/chia/pools/pool_wallet_info.py @@ -9,7 +9,6 @@ from chia.protocols.pool_protocol import POOL_PROTOCOL_VERSION from chia.types.blockchain_format.coin import Coin from chia.types.blockchain_format.sized_bytes import bytes32 -from chia.util.byte_types import hexstr_to_bytes from chia.util.ints import uint8, uint32 from chia.util.streamable import Streamable, streamable @@ -75,7 +74,7 @@ def initial_pool_state_from_dict( pool_url: str = "" relative_lock_height = uint32(0) elif singleton_state == FARMING_TO_POOL: - target_puzzle_hash = bytes32(hexstr_to_bytes(state_dict["target_puzzle_hash"])) + target_puzzle_hash = bytes32.from_hexstr(state_dict["target_puzzle_hash"]) pool_url = state_dict["pool_url"] relative_lock_height = uint32(state_dict["relative_lock_height"]) else: diff --git a/chia/rpc/data_layer_rpc_api.py b/chia/rpc/data_layer_rpc_api.py index 1611c5061c3e..e62faf7dc69e 100644 --- a/chia/rpc/data_layer_rpc_api.py +++ b/chia/rpc/data_layer_rpc_api.py @@ -49,7 +49,7 @@ def process_change(change: Dict[str, Any]) -> Dict[str, Any]: # have to deal with maybe-present attributes or Dict[str, Any] hints. reference_node_hash = change.get("reference_node_hash") if reference_node_hash is not None: - reference_node_hash = bytes32(hexstr_to_bytes(reference_node_hash)) + reference_node_hash = bytes32.from_hexstr(reference_node_hash) side = change.get("side") if side is not None: @@ -216,7 +216,7 @@ async def get_keys(self, request: Dict[str, Any]) -> EndpointResult: return response async def get_keys_values(self, request: Dict[str, Any]) -> EndpointResult: - store_id = bytes32(hexstr_to_bytes(request["id"])) + store_id = bytes32.from_hexstr(request["id"]) # NOTE: being outside the rpc, this retains the none-means-unspecified semantics root_hash: Optional[str] = request.get("root_hash") page = request.get("page", None) @@ -256,7 +256,7 @@ async def get_keys_values(self, request: Dict[str, Any]) -> EndpointResult: return response async def get_ancestors(self, request: Dict[str, Any]) -> EndpointResult: - store_id = bytes32(hexstr_to_bytes(request["id"])) + store_id = bytes32.from_hexstr(request["id"]) node_hash = bytes32.from_hexstr(request["hash"]) if self.service is None: raise Exception("Data layer not created") @@ -270,7 +270,7 @@ async def batch_update(self, request: Dict[str, Any]) -> EndpointResult: """ fee = get_fee(self.service.config, request) changelist = [process_change(change) for change in request["changelist"]] - store_id = bytes32(hexstr_to_bytes(request["id"])) + store_id = bytes32.from_hexstr(request["id"]) submit_on_chain = request.get("submit_on_chain", True) # todo input checks if self.service is None: @@ -302,7 +302,7 @@ async def multistore_batch_update(self, request: Dict[str, Any]) -> EndpointResu return {} async def submit_pending_root(self, request: Dict[str, Any]) -> EndpointResult: - store_id = bytes32(hexstr_to_bytes(request["id"])) + store_id = bytes32.from_hexstr(request["id"]) fee = get_fee(self.service.config, request) transaction_record = await self.service.submit_pending_root(store_id, uint64(fee)) return {"tx_id": transaction_record.name} @@ -320,7 +320,7 @@ async def insert(self, request: Dict[str, Any]) -> EndpointResult: fee = get_fee(self.service.config, request) key = hexstr_to_bytes(request["key"]) value = hexstr_to_bytes(request["value"]) - store_id = bytes32(hexstr_to_bytes(request["id"])) + store_id = bytes32.from_hexstr(request["id"]) # todo input checks if self.service is None: raise Exception("Data layer not created") @@ -336,7 +336,7 @@ async def delete_key(self, request: Dict[str, Any]) -> EndpointResult: """ fee = get_fee(self.service.config, request) key = hexstr_to_bytes(request["key"]) - store_id = bytes32(hexstr_to_bytes(request["id"])) + store_id = bytes32.from_hexstr(request["id"]) # todo input checks if self.service is None: raise Exception("Data layer not created") @@ -347,7 +347,7 @@ async def delete_key(self, request: Dict[str, Any]) -> EndpointResult: async def get_root(self, request: Dict[str, Any]) -> EndpointResult: """get hash of latest tree root""" - store_id = bytes32(hexstr_to_bytes(request["id"])) + store_id = bytes32.from_hexstr(request["id"]) # todo input checks if self.service is None: raise Exception("Data layer not created") @@ -358,7 +358,7 @@ async def get_root(self, request: Dict[str, Any]) -> EndpointResult: async def get_local_root(self, request: Dict[str, Any]) -> EndpointResult: """get hash of latest tree root saved in our local datastore""" - store_id = bytes32(hexstr_to_bytes(request["id"])) + store_id = bytes32.from_hexstr(request["id"]) # todo input checks if self.service is None: raise Exception("Data layer not created") diff --git a/chia/rpc/farmer_rpc_api.py b/chia/rpc/farmer_rpc_api.py index 24c6d64adad8..2bd84fce95d0 100644 --- a/chia/rpc/farmer_rpc_api.py +++ b/chia/rpc/farmer_rpc_api.py @@ -11,7 +11,6 @@ from chia.protocols.harvester_protocol import Plot from chia.rpc.rpc_server import Endpoint, EndpointResult from chia.types.blockchain_format.sized_bytes import bytes32 -from chia.util.byte_types import hexstr_to_bytes from chia.util.ints import uint32 from chia.util.paginator import Paginator from chia.util.streamable import Streamable, streamable @@ -354,7 +353,7 @@ async def get_harvester_plots_duplicates(self, request_dict: Dict[str, object]) return self.paginated_plot_path_request(Receiver.duplicates, request_dict) async def get_pool_login_link(self, request: Dict[str, Any]) -> EndpointResult: - launcher_id: bytes32 = bytes32(hexstr_to_bytes(request["launcher_id"])) + launcher_id: bytes32 = bytes32.from_hexstr(request["launcher_id"]) login_link: Optional[str] = await self.service.generate_login_link(launcher_id) if login_link is None: raise ValueError(f"Failed to generate login link for {launcher_id.hex()}") diff --git a/chia/rpc/full_node_rpc_client.py b/chia/rpc/full_node_rpc_client.py index fd110bbc23e8..eba4e0f9e97e 100644 --- a/chia/rpc/full_node_rpc_client.py +++ b/chia/rpc/full_node_rpc_client.py @@ -12,7 +12,6 @@ from chia.types.full_block import FullBlock from chia.types.spend_bundle import SpendBundle from chia.types.unfinished_header_block import UnfinishedHeaderBlock -from chia.util.byte_types import hexstr_to_bytes from chia.util.ints import uint32 @@ -235,13 +234,13 @@ async def get_puzzle_and_solution(self, coin_id: bytes32, height: uint32) -> Opt async def get_all_mempool_tx_ids(self) -> List[bytes32]: response = await self.fetch("get_all_mempool_tx_ids", {}) - return [bytes32(hexstr_to_bytes(tx_id_hex)) for tx_id_hex in response["tx_ids"]] + return [bytes32.from_hexstr(tx_id_hex) for tx_id_hex in response["tx_ids"]] async def get_all_mempool_items(self) -> Dict[bytes32, Dict[str, Any]]: response = await self.fetch("get_all_mempool_items", {}) converted: Dict[bytes32, Dict[str, Any]] = {} for tx_id_hex, item in response["mempool_items"].items(): - converted[bytes32(hexstr_to_bytes(tx_id_hex))] = item + converted[bytes32.from_hexstr(tx_id_hex)] = item return converted async def get_mempool_item_by_tx_id( diff --git a/chia/rpc/wallet_rpc_api.py b/chia/rpc/wallet_rpc_api.py index d34ffdfb4aee..a068a31cd579 100644 --- a/chia/rpc/wallet_rpc_api.py +++ b/chia/rpc/wallet_rpc_api.py @@ -1047,7 +1047,7 @@ async def get_wallet_balances(self, request: Dict[str, Any]) -> EndpointResult: return {"wallet_balances": wallet_balances} async def get_transaction(self, request: Dict[str, Any]) -> EndpointResult: - transaction_id: bytes32 = bytes32(hexstr_to_bytes(request["transaction_id"])) + transaction_id: bytes32 = bytes32.from_hexstr(request["transaction_id"]) tr: Optional[TransactionRecord] = await self.service.wallet_state_manager.get_transaction(transaction_id) if tr is None: raise ValueError(f"Transaction 0x{transaction_id.hex()} not found") @@ -1058,7 +1058,7 @@ async def get_transaction(self, request: Dict[str, Any]) -> EndpointResult: } async def get_transaction_memo(self, request: Dict[str, Any]) -> EndpointResult: - transaction_id: bytes32 = bytes32(hexstr_to_bytes(request["transaction_id"])) + transaction_id: bytes32 = bytes32.from_hexstr(request["transaction_id"]) tr: Optional[TransactionRecord] = await self.service.wallet_state_manager.get_transaction(transaction_id) if tr is None: raise ValueError(f"Transaction 0x{transaction_id.hex()} not found") @@ -3681,7 +3681,7 @@ async def nft_mint_bulk( if xch_change_target[:2] == "xch": xch_change_ph = decode_puzzle_hash(xch_change_target) else: - xch_change_ph = bytes32(hexstr_to_bytes(xch_change_target)) + xch_change_ph = bytes32.from_hexstr(xch_change_target) else: xch_change_ph = None new_innerpuzhash = request.get("new_innerpuzhash", None) @@ -3693,7 +3693,7 @@ async def nft_mint_bulk( did_coin = None did_lineage_parent_hex = request.get("did_lineage_parent", None) if did_lineage_parent_hex: - did_lineage_parent = bytes32(hexstr_to_bytes(did_lineage_parent_hex)) + did_lineage_parent = bytes32.from_hexstr(did_lineage_parent_hex) else: did_lineage_parent = None mint_from_did = request.get("mint_from_did", False) @@ -3982,7 +3982,7 @@ async def pw_join_pool( raise ValueError("Wallet needs to be fully synced.") if "target_puzzlehash" in request: - target_puzzlehash = bytes32(hexstr_to_bytes(request["target_puzzlehash"])) + target_puzzlehash = bytes32.from_hexstr(request["target_puzzlehash"]) assert target_puzzlehash is not None new_target_state: PoolState = create_pool_state( FARMING_TO_POOL, diff --git a/chia/simulator/simulator_full_node_rpc_client.py b/chia/simulator/simulator_full_node_rpc_client.py index c5876bc06362..70ad09fade24 100644 --- a/chia/simulator/simulator_full_node_rpc_client.py +++ b/chia/simulator/simulator_full_node_rpc_client.py @@ -7,7 +7,6 @@ from chia.types.coin_record import CoinRecord from chia.types.full_block import FullBlock from chia.util.bech32m import encode_puzzle_hash -from chia.util.byte_types import hexstr_to_bytes from chia.util.ints import uint128 @@ -33,7 +32,7 @@ async def get_auto_farming(self) -> bool: async def get_farming_ph(self) -> bytes32: result = await self.fetch("get_farming_ph", {}) - return bytes32(hexstr_to_bytes(result["puzzle_hash"])) + return bytes32.from_hexstr(result["puzzle_hash"]) async def get_all_coins(self, include_spent_coins: bool = False) -> List[CoinRecord]: json_result = await self.fetch("get_all_coins", {"include_spent_coins": include_spent_coins}) diff --git a/chia/wallet/cat_wallet/cat_wallet.py b/chia/wallet/cat_wallet/cat_wallet.py index bd7783e5eb9d..74d52943a99d 100644 --- a/chia/wallet/cat_wallet/cat_wallet.py +++ b/chia/wallet/cat_wallet/cat_wallet.py @@ -225,7 +225,7 @@ async def get_or_create_wallet_for_cat( elif name is None: name = self.default_wallet_name_for_unknown_cat(limitations_program_hash_hex) - limitations_program_hash = bytes32(hexstr_to_bytes(limitations_program_hash_hex)) + limitations_program_hash = bytes32.from_hexstr(limitations_program_hash_hex) self.cat_info = CATInfo(limitations_program_hash, None) info_as_string = bytes(self.cat_info).hex() self.wallet_info = await wallet_state_manager.user_store.create_wallet(name, WalletType.CAT, info_as_string) diff --git a/chia/wallet/cat_wallet/dao_cat_wallet.py b/chia/wallet/cat_wallet/dao_cat_wallet.py index f769d5803391..d9b64b2ac8c3 100644 --- a/chia/wallet/cat_wallet/dao_cat_wallet.py +++ b/chia/wallet/cat_wallet/dao_cat_wallet.py @@ -128,7 +128,7 @@ async def get_or_create_wallet_for_cat( if name is None: name = CATWallet.default_wallet_name_for_unknown_cat(limitations_program_hash_hex) - limitations_program_hash = bytes32(hexstr_to_bytes(limitations_program_hash_hex)) + limitations_program_hash = bytes32.from_hexstr(limitations_program_hash_hex) self.dao_cat_info = DAOCATInfo( dao_wallet_id,