Skip to content

Commit 59d52ff

Browse files
author
Roman
committed
cleanup bittensor/core/extrinsics/utils.py
1 parent 62b2aa7 commit 59d52ff

File tree

1 file changed

+5
-92
lines changed

1 file changed

+5
-92
lines changed

bittensor/core/extrinsics/utils.py

Lines changed: 5 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -2,106 +2,19 @@
22

33
from typing import TYPE_CHECKING
44

5-
from async_substrate_interface.errors import SubstrateRequestException
6-
7-
from bittensor.utils import format_error_message
85
from bittensor.utils.balance import Balance
9-
from bittensor.utils.btlogging import logging
106

117
if TYPE_CHECKING:
128
from bittensor_wallet import Wallet
13-
from bittensor.core.async_subtensor import AsyncSubtensor
14-
from async_substrate_interface import (
15-
AsyncExtrinsicReceipt,
16-
ExtrinsicReceipt,
17-
)
18-
from bittensor.core.subtensor import Subtensor
199
from bittensor.core.chain_data import StakeInfo
20-
from scalecodec.types import GenericExtrinsic
21-
22-
23-
def submit_extrinsic(
24-
subtensor: "Subtensor",
25-
extrinsic: "GenericExtrinsic",
26-
wait_for_inclusion: bool,
27-
wait_for_finalization: bool,
28-
) -> "ExtrinsicReceipt":
29-
"""
30-
Submits an extrinsic to the substrate blockchain and handles potential exceptions.
31-
32-
This function attempts to submit an extrinsic to the substrate blockchain with specified options
33-
for waiting for inclusion in a block and/or finalization. If an exception occurs during submission,
34-
it logs the error and re-raises the exception.
35-
36-
Args:
37-
subtensor: The Subtensor instance used to interact with the blockchain.
38-
extrinsic (scalecodec.types.GenericExtrinsic): The extrinsic to be submitted to the blockchain.
39-
wait_for_inclusion (bool): Whether to wait for the extrinsic to be included in a block.
40-
wait_for_finalization (bool): Whether to wait for the extrinsic to be finalized on the blockchain.
41-
42-
Returns:
43-
response: The response from the substrate after submitting the extrinsic.
44-
45-
Raises:
46-
SubstrateRequestException: If the submission of the extrinsic fails, the error is logged and re-raised.
47-
"""
48-
try:
49-
return subtensor.substrate.submit_extrinsic(
50-
extrinsic,
51-
wait_for_inclusion=wait_for_inclusion,
52-
wait_for_finalization=wait_for_finalization,
53-
)
54-
except SubstrateRequestException as e:
55-
logging.error(format_error_message(e.args[0]))
56-
# Re-raise the exception for retrying of the extrinsic call. If we remove the retry logic,
57-
# the raise will need to be removed.
58-
raise
59-
60-
61-
async def async_submit_extrinsic(
62-
subtensor: "AsyncSubtensor",
63-
extrinsic: "GenericExtrinsic",
64-
wait_for_inclusion: bool,
65-
wait_for_finalization: bool,
66-
) -> "AsyncExtrinsicReceipt":
67-
"""
68-
Submits an extrinsic to the substrate blockchain and handles potential exceptions.
69-
70-
This function attempts to submit an extrinsic to the substrate blockchain with specified options
71-
for waiting for inclusion in a block and/or finalization. If an exception occurs during submission,
72-
it logs the error and re-raises the exception.
73-
74-
Args:
75-
subtensor: The AsyncSubtensor instance used to interact with the blockchain.
76-
extrinsic: The extrinsic to be submitted to the blockchain.
77-
wait_for_inclusion: Whether to wait for the extrinsic to be included in a block.
78-
wait_for_finalization: Whether to wait for the extrinsic to be finalized on the blockchain.
79-
80-
Returns:
81-
response: The response from the substrate after submitting the extrinsic.
82-
83-
Raises:
84-
SubstrateRequestException: If the submission of the extrinsic fails, the error is logged and re-raised.
85-
"""
86-
try:
87-
return await subtensor.substrate.submit_extrinsic(
88-
extrinsic,
89-
wait_for_inclusion=wait_for_inclusion,
90-
wait_for_finalization=wait_for_finalization,
91-
)
92-
except SubstrateRequestException as e:
93-
logging.error(format_error_message(e.args[0]))
94-
# Re-raise the exception for retrying of the extrinsic call. If we remove the retry logic,
95-
# the raise will need to be removed.
96-
raise
9710

9811

9912
def get_old_stakes(
10013
wallet: "Wallet",
10114
hotkey_ss58s: list[str],
10215
netuids: list[int],
10316
all_stakes: list["StakeInfo"],
104-
) -> list[Balance]:
17+
) -> list["Balance"]:
10518
"""
10619
Retrieve the previous staking balances for a wallet's hotkeys across given netuids.
10720
@@ -110,10 +23,10 @@ def get_old_stakes(
11023
is found for a particular hotkey and netuid combination, a default balance of zero is returned.
11124
11225
Args:
113-
wallet (Wallet): The wallet containing the coldkey to compare with stake data.
114-
hotkey_ss58s (list[str]): List of hotkey SS58 addresses for which stakes are retrieved.
115-
netuids (list[int]): List of network unique identifiers (netuids) corresponding to the hotkeys.
116-
all_stakes (list[StakeInfo]): A collection of all staking information to search through.
26+
wallet: The wallet containing the coldkey to compare with stake data.
27+
hotkey_ss58s: List of hotkey SS58 addresses for which stakes are retrieved.
28+
netuids: List of network unique identifiers (netuids) corresponding to the hotkeys.
29+
all_stakes: A collection of all staking information to search through.
11730
11831
Returns:
11932
list[Balance]: A list of Balances, each representing the stake for a given hotkey and netuid.

0 commit comments

Comments
 (0)