async def get_shh_messages( self, identifier: int) -> Union[List[eth_models.Message], bool]: """Get all messages matching a filter. Unlike shh_getFilterChanges this returns all messages. Calls shh_getMessages. :param identifier: The filter id. :returns List[eth_models.Messages]: Array of messages received. bool: False if no messages. """ result = await self.rpc( eth_models.JSONRPCRequest( method=self.rpc_schema.get_shh_messages[0], id=self.rpc_schema.get_shh_messages[1], params=[conversions.to_hex(identifier)], )) truthiness = eth_utils.result_truthiness(result) if isinstance(truthiness, bool): return truthiness return eth_models.iterate_list(eth_models.Message, result)
async def mining(self) -> bool: """Returns True if the client is actively mining new blocks. Calls eth_mining. :returns bool: True if the client is mining, otherwise False """ # Why can this RPC actually return a bool? return eth_utils.result_truthiness(await self.rpc( eth_models.JSONRPCRequest(method=self.rpc_schema.mining[0], id=self.rpc_schema.mining[1])))
async def shh_has_identity(self, identifier: eth_types.Data) -> bool: """Checks if the client hold the private keys for a given identity. Calls shh_hasIdentity. :params id: The identity address to check. :returns bool: Returns true if the message was send, otherwise false. """ return eth_utils.result_truthiness(await self.rpc( eth_models.JSONRPCRequest( method=self.rpc_schema.shh_has_identity[0], id=self.rpc_schema.shh_has_identity[1], params=[identifier], )))
async def shh_add_to_group(self, identifier: eth_types.Data) -> bool: """Add an identity to a group (?). Calls shh_addToGroup. :params id: The identity address to add to a group. :returns bool: Returns true if the identity was successfully added to the group, otherwise false (?). """ return eth_utils.result_truthiness(await self.rpc( eth_models.JSONRPCRequest( method=self.rpc_schema.shh_add_to_group[0], id=self.rpc_schema.shh_add_to_group[1], params=[identifier], )))
async def syncing(self) -> eth_models.SyncStatus: """Returns an object with sync status data. Calls eth_syncing. :returns eth_models.SyncStatus or False: with sync status data or False when not syncing. """ # It mystifies me why this can't return a proper JSON boolean. result = eth_utils.result_truthiness(await self.rpc( eth_models.JSONRPCRequest(method=self.rpc_schema.syncing[0], id=self.rpc_schema.syncing[1]))) if result: result["syncing"] = True return eth_models.SyncStatus.parse_obj(result) else: return eth_models.SyncStatus(syncing=False)
async def submit_hashrate( self, hashrate: eth_types.HexStr, identifier: eth_types.HexStr, ) -> bool: """Return code at a given address during specified block. Calls eth_submitHashrate. :param hashrate: A hexadecimal string representation of the hash rate. :param identifier: A random hexadecimal ID identifying the client. :returns bool: True if submitting went through and false otherwise. """ return eth_utils.result_truthiness(await self.rpc( eth_models.JSONRPCRequest( method=self.rpc_schema.submit_hashrate[0], id=self.rpc_schema.submit_hashrate[1], params=[hashrate, identifier], )))