Skip to content

Commit

Permalink
Merge pull request #1275 from njgheorghita/relocate-txpool
Browse files Browse the repository at this point in the history
Move txpool to geth namespace
  • Loading branch information
njgheorghita authored Mar 15, 2019
2 parents 9bb63e7 + 5285718 commit 4481263
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 36 deletions.
26 changes: 13 additions & 13 deletions docs/web3.txpool.rst
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
TX Pool API
===========

.. py:module:: web3.txpool
.. py:currentmodule:: web3.txpool
.. py:module:: web3.geth.txpool
.. py:currentmodule:: web3.geth.txpool
.. py:class:: TxPool
The ``web3.txpool`` object exposes methods to interact with the RPC APIs under
the ``txpool_`` namespace.
The ``web3.geth.txpool`` object exposes methods to interact with the RPC APIs under
the ``txpool_`` namespace. These methods are only exposed under the ``geth`` namespace
since they are not standard nor supported in Parity.


Properties
----------
Methods
-------

The following properties are available on the ``web3.txpool`` namespace.
The following methods are available on the ``web3.geth.txpool`` namespace.


.. py:attribute:: TxPool.inspect
.. py:method:: TxPool.inspect()
* Delegates to ``txpool_inspect`` RPC Method

Expand All @@ -26,7 +26,7 @@ The following properties are available on the ``web3.txpool`` namespace.

.. code-block:: python
>>> web3.txpool.inspect
>>> web3.geth.txpool.inspect()
{
'pending': {
'0x26588a9301b0428d95e6fc3a5024fce8bec12d51': {
Expand Down Expand Up @@ -78,7 +78,7 @@ The following properties are available on the ``web3.txpool`` namespace.
}
.. py:attribute:: TxPool.status
.. py:method:: TxPool.status()
* Delegates to ``txpool_status`` RPC Method

Expand All @@ -94,15 +94,15 @@ The following properties are available on the ``web3.txpool`` namespace.
}
.. py:attribute:: TxPool.content
.. py:method:: TxPool.content()
* Delegates to ``txpool_content`` RPC Method

Returns the exact details of all transactions that are pending or queued.

.. code-block:: python
>>> web3.txpool.content
>>> web3.geth.txpool.content()
{
'pending': {
'0x0216d5032f356960cd3749c31ab34eeff21b3395': {
Expand Down
2 changes: 1 addition & 1 deletion tests/core/txpool-module/test_txpool_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_txpool_content(web3_empty):
})
txn_2 = web3.eth.getTransaction(txn_2_hash)

content = web3.txpool.content
content = web3.geth.txpool.content

assert web3.eth.coinbase in content['pending']

Expand Down
2 changes: 1 addition & 1 deletion tests/core/txpool-module/test_txpool_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_txpool_inspect(web3_empty):
})
txn_2 = web3.eth.getTransaction(txn_2_hash)

inspect_content = web3.txpool.inspect
inspect_content = web3.geth.txpool.inspect

assert web3.eth.coinbase in inspect_content['pending']

Expand Down
14 changes: 14 additions & 0 deletions web3/geth.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
sign,
unlockAccount,
)
from web3.txpool import (
content,
inspect,
status,
)


class Geth(Module):
Expand All @@ -30,3 +35,12 @@ class GethPersonal(ModuleV2):
sendTransaction = sendTransaction()
sign = sign()
unlockAccount = unlockAccount()


class GethTxPool(ModuleV2):
"""
https://github.com/ethereum/go-ethereum/wiki/Management-APIs#txpool
"""
content = content()
inspect = inspect()
status = status()
8 changes: 3 additions & 5 deletions web3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from web3.geth import (
Geth,
GethPersonal,
GethTxPool,
)
from web3.iban import (
Iban,
Expand Down Expand Up @@ -78,9 +79,6 @@
from web3.testing import (
Testing,
)
from web3.txpool import (
TxPool,
)
from web3.version import (
Version,
)
Expand All @@ -91,14 +89,14 @@ def get_default_modules():
"eth": (Eth,),
"net": (Net,),
"version": (Version,),
"txpool": (TxPool,),
"miner": (Miner,),
"admin": (Admin,),
"parity": (Parity, {
"personal": (ParityPersonal,)
}),
"geth": (Geth, {
"personal": (GethPersonal,)
"personal": (GethPersonal,),
"txpool": (GethTxPool,),
}),
"testing": (Testing,),
}
Expand Down
4 changes: 4 additions & 0 deletions web3/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def default_munger(module, *args, **kwargs):
raise TypeError("Parameters passed to method without parameter mungers defined.")


def default_root_munger(module, *args):
return [*args]


class Method:
"""Method object for web3 module methods
Expand Down
5 changes: 1 addition & 4 deletions web3/personal.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from web3.method import (
Method,
default_root_munger,
)


def default_root_munger(module, *args):
return [*args]


def importRawKey():
return Method(
"personal_importRawKey",
Expand Down
31 changes: 19 additions & 12 deletions web3/txpool.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
from web3.module import (
Module,
from web3.method import (
Method,
)


class TxPool(Module):
@property
def content(self):
return self.web3.manager.request_blocking("txpool_content", [])
def content():
return Method(
"txpool_content",
mungers=None,
)

@property
def inspect(self):
return self.web3.manager.request_blocking("txpool_inspect", [])

@property
def status(self):
return self.web3.manager.request_blocking("txpool_status", [])
def inspect():
return Method(
"txpool_inspect",
mungers=None,
)


def status():
return Method(
"txpool_status",
mungers=None,
)

0 comments on commit 4481263

Please sign in to comment.