Skip to content

Commit

Permalink
Black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
gabedonnan committed Oct 31, 2023
1 parent b68f804 commit 2777bd5
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 60 deletions.
18 changes: 9 additions & 9 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------------------
Expand All @@ -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.
Expand All @@ -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']
html_static_path = ["_static"]
100 changes: 50 additions & 50 deletions pythereum/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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]

Expand All @@ -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()}"
}


Expand All @@ -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:
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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]

Expand All @@ -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]

Expand All @@ -214,15 +214,15 @@ 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}]

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()}"
}


Expand All @@ -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]
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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(
Expand All @@ -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 = [
Expand All @@ -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]
Expand All @@ -340,17 +340,17 @@ 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]
return await asyncio.gather(
*(
self._send_message(builder, method, uuid)
for builder, method, uuid in zip(
self.builders, cancel_methods, replacement_uuids
)
self.builders, cancel_methods, replacement_uuids
)
)
)

Expand Down
4 changes: 3 additions & 1 deletion pythereum/socket_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2777bd5

Please sign in to comment.