diff --git a/bittensor/core/async_subtensor.py b/bittensor/core/async_subtensor.py index ca90ba4299..ea7ec359bb 100644 --- a/bittensor/core/async_subtensor.py +++ b/bittensor/core/async_subtensor.py @@ -343,7 +343,7 @@ async def determine_block_hash( # Return the appropriate value. if block_hash: return block_hash - if block: + if block is not None: return await self.get_block_hash(block) return None @@ -1235,6 +1235,9 @@ async def get_balances( """ if reuse_block: block_hash = self.substrate.last_block_hash + elif block_hash is None and block is None: + # Neither block nor block_hash provided, default to head + block_hash = await self.get_block_hash() else: block_hash = await self.determine_block_hash(block, block_hash, reuse_block) calls = [ @@ -1306,7 +1309,7 @@ async def get_block_hash(self, block: Optional[int] = None) -> str: Notes: See also: """ - if block: + if block is not None: return await self._get_block_hash(block) else: return await self.substrate.get_chain_head() diff --git a/bittensor/core/subtensor.py b/bittensor/core/subtensor.py index 28371fb7d6..49729d6a8b 100644 --- a/bittensor/core/subtensor.py +++ b/bittensor/core/subtensor.py @@ -746,7 +746,7 @@ def get_block_hash(self, block: Optional[int] = None) -> str: data. It is crucial for verifying transactions, ensuring data consistency, and maintaining the trustworthiness of the blockchain. """ - if block: + if block is not None: return self._get_block_hash(block) else: return self.substrate.get_chain_head() diff --git a/bittensor/utils/mock/subtensor_mock.py b/bittensor/utils/mock/subtensor_mock.py index 9773d525a4..becbd90595 100644 --- a/bittensor/utils/mock/subtensor_mock.py +++ b/bittensor/utils/mock/subtensor_mock.py @@ -581,7 +581,7 @@ def query_subtensor( ) -> MockSubtensorValue: if params is None: params = [] - if block: + if block is not None: if self.block_number < block: raise Exception("Cannot query block in the future") @@ -622,7 +622,7 @@ def query_map_subtensor( """ if params is None: params = [] - if block: + if block is not None: if self.block_number < block: raise Exception("Cannot query block in the future") @@ -668,7 +668,7 @@ def query_map_subtensor( def query_constant( self, module_name: str, constant_name: str, block: Optional[int] = None ) -> Optional[object]: - if block: + if block is not None: if self.block_number < block: raise Exception("Cannot query block in the future") @@ -697,7 +697,7 @@ def get_current_block(self) -> int: # ==== Balance RPC methods ==== def get_balance(self, address: str, block: int = None) -> "Balance": - if block: + if block is not None: if self.block_number < block: raise Exception("Cannot query block in the future") @@ -732,7 +732,7 @@ def neuron_for_uid( if uid is None: return NeuronInfo.get_null_neuron() - if block: + if block is not None: if self.block_number < block: raise Exception("Cannot query block in the future") @@ -958,7 +958,7 @@ def neuron_for_uid_lite( if uid is None: return NeuronInfoLite.get_null_neuron() - if block: + if block is not None: if self.block_number < block: raise Exception("Cannot query block in the future")