diff --git a/docs/web3.eth.rst b/docs/web3.eth.rst index 873090aa47..f36780da58 100644 --- a/docs/web3.eth.rst +++ b/docs/web3.eth.rst @@ -825,6 +825,20 @@ with the filtering API. 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 --------- diff --git a/tests/integration/test_ethereum_tester.py b/tests/integration/test_ethereum_tester.py index d3e0c3fc82..b18313a9b2 100644 --- a/tests/integration/test_ethereum_tester.py +++ b/tests/integration/test_ethereum_tester.py @@ -217,6 +217,7 @@ def func_wrapper(self, eth_tester, *args, **kwargs): class TestEthereumTesterEthModule(EthModuleTest): test_eth_sign = not_implemented(EthModuleTest.test_eth_sign, 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): diff --git a/web3/_utils/module_testing/eth_module.py b/web3/_utils/module_testing/eth_module.py index d024c4d180..9e02f7144b 100644 --- a/web3/_utils/module_testing/eth_module.py +++ b/web3/_utils/module_testing/eth_module.py @@ -816,3 +816,10 @@ def test_eth_submitHashrate(self, web3): 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 diff --git a/web3/_utils/rpc_abi.py b/web3/_utils/rpc_abi.py index aa31a91803..3ef21b14b0 100644 --- a/web3/_utils/rpc_abi.py +++ b/web3/_utils/rpc_abi.py @@ -51,7 +51,8 @@ 'eth_sendRawTransaction': ['bytes'], 'eth_sendTransaction': TRANSACTION_PARAMS_ABIS, 'eth_sign': ['address', 'bytes'], - 'eth_submitHashrate': ['uint', None], + 'eth_submitHashrate': ['uint', 'bytes'], + 'eth_submitWork': ['bytes8', 'bytes32', 'bytes32'], # personal 'personal_sendTransaction': TRANSACTION_PARAMS_ABIS, 'personal_lockAccount': ['address'], diff --git a/web3/eth.py b/web3/eth.py index 3708959a05..502a92d4fd 100644 --- a/web3/eth.py +++ b/web3/eth.py @@ -395,6 +395,11 @@ def submitHashrate(self, hashrate, node_id): "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], diff --git a/web3/middleware/pythonic.py b/web3/middleware/pythonic.py index b7df3724f9..d04e99326b 100644 --- a/web3/middleware/pythonic.py +++ b/web3/middleware/pythonic.py @@ -254,6 +254,15 @@ def to_hexbytes(num_bytes, val, variable_length=False): ) +def nonce_formatter(nonce): + """ + Convert integer to hex and pad to length 16. + """ + hex_nonce = remove_0x_prefix(integer_to_hex(nonce)) + pad_value = 16 - len(hex_nonce) + return "0x" + "0" * pad_value + hex_nonce + + pythonic_middleware = construct_formatting_middleware( request_formatters={ # Eth @@ -287,7 +296,12 @@ def to_hexbytes(num_bytes, val, variable_length=False): (estimate_gas_with_block_id, is_length(2)), )), 'eth_sendTransaction': apply_formatter_at_index(transaction_param_formatter, 0), - 'eth_submitHashrate': apply_formatter_at_index(hexstr_if_str(to_hex), 1), + # 'eth_submitHashrate': apply_formatter_at_index(hexstr_if_str(to_hex), 1), + # 'eth_submitWork': compose( + # apply_formatter_at_index(nonce_formatter, 0), + # apply_formatter_at_index(hexstr_if_str(to_hex), 1), + # apply_formatter_at_index(hexstr_if_str(to_hex), 2), + # ), # personal 'personal_importRawKey': apply_formatter_at_index( compose(remove_0x_prefix, hexstr_if_str(to_hex)),