From d885c3f7ef2129afe943ee1a9eec4130ff5b66d4 Mon Sep 17 00:00:00 2001 From: gmandonnan Date: Sat, 14 Oct 2023 15:10:30 +0100 Subject: [PATCH] v1.1.5 Commit --- README.md | 141 +++++++++++++++++++++++++++++++++++-------------- poetry.lock | 10 ++-- pyproject.toml | 4 +- 3 files changed, 107 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 5e9e944..9677d57 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,51 @@ The following builder classes are currently implemented: Each of these now have support for [mevboost](https://mevboost.pics) bundles. -### Example usage +# Getting started + +## Poetry + +This project and its dependencies are managed by python poetry, +which will automatically manage the versions of each library / python version +upon which this project depends. + +Install poetry with the instructions [here.](https://python-poetry.org/docs/) + +## Installation + +### Poetry Installation +The library currently requires python versions `>=3.11`. + +If you want to include this library for use in another project via Poetry +you must simply add the following to your `pyproject.toml` file under `[tool.poetry.dependencies]` + +```toml +pythereum = {git = "https://github.com/gabedonnan/pythereum.git"} +``` + +or + +```toml +pythereum = "^1.1.5" +``` + +If you would like to install the library via pypi instead of via this git repository. +This git repository will always be the most up to date but the releases on pypi should +be more thoroughly tested. + +### Pip / PyPi installation + +The library is now available via pip!! (I had to change the whole project name to get it there) + +It can be installed with the following command, or downloaded [here](https://pypi.org/project/pythereum/): -#### Basic single function call +```commandline +python3 -m pip install pythereum +``` + +## Example usage + +### Basic single function call ```python # Example simple function @@ -55,7 +97,7 @@ if __name__ == "__main__": asyncio.run(test_transaction_count()) ``` -#### Example subscription +### Example subscription ```python # Example subscription @@ -82,7 +124,7 @@ if __name__ == "__main__": asyncio.run(test_subscription(SubscriptionType.new_heads)) ``` -#### Example batch call +### Example batch call ```python # Example batch call @@ -111,7 +153,7 @@ if __name__ == "__main__": asyncio.run(test_batching()) ``` -#### Example currency conversion +### Example currency conversion ```python >>> from pythereum import EthDenomination, convert_eth @@ -121,7 +163,7 @@ if __name__ == "__main__": 1e-09 ``` -#### Example builder submission +### Example builder submission ```python # Example builder submission @@ -159,50 +201,67 @@ if __name__ == "__main__": asyncio.run(test_builder_submission()) ``` -More examples available in the [demo](https://github.com/gabedonnan/pythereum/tree/main/demo) folder. - -# Getting started - -## Poetry - -This project and its dependencies are managed by python poetry, -which will automatically manage the versions of each library / python version -upon which this project depends. - -Install poetry with the instructions [here.](https://python-poetry.org/docs/) - -## Installation - -### Poetry Installation -The library currently requires python versions `>=3.11`. - -If you want to include this library for use in another project via Poetry -you must simply add the following to your `pyproject.toml` file under `[tool.poetry.dependencies]` +### Example Gas and Nonce management -```toml -pythereum = {git = "https://github.com/gabedonnan/pythereum.git"} -``` - -or +```python +import asyncio +from eth_account import Account +from pythereum import GasManager, NonceManager, Transaction, EthRPC -```toml -pythereum = "^1.1.4" -``` +TEST_URL = "ws://127.0.0.1:8545" -If you would like to install the library via pypi instead of via this git repository. -This git repository will always be the most up to date but the releases on pypi should -be more thoroughly tested. +async def test_management(): + acct = Account.create() -### Pip / PyPi installation + tx = Transaction( + from_address=acct.address, + to_address="0x5fC2E691E520bbd3499f409bb9602DBA94184672", + value=1, + chain_id=1 + ) + + manager_rpc = EthRPC(TEST_URL, pool_size=2) + + await manager_rpc.start_pool() + + gm = GasManager(manager_rpc) + + async with gm.informed_manager() as im: + im.fill_transaction(tx) + + async with NonceManager(manager_rpc) as nm: + await nm.fill_transaction(tx) -The library is now available via pip!! (I had to change the whole project name to get it there) + signed_tx = Account.sign_transaction(tx, acct.key).rawTransaction -It can be installed with the following command, or downloaded [here](https://pypi.org/project/pythereum/): + tx_result = await manager_rpc.send_raw_transaction(signed_tx) + print(tx_result) + + # Wait some time for transaction to be executed so we can get its receipt + await asyncio.sleep(3) + + tx_receipt = await manager_rpc.get_transaction_receipt(tx_result) + + # Informing the informed manager about the result of transaction + # Giving it information like this means the next time gm.informed_manager() + # Fills a transaction, it will update its pricing accordingly. + # An execution success will mean the maxPriorityFeePerGas value of tx will + # be modified by im.success_multiplier, or alternatively if the transaction fails + # it will be modified by im.fail_multiplier + async with gm.informed_manager() as im: + if tx_receipt is not None: + if tx_receipt.status == 1: + # Tell the gas manager that the transaction succeeded + im.execution_success() + else: + # Tell the gas manager that the transaction failed + im.execution_failure() -```commandline -python3 -m pip install pythereum +if __name__ == "__main__": + asyncio.run(test_management()) ``` +More examples available in the [demo](https://github.com/gabedonnan/pythereum/tree/main/demo) folder. ## Testing your programs diff --git a/poetry.lock b/poetry.lock index 70fe3c4..e160898 100644 --- a/poetry.lock +++ b/poetry.lock @@ -672,13 +672,13 @@ test = ["pytest (>=7.0.0)", "pytest-xdist (>=2.4.0)"] [[package]] name = "eth-utils" -version = "2.2.1" +version = "2.2.2" description = "eth-utils: Common utility functions for python code that interacts with Ethereum" optional = false python-versions = ">=3.7,<4" files = [ - {file = "eth-utils-2.2.1.tar.gz", hash = "sha256:f79a95f86dd991344697c763db40271dbe43fbbcd5776f49b0c4fb7b645ee1c4"}, - {file = "eth_utils-2.2.1-py3-none-any.whl", hash = "sha256:60fc999c1b4ae011ab600b01a3eb5375156f3bc46e7cd1a83ca9e6e14bb9b13c"}, + {file = "eth-utils-2.2.2.tar.gz", hash = "sha256:5ca6265177ce544d9d43cdf2272ae2227e5d6d9529c270bbb707d17339087101"}, + {file = "eth_utils-2.2.2-py3-none-any.whl", hash = "sha256:2580a8065273f62ca1ec4c175228c52e626a5f1007e965d2117e5eca1a93cae8"}, ] [package.dependencies] @@ -689,7 +689,7 @@ toolz = {version = ">0.8.2", markers = "implementation_name == \"pypy\""} [package.extras] dev = ["black (>=23)", "build (>=0.9.0)", "bumpversion (>=0.5.3)", "eth-hash[pycryptodome]", "flake8 (==3.8.3)", "hypothesis (>=4.43.0)", "ipython", "isort (>=5.11.0)", "mypy (==0.971)", "pydocstyle (>=5.0.0)", "pytest (>=7.0.0)", "pytest-watch (>=4.1.0)", "pytest-xdist (>=2.4.0)", "sphinx (>=5.0.0)", "sphinx-rtd-theme (>=1.0.0)", "towncrier (>=21,<22)", "tox (>=4.0.0)", "twine", "types-setuptools", "wheel"] -doc = ["sphinx (>=5.0.0)", "sphinx-rtd-theme (>=1.0.0)", "towncrier (>=21,<22)"] +docs = ["sphinx (>=5.0.0)", "sphinx-rtd-theme (>=1.0.0)", "towncrier (>=21,<22)"] lint = ["black (>=23)", "flake8 (==3.8.3)", "isort (>=5.11.0)", "mypy (==0.971)", "pydocstyle (>=5.0.0)", "types-setuptools"] test = ["hypothesis (>=4.43.0)", "mypy (==0.971)", "pytest (>=7.0.0)", "pytest-xdist (>=2.4.0)", "types-setuptools"] @@ -1372,4 +1372,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = ">=3.11,<4.0" -content-hash = "d1f36a9ea4b1e6ee1d5de2ce1ae4b3e991f7cb8ae18b72831217925283e273f5" +content-hash = "8570f503d9c35d9f84aac273114dceaa402d0c1cdf0d0a3dc319ae2052b010da" diff --git a/pyproject.toml b/pyproject.toml index 891fcd8..b429f8d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pythereum" -version = "1.1.4" +version = "1.1.5" description = "A lightweight Ethereum JSON RPC library written in python" authors = ["gabedonnan <47415809+gabedonnan@users.noreply.github.com>"] readme = "README.md" @@ -14,7 +14,7 @@ pytest = "^7.4.2" pytest-asyncio = "^0.21.1" aiohttp = "^3.8.6" eth-account = "^0.9.0" -eth-utils = "^2.2.1" +eth-utils = "^2.2.2" [build-system] requires = ["poetry-core"]