Skip to content

Commit

Permalink
Merge pull request #1280 from njgheorghita/eth_submitHashrate
Browse files Browse the repository at this point in the history
Implement eth_submitHashrate and eth_submitWork
  • Loading branch information
njgheorghita authored Mar 15, 2019
2 parents 5057d20 + fa9207e commit 86c4457
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Unreleased (latest source)
--------------------------
- Remove ``web3/utils`` directory in favor of ``web3/_utils``
- `#1282 <https://github.com/ethereum/web3.py/pull/1282>`_
- Implement ``eth_submitHashrate`` and ``eth_submitWork`` JSONRPC endpoints.
- `#1280 <https://github.com/ethereum/web3.py/pull/1280>`_

v5.0.0-alpha.7
--------------
Expand Down
25 changes: 25 additions & 0 deletions docs/web3.eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,31 @@ with the filtering API.
:meth:`~Eth.filter` for details on allowed filter parameters.


.. py:method:: Eth.submitHashrate(hashrate, nodeid)
* Delegates to ``eth_submitHashrate`` RPC Method

.. code-block:: python
>>> node_id = '59daa26581d0acd1fce254fb7e85952f4c09d0915afd33d3886cd914bc7d283c'
>>> web3.eth.submitHashrate(5000, node_id)
True
.. py:method:: Eth.submitWork(nonce, pow_hash, mix_digest)
* Delegates to ``eth_submitWork`` RPC Method.

.. code-block:: python
>>> web3.eth.submitWork(
1,
'0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
'0xD1FE5700000000000000000000000000D1FE5700000000000000000000000000',
)
True
Contracts
---------

Expand Down
2 changes: 2 additions & 0 deletions tests/integration/test_ethereum_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ def func_wrapper(self, eth_tester, *args, **kwargs):
class TestEthereumTesterEthModule(EthModuleTest):
test_eth_sign = not_implemented(EthModuleTest.test_eth_sign, ValueError)
test_eth_signTransaction = not_implemented(EthModuleTest.test_eth_signTransaction, ValueError)
test_eth_submitHashrate = not_implemented(EthModuleTest.test_eth_submitHashrate, ValueError)
test_eth_submitWork = not_implemented(EthModuleTest.test_eth_submitWork, ValueError)

@disable_auto_mine
def test_eth_getTransactionReceipt_unmined(self, eth_tester, web3, unlocked_account):
Expand Down
13 changes: 13 additions & 0 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,3 +832,16 @@ def test_eth_getTransactionFromBlock_deprecation(self, web3, block_with_txn):
def test_eth_getCompilers_deprecation(self, web3):
with pytest.raises(DeprecationWarning):
web3.eth.getCompilers()

def test_eth_submitHashrate(self, web3):
# node_id from EIP 1474: https://github.com/ethereum/EIPs/pull/1474/files
node_id = '59daa26581d0acd1fce254fb7e85952f4c09d0915afd33d3886cd914bc7d283c'
result = web3.eth.submitHashrate(5000, node_id)
assert result is True

def test_eth_submitWork(self, web3):
nonce = 1
pow_hash = '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'
mix_digest = '0xD1FE5700000000000000000000000000D1FE5700000000000000000000000000'
result = web3.eth.submitWork(nonce, pow_hash, mix_digest)
assert result is False
2 changes: 2 additions & 0 deletions web3/_utils/rpc_abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
'eth_sendTransaction': TRANSACTION_PARAMS_ABIS,
'eth_signTransaction': TRANSACTION_PARAMS_ABIS,
'eth_sign': ['address', 'bytes'],
'eth_submitHashrate': ['uint', 'bytes32'],
'eth_submitWork': ['bytes8', 'bytes32', 'bytes32'],
# personal
'personal_sendTransaction': TRANSACTION_PARAMS_ABIS,
'personal_lockAccount': ['address'],
Expand Down
10 changes: 10 additions & 0 deletions web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,16 @@ def getLogs(self, filter_params):
"eth_getLogs", [filter_params],
)

def submitHashrate(self, hashrate, node_id):
return self.web3.manager.request_blocking(
"eth_submitHashrate", [hashrate, node_id],
)

def submitWork(self, nonce, pow_hash, mix_digest):
return self.web3.manager.request_blocking(
"eth_submitWork", [nonce, pow_hash, mix_digest],
)

def uninstallFilter(self, filter_id):
return self.web3.manager.request_blocking(
"eth_uninstallFilter", [filter_id],
Expand Down

0 comments on commit 86c4457

Please sign in to comment.