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)
def sign_send_tx(self, from_account, tx_dict): tx_dict["nonce"] = from_account.nonce signed_tx = self.w3.eth.account.signTransaction(tx_dict, from_account.private_key) try: try: tx_hash = to_hex(self.w3.eth.sendRawTransaction(signed_tx.rawTransaction)) except ValueError as e: log(f"tx failed. trying with 0.2 more gwei({e})") tx_dict["gasPrice"] += 200000000 signed_tx = self.w3.eth.account.signTransaction(tx_dict, from_account.private_key) tx_hash = to_hex(self.w3.eth.sendRawTransaction(signed_tx.rawTransaction)) from_account.nonce += 1 return tx_hash except Timeout as e: log(f"ipc timeout ({e}). ignoring.") from_account.nonce += 1 return to_hex(signed_tx.hash)
async def shh_uninstall_filter(self, identifier: int) -> bool: """Uninstalls a filter with given id. Should always be called when watch is no longer needed. Additionally, filters timeout when they are not requested with shh_getFilterChanges for a period of time. Calls shh_uninstallFilter. :params id: The filter id. :returns bool: True if the filter was successfully uninstalled, otherwise false. """ return await self.rpc( eth_models.JSONRPCRequest( method=self.rpc_schema.shh_uninstall_filter[0], id=self.rpc_schema.shh_uninstall_filter[1], params=[conversions.to_hex(identifier)], ))
async def get_shh_filter_changes( self, identifier: int) -> List[eth_models.Message]: """Polling method for whisper filters. Returns new messages since the last call of this method. Note: Calling the shh_getMessages method, will reset the buffer for this method, so that you won’t receive duplicate messages. Calls shh_getFilterChanges. :param identifier: The filter id. :returns List[eth_models.Messages]: Array of messages received since last poll. """ result = await self.rpc( eth_models.JSONRPCRequest( method=self.rpc_schema.get_shh_filter_changes[0], id=self.rpc_schema.get_shh_filter_changes[1], params=[conversions.to_hex(identifier)], )) return eth_models.iterate_list(eth_models.Message, result)
def force_bytes_to_address(value: bytes): trimmed_value = value[-20:] padded_value = trimmed_value.rjust(20, b'\x00') return to_hex(padded_value)
def default(self, o): if isinstance(o, bytes): return to_hex(o) else: return super(BytesJSONEncoder, self).default(o)
def private_key(self): return to_hex(self.w3account.privateKey)