diff --git a/docs/source/conf.py b/docs/source/conf.py index 3bd2fdd..030a02c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -17,12 +17,12 @@ # -- Project information ----------------------------------------------------- -project = 'Pythereum' -copyright = '2023, Gabriel Donnan' -author = 'Gabriel Donnan' +project = "Pythereum" +copyright = "2023, Gabriel Donnan" +author = "Gabriel Donnan" # The full version, including alpha/beta/rc tags -release = '1.1.6' +release = "1.1.6" # -- General configuration --------------------------------------------------- @@ -33,16 +33,16 @@ extensions = ["sphinx.ext.autodoc", "sphinx.ext.viewcode", "sphinx.ext.napoleon"] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = 'English' +language = "English" -pygments_style = 'sphinx' +pygments_style = "sphinx" # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. @@ -55,9 +55,9 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = 'sphinx_rtd_theme' +html_theme = "sphinx_rtd_theme" # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] \ No newline at end of file +html_static_path = ["_static"] diff --git a/pythereum/builders.py b/pythereum/builders.py index 470d68b..cb65632 100644 --- a/pythereum/builders.py +++ b/pythereum/builders.py @@ -16,14 +16,14 @@ class Builder(ABC): def __init__( - self, - url: str, - private_transaction_method: str = "eth_sendPrivateTransaction", - bundle_method: str = "eth_sendBundle", - cancel_bundle_method: str = "eth_cancelBundle", - mev_bundle_method: str = "mev_sendBundle", - bundle_params: set = None, - private_key: str = None, + self, + url: str, + private_transaction_method: str = "eth_sendPrivateTransaction", + bundle_method: str = "eth_sendBundle", + cancel_bundle_method: str = "eth_cancelBundle", + mev_bundle_method: str = "mev_sendBundle", + bundle_params: set = None, + private_key: str = None, ): if bundle_params is None: bundle_params = { @@ -48,9 +48,9 @@ def __init__( super().__init__() def format_private_transaction( - self, - tx: str | HexStr | list[str] | list[HexStr], - max_block_number: str | HexStr | list[str] | list[HexStr] | None = None, + self, + tx: str | HexStr | list[str] | list[HexStr], + max_block_number: str | HexStr | list[str] | list[HexStr] | None = None, ) -> list[Any]: return [tx, max_block_number] @@ -68,7 +68,7 @@ def get_flashbots_header(self, payload: str = "") -> dict: payload = messages.encode_defunct(keccak(text=payload)) return { "X-Flashbots-Signature": f"{Account.from_key(self.private_key.hex_bytes).address}:" - f"{Account.sign_message(payload, self.private_key.hex_bytes).signature.hex()}" + f"{Account.sign_message(payload, self.private_key.hex_bytes).signature.hex()}" } @@ -95,9 +95,9 @@ def __init__(self, private_key: str | HexStr | None = None): ) def format_private_transaction( - self, - tx: str | HexStr | list[str] | list[HexStr], - max_block_number: str | HexStr | list[str] | list[HexStr] | None = None, + self, + tx: str | HexStr | list[str] | list[HexStr], + max_block_number: str | HexStr | list[str] | list[HexStr] | None = None, ) -> list[dict]: res = {"tx": tx} if max_block_number is not None: @@ -128,9 +128,9 @@ def __init__(self, private_key: str | HexStr | None = None): ) def format_private_transaction( - self, - tx: str | HexStr | list[str] | list[HexStr], - max_block_number: str | HexStr | list[str] | list[HexStr] | None = None, + self, + tx: str | HexStr | list[str] | list[HexStr], + max_block_number: str | HexStr | list[str] | list[HexStr] | None = None, ) -> list[Any]: return [tx] @@ -158,9 +158,9 @@ def __init__(self, private_key: str | HexStr | None = None): ) def format_private_transaction( - self, - tx: str | HexStr | list[str] | list[HexStr], - max_block_number: str | HexStr | list[str] | list[HexStr] | None = None, + self, + tx: str | HexStr | list[str] | list[HexStr], + max_block_number: str | HexStr | list[str] | list[HexStr] | None = None, ) -> list[Any]: return [tx] @@ -187,9 +187,9 @@ def __init__(self, private_key: str | HexStr | None = None): ) def format_private_transaction( - self, - tx: str | HexStr | list[str] | list[HexStr], - max_block_number: str | HexStr | list[str] | list[HexStr] | None = None, + self, + tx: str | HexStr | list[str] | list[HexStr], + max_block_number: str | HexStr | list[str] | list[HexStr] | None = None, ) -> list[Any]: return [tx] @@ -214,7 +214,7 @@ def __init__(self, private_key: str | HexStr | None = None): ) def format_private_transaction( - self, tx: str | HexStr | list[str] | list[HexStr], preferences: dict = None + self, tx: str | HexStr | list[str] | list[HexStr], preferences: dict = None ) -> list[Any]: return [{"tx": tx, "preferences": preferences}] @@ -222,7 +222,7 @@ def get_header(self, payload: str = "") -> dict: payload = messages.encode_defunct(keccak(text=payload)) return { "X-Flashbots-Signature": f"{Account.from_key(self.private_key.hex_bytes).address}:" - f"{Account.sign_message(payload, self.private_key.hex_bytes).signature.hex()}" + f"{Account.sign_message(payload, self.private_key.hex_bytes).signature.hex()}" } @@ -232,14 +232,14 @@ class BuilderRPC: """ def __init__( - self, - builders: Builder | list[Builder], - private_key: str - | bytes - | HexStr - | list[str] - | list[bytes] - | list[HexStr] = None, + self, + builders: Builder | list[Builder], + private_key: str + | bytes + | HexStr + | list[str] + | list[bytes] + | list[HexStr] = None, ): if not isinstance(builders, list): builders = [builders] @@ -257,7 +257,7 @@ def _next_id(self) -> None: self._id += 1 def _build_json( - self, method: str, params: list[Any], increment: bool = True + self, method: str, params: list[Any], increment: bool = True ) -> dict: """ :param method: ethereum RPC method @@ -272,11 +272,11 @@ def _build_json( return res async def _send_message( - self, - builder: Builder, - method: str | list[str], - params: list[Any], - use_flashbots_signature: bool = False, + self, + builder: Builder, + method: str | list[str], + params: list[Any], + use_flashbots_signature: bool = False, ): if self.session is not None: constructed_json = self._build_json(method, params) @@ -286,7 +286,7 @@ async def _send_message( else builder.get_header(json.dumps(constructed_json)) ) async with self.session.post( - builder.url, json=constructed_json, headers=header_data + builder.url, json=constructed_json, headers=header_data ) as resp: if resp.status != 200: raise ERPCRequestException( @@ -310,9 +310,9 @@ async def close_session(self): await self.session.close() async def send_private_transaction( - self, - tx: str | HexStr, - extra_info: Any = None, + self, + tx: str | HexStr, + extra_info: Any = None, ) -> Any: tx_methods = [builder.private_transaction_method for builder in self.builders] tx = [ @@ -327,8 +327,8 @@ async def send_private_transaction( ) async def send_bundle( - self, - bundle: Bundle, + self, + bundle: Bundle, ) -> Any: tx_methods = [builder.bundle_method for builder in self.builders] tx = [builder.format_bundle(bundle) for builder in self.builders] @@ -340,8 +340,8 @@ async def send_bundle( ) async def cancel_bundle( - self, - replacement_uuids: str | HexStr, + self, + replacement_uuids: str | HexStr, ): cancel_methods = [builder.cancel_bundle_method for builder in self.builders] replacement_uuids = [replacement_uuids for _ in self.builders] @@ -349,8 +349,8 @@ async def cancel_bundle( *( self._send_message(builder, method, uuid) for builder, method, uuid in zip( - self.builders, cancel_methods, replacement_uuids - ) + self.builders, cancel_methods, replacement_uuids + ) ) ) diff --git a/pythereum/socket_pool.py b/pythereum/socket_pool.py index bbb9281..bc3bd31 100644 --- a/pythereum/socket_pool.py +++ b/pythereum/socket_pool.py @@ -25,7 +25,9 @@ async def start(self) -> None: if self.connected: await self.quit() # Creates a number of sockets equal to the maximum pool size - sockets = await gather(*(connect(self._url) for _ in range(self._max_pool_size))) + sockets = await gather( + *(connect(self._url) for _ in range(self._max_pool_size)) + ) await gather(*(self._sockets.put(socket) for socket in sockets)) self._sockets_used = 0 self.connected = True