2525 decode_account_id ,
2626 SubnetInfo ,
2727 PrometheusInfo ,
28+ ProposalVoteData ,
2829)
2930from bittensor .core .extrinsics .asyncio .registration import register_extrinsic
3031from bittensor .core .extrinsics .asyncio .root import (
@@ -76,26 +77,6 @@ class ParamWithTypes(TypedDict):
7677 type : str # ScaleType string of the parameter.
7778
7879
79- class ProposalVoteData :
80- index : int
81- threshold : int
82- ayes : list [str ]
83- nays : list [str ]
84- end : int
85-
86- def __init__ (self , proposal_dict : dict ) -> None :
87- self .index = proposal_dict ["index" ]
88- self .threshold = proposal_dict ["threshold" ]
89- self .ayes = self .decode_ss58_tuples (proposal_dict ["ayes" ])
90- self .nays = self .decode_ss58_tuples (proposal_dict ["nays" ])
91- self .end = proposal_dict ["end" ]
92-
93- @staticmethod
94- def decode_ss58_tuples (line : tuple ):
95- """Decodes a tuple of ss58 addresses formatted as bytes tuples."""
96- return [decode_account_id (line [x ][0 ]) for x in range (len (line ))]
97-
98-
9980def _decode_hex_identity_dict (info_dictionary : dict [str , Any ]) -> dict [str , Any ]:
10081 """Decodes a dictionary of hexadecimal identities."""
10182 for k , v in info_dictionary .items ():
@@ -1405,6 +1386,7 @@ async def sign_and_send_extrinsic(
14051386 wallet : "Wallet" ,
14061387 wait_for_inclusion : bool = True ,
14071388 wait_for_finalization : bool = False ,
1389+ sign_with : str = "coldkey" ,
14081390 ) -> tuple [bool , str ]:
14091391 """
14101392 Helper method to sign and submit an extrinsic call to chain.
@@ -1414,13 +1396,19 @@ async def sign_and_send_extrinsic(
14141396 wallet (bittensor_wallet.Wallet): the wallet whose coldkey will be used to sign the extrinsic
14151397 wait_for_inclusion (bool): whether to wait until the extrinsic call is included on the chain
14161398 wait_for_finalization (bool): whether to wait until the extrinsic call is finalized on the chain
1399+ sign_with: the wallet attr to sign the extrinsic call [coldkey (default), hotkey, or coldkeypub]
14171400
14181401 Returns:
14191402 (success, error message)
14201403 """
1404+ if sign_with not in ("coldkey" , "hotkey" , "coldkeypub" ):
1405+ raise AttributeError (
1406+ f"'sign_with' must be either 'coldkey', 'hotkey' or 'coldkeypub', not '{ sign_with } '"
1407+ )
1408+
14211409 extrinsic = await self .substrate .create_signed_extrinsic (
1422- call = call , keypair = wallet . coldkey
1423- ) # sign with coldkey
1410+ call = call , keypair = getattr ( wallet , sign_with )
1411+ )
14241412 try :
14251413 response = await self .substrate .submit_extrinsic (
14261414 extrinsic ,
@@ -1437,24 +1425,38 @@ async def sign_and_send_extrinsic(
14371425 except SubstrateRequestException as e :
14381426 return False , format_error_message (e )
14391427
1440- async def get_children (self , hotkey : str , netuid : int ) -> tuple [bool , list , str ]:
1428+ async def get_children (
1429+ self ,
1430+ hotkey : str ,
1431+ netuid : int ,
1432+ block : Optional [int ] = None ,
1433+ block_hash : Optional [str ] = None ,
1434+ reuse_block : bool = False ,
1435+ ) -> tuple [bool , list , str ]:
14411436 """
14421437 This method retrieves the children of a given hotkey and netuid. It queries the SubtensorModule's ChildKeys
14431438 storage function to get the children and formats them before returning as a tuple.
14441439
14451440 Args:
14461441 hotkey: The hotkey value.
14471442 netuid: The netuid value.
1443+ block: The block number to query. Do not specify if using block_hash or reuse_block.
1444+ block_hash: The hash of the blockchain block number for the query. Do not specify if using bloc or
1445+ reuse_block.
1446+ reuse_block: Whether to reuse the last-used blockchain hash. Do not set if using block_hash or reuse_block.
14481447
14491448 Returns:
14501449 A tuple containing a boolean indicating success or failure, a list of formatted children, and an error
14511450 message (if applicable)
14521451 """
1452+ block_hash = await self ._determine_block_hash (block , block_hash , reuse_block )
14531453 try :
14541454 children = await self .substrate .query (
14551455 module = "SubtensorModule" ,
14561456 storage_function = "ChildKeys" ,
14571457 params = [hotkey , netuid ],
1458+ block_hash = block_hash ,
1459+ reuse_block_hash = reuse_block ,
14581460 )
14591461 if children :
14601462 formatted_children = []
@@ -2702,3 +2704,36 @@ async def unstake(
27022704 wait_for_inclusion = wait_for_inclusion ,
27032705 wait_for_finalization = wait_for_finalization ,
27042706 )
2707+
2708+ async def state_call (
2709+ self ,
2710+ method : str ,
2711+ data : str ,
2712+ block : Optional [int ] = None ,
2713+ block_hash : Optional [str ] = None ,
2714+ reuse_block : bool = False ,
2715+ ) -> dict [Any , Any ]:
2716+ """
2717+ Makes a state call to the Bittensor blockchain, allowing for direct queries of the blockchain's state. This
2718+ function is typically used for advanced queries that require specific method calls and data inputs.
2719+
2720+ Args:
2721+ method: The method name for the state call.
2722+ data: The data to be passed to the method.
2723+ block: The blockchain block number at which to perform the state call.
2724+ block_hash: The hash of the block to retrieve the parameter from. Do not specify if using block or
2725+ reuse_block
2726+ reuse_block: Whether to use the last-used block. Do not set if using block_hash or block.
2727+
2728+ Returns:
2729+ result (dict[Any, Any]): The result of the rpc call.
2730+
2731+ The state call function provides a more direct and flexible way of querying blockchain data, useful for specific
2732+ use cases where standard queries are insufficient.
2733+ """
2734+ block_hash = await self ._determine_block_hash (block , block_hash , reuse_block )
2735+ return self .substrate .rpc_request (
2736+ method = "state_call" ,
2737+ params = [method , data , block_hash ] if block_hash else [method , data ],
2738+ reuse_block_hash = reuse_block ,
2739+ )
0 commit comments