We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Changes to web3.eth.estimateGas
Check whether 'from' parameter is already in transaction and use it. Otherwise use defaultAccount.
Basically to implement the same behavior as for 'sendTransaction'.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `web3/eth.py`
Content:
```
1 from __future__ import unicode_literals
2 
3 from cytoolz import compose
4 from cytoolz.dicttoolz import (
5     assoc,
6 )
7 
8 from eth_utils import (
9     is_address,
10     is_string,
11     keccak,
12 )
13 
14 from web3.iban import Iban
15 
16 from web3.contract import (
17     Contract,
18 )
19 from web3.module import (
20     Module,
21 )
22 
23 from web3.utils.blocks import (
24     select_method_for_block_identifier,
25 )
26 from web3.utils.signing import (
27     signature_wrapper,
28 )
29 from web3.utils.empty import (
30     empty,
31 )
32 from web3.utils.encoding import (
33     to_bytes,
34     to_hex,
35 )
36 from web3.utils.filters import (
37     BlockFilter,
38     TransactionFilter,
39     LogFilter,
40 )
41 from web3.utils.transactions import (
42     get_buffered_gas_estimate,
43 )
44 from web3.utils.validation import (
45     validate_address,
46     validate_address_checksum,
47 )
48 
49 
50 class Eth(Module):
51     defaultAccount = empty
52     defaultBlock = "latest"
53     defaultContractFactory = Contract
54     iban = Iban
55 
56     def namereg(self):
57         raise NotImplementedError()
58 
59     def icapNamereg(self):
60         raise NotImplementedError()
61 
62     @property
63     def protocolVersion(self):
64         return self.web3.manager.request_blocking("eth_protocolVersion", [])
65 
66     @property
67     def syncing(self):
68         return self.web3.manager.request_blocking("eth_syncing", [])
69 
70     @property
71     def coinbase(self):
72         return self.web3.manager.request_blocking("eth_coinbase", [])
73 
74     @property
75     def mining(self):
76         return self.web3.manager.request_blocking("eth_mining", [])
77 
78     @property
79     def hashrate(self):
80         return self.web3.manager.request_blocking("eth_hashrate", [])
81 
82     @property
83     def gasPrice(self):
84         return self.web3.manager.request_blocking("eth_gasPrice", [])
85 
86     @property
87     def accounts(self):
88         return self.web3.manager.request_blocking("eth_accounts", [])
89 
90     @property
91     def blockNumber(self):
92         return self.web3.manager.request_blocking("eth_blockNumber", [])
93 
94     def getBalance(self, account, block_identifier=None):
95         if block_identifier is None:
96             block_identifier = self.defaultBlock
97         return self.web3.manager.request_blocking(
98             "eth_getBalance",
99             [account, block_identifier],
100         )
101 
102     def getStorageAt(self, account, position, block_identifier=None):
103         if block_identifier is None:
104             block_identifier = self.defaultBlock
105         return self.web3.manager.request_blocking(
106             "eth_getStorageAt",
107             [account, position, block_identifier]
108         )
109 
110     def getCode(self, account, block_identifier=None):
111         if block_identifier is None:
112             block_identifier = self.defaultBlock
113         return self.web3.manager.request_blocking(
114             "eth_getCode",
115             [account, block_identifier],
116         )
117 
118     def getBlock(self, block_identifier, full_transactions=False):
119         """
120         `eth_getBlockByHash`
121         `eth_getBlockByNumber`
122         """
123         method = select_method_for_block_identifier(
124             block_identifier,
125             if_predefined='eth_getBlockByNumber',
126             if_hash='eth_getBlockByHash',
127             if_number='eth_getBlockByNumber',
128         )
129 
130         return self.web3.manager.request_blocking(
131             method,
132             [block_identifier, full_transactions],
133         )
134 
135     def getBlockTransactionCount(self, block_identifier):
136         """
137         `eth_getBlockTransactionCountByHash`
138         `eth_getBlockTransactionCountByNumber`
139         """
140         method = select_method_for_block_identifier(
141             block_identifier,
142             if_predefined='eth_getBlockTransactionCountByNumber',
143             if_hash='eth_getBlockTransactionCountByHash',
144             if_number='eth_getBlockTransactionCountByNumber',
145         )
146         return self.web3.manager.request_blocking(
147             method,
148             [block_identifier],
149         )
150 
151     def getUncleCount(self, block_identifier):
152         """
153         `eth_getUncleCountByBlockHash`
154         `eth_getUncleCountByBlockNumber`
155         """
156         method = select_method_for_block_identifier(
157             block_identifier,
158             if_predefined='eth_getUncleCountByBlockNumber',
159             if_hash='eth_getUncleCountByBlockHash',
160             if_number='eth_getUncleCountByBlockNumber',
161         )
162         return self.web3.manager.request_blocking(
163             method,
164             [block_identifier],
165         )
166 
167     def getTransaction(self, transaction_hash):
168         return self.web3.manager.request_blocking(
169             "eth_getTransactionByHash",
170             [transaction_hash],
171         )
172 
173     def getTransactionFromBlock(self, block_identifier, transaction_index):
174         """
175         `eth_getTransactionByBlockHashAndIndex`
176         `eth_getTransactionByBlockNumberAndIndex`
177         """
178         method = select_method_for_block_identifier(
179             block_identifier,
180             if_predefined='eth_getTransactionByBlockNumberAndIndex',
181             if_hash='eth_getTransactionByBlockHashAndIndex',
182             if_number='eth_getTransactionByBlockNumberAndIndex',
183         )
184         return self.web3.manager.request_blocking(
185             method,
186             [block_identifier, transaction_index],
187         )
188 
189     def getTransactionReceipt(self, transaction_hash):
190         return self.web3.manager.request_blocking(
191             "eth_getTransactionReceipt",
192             [transaction_hash],
193         )
194 
195     def getTransactionCount(self, account, block_identifier=None):
196         if block_identifier is None:
197             block_identifier = self.defaultBlock
198         return self.web3.manager.request_blocking(
199             "eth_getTransactionCount",
200             [
201                 account,
202                 block_identifier,
203             ],
204         )
205 
206     def sendTransaction(self, transaction):
207         # TODO: move to middleware
208         if 'from' not in transaction and is_address(self.defaultAccount):
209             transaction = assoc(transaction, 'from', self.defaultAccount)
210 
211         # TODO: move gas estimation in middleware
212         if 'gas' not in transaction:
213             transaction = assoc(
214                 transaction,
215                 'gas',
216                 get_buffered_gas_estimate(self.web3, transaction),
217             )
218 
219         return self.web3.manager.request_blocking(
220             "eth_sendTransaction",
221             [transaction],
222         )
223 
224     def sendRawTransaction(self, raw_transaction):
225         return self.web3.manager.request_blocking(
226             "eth_sendRawTransaction",
227             [raw_transaction],
228         )
229 
230     def sign(self, account, data=None, hexstr=None, text=None):
231         message_hex = to_hex(data, hexstr=hexstr, text=text)
232         return self.web3.manager.request_blocking(
233             "eth_sign", [account, message_hex],
234         )
235 
236     @staticmethod
237     def _recoveryMessageHash(data=None, hexstr=None, text=None):
238         message_bytes = to_bytes(data, hexstr=hexstr, text=text)
239         recovery_hasher = compose(to_hex, keccak, signature_wrapper)
240         return recovery_hasher(message_bytes)
241 
242     def call(self, transaction, block_identifier=None):
243         # TODO: move to middleware
244         if 'from' not in transaction and is_address(self.defaultAccount):
245             transaction = assoc(transaction, 'from', self.defaultAccount)
246 
247         # TODO: move to middleware
248         if block_identifier is None:
249             block_identifier = self.defaultBlock
250 
251         return self.web3.manager.request_blocking(
252             "eth_call",
253             [transaction, block_identifier],
254         )
255 
256     def estimateGas(self, transaction):
257         # TODO: move to middleware
258         if is_address(self.defaultAccount):
259             transaction = assoc(transaction, 'from', self.defaultAccount)
260 
261         return self.web3.manager.request_blocking(
262             "eth_estimateGas",
263             [transaction],
264         )
265 
266     def filter(self, filter_params):
267         if is_string(filter_params):
268             if filter_params == "latest":
269                 filter_id = self.web3.manager.request_blocking(
270                     "eth_newBlockFilter", [],
271                 )
272                 return BlockFilter(self.web3, filter_id)
273             elif filter_params == "pending":
274                 filter_id = self.web3.manager.request_blocking(
275                     "eth_newPendingTransactionFilter", [],
276                 )
277                 return TransactionFilter(self.web3, filter_id)
278             else:
279                 raise ValueError(
280                     "The filter API only accepts the values of `pending` or "
281                     "`latest` for string based filters"
282                 )
283         elif isinstance(filter_params, dict):
284             filter_id = self.web3.manager.request_blocking(
285                 "eth_newFilter",
286                 [filter_params],
287             )
288             return LogFilter(self.web3, filter_id)
289         else:
290             raise ValueError("Must provide either a string or a valid filter object")
291 
292     def getFilterChanges(self, filter_id):
293         return self.web3.manager.request_blocking(
294             "eth_getFilterChanges", [filter_id],
295         )
296 
297     def getFilterLogs(self, filter_id):
298         return self.web3.manager.request_blocking(
299             "eth_getFilterLogs", [filter_id],
300         )
301 
302     def getLogs(self, filter_params):
303         raise NotImplementedError("Not yet implemented")
304 
305     def uninstallFilter(self, filter_id):
306         return self.web3.manager.request_blocking(
307             "eth_uninstallFilter", [filter_id],
308         )
309 
310     def contract(self,
311                  *args,
312                  **kwargs):
313         ContractFactoryClass = kwargs.pop('ContractFactoryClass', self.defaultContractFactory)
314         contract_name = kwargs.pop('contract_name', None)
315 
316         has_address = any((
317             'address' in kwargs,
318             len(args) >= 1 and is_address(args[0]),
319             len(args) >= 2 and is_address(args[1]),
320         ))
321 
322         for potential_address in args:
323             validate_address_checksum(potential_address)
324 
325         if has_address:
326             if 'address' in kwargs:
327                 address = kwargs.pop('address')
328             elif is_address(args[0]):
329                 address = args[0]
330             elif is_address(args[1]):
331                 address = args[1]
332                 kwargs['abi'] = args[0]
333             validate_address(address)
334 
335             return ContractFactoryClass.factory(self.web3, contract_name, **kwargs)(address)
336         else:
337             try:
338                 kwargs['abi'] = args[0]
339             except IndexError:
340                 pass
341             return ContractFactoryClass.factory(self.web3, contract_name, **kwargs)
342 
343     def setContractFactory(self, contractFactory):
344         self.defaultContractFactory = contractFactory
345 
346     def getCompilers(self):
347         return self.web3.manager.request_blocking("eth_getCompilers", [])
348 
349     def getWork(self):
350         return self.web3.manager.request_blocking("eth_getWork", [])
351
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/web3/eth.py b/web3/eth.py
--- a/web3/eth.py
+++ b/web3/eth.py
@@ -255,7 +255,7 @@
 
     def estimateGas(self, transaction):
         # TODO: move to middleware
-        if is_address(self.defaultAccount):
+        if 'from' not in transaction and is_address(self.defaultAccount):
             transaction = assoc(transaction, 'from', self.defaultAccount)
 
         return self.web3.manager.request_blocking(

{"golden_diff": "diff --git a/web3/eth.py b/web3/eth.py\n--- a/web3/eth.py\n+++ b/web3/eth.py\n@@ -255,7 +255,7 @@\n \n     def estimateGas(self, transaction):\n         # TODO: move to middleware\n-        if is_address(self.defaultAccount):\n+        if 'from' not in transaction and is_address(self.defaultAccount):\n             transaction = assoc(transaction, 'from', self.defaultAccount)\n \n         return self.web3.manager.request_blocking(\n", "issue": "Changes to web3.eth.estimateGas\nCheck whether 'from' parameter is already in transaction and use it. Otherwise use defaultAccount.\r\nBasically to implement the same behavior as for 'sendTransaction'.\r\n\n", "before_files": [{"content": "from __future__ import unicode_literals\n\nfrom cytoolz import compose\nfrom cytoolz.dicttoolz import (\n    assoc,\n)\n\nfrom eth_utils import (\n    is_address,\n    is_string,\n    keccak,\n)\n\nfrom web3.iban import Iban\n\nfrom web3.contract import (\n    Contract,\n)\nfrom web3.module import (\n    Module,\n)\n\nfrom web3.utils.blocks import (\n    select_method_for_block_identifier,\n)\nfrom web3.utils.signing import (\n    signature_wrapper,\n)\nfrom web3.utils.empty import (\n    empty,\n)\nfrom web3.utils.encoding import (\n    to_bytes,\n    to_hex,\n)\nfrom web3.utils.filters import (\n    BlockFilter,\n    TransactionFilter,\n    LogFilter,\n)\nfrom web3.utils.transactions import (\n    get_buffered_gas_estimate,\n)\nfrom web3.utils.validation import (\n    validate_address,\n    validate_address_checksum,\n)\n\n\nclass Eth(Module):\n    defaultAccount = empty\n    defaultBlock = \"latest\"\n    defaultContractFactory = Contract\n    iban = Iban\n\n    def namereg(self):\n        raise NotImplementedError()\n\n    def icapNamereg(self):\n        raise NotImplementedError()\n\n    @property\n    def protocolVersion(self):\n        return self.web3.manager.request_blocking(\"eth_protocolVersion\", [])\n\n    @property\n    def syncing(self):\n        return self.web3.manager.request_blocking(\"eth_syncing\", [])\n\n    @property\n    def coinbase(self):\n        return self.web3.manager.request_blocking(\"eth_coinbase\", [])\n\n    @property\n    def mining(self):\n        return self.web3.manager.request_blocking(\"eth_mining\", [])\n\n    @property\n    def hashrate(self):\n        return self.web3.manager.request_blocking(\"eth_hashrate\", [])\n\n    @property\n    def gasPrice(self):\n        return self.web3.manager.request_blocking(\"eth_gasPrice\", [])\n\n    @property\n    def accounts(self):\n        return self.web3.manager.request_blocking(\"eth_accounts\", [])\n\n    @property\n    def blockNumber(self):\n        return self.web3.manager.request_blocking(\"eth_blockNumber\", [])\n\n    def getBalance(self, account, block_identifier=None):\n        if block_identifier is None:\n            block_identifier = self.defaultBlock\n        return self.web3.manager.request_blocking(\n            \"eth_getBalance\",\n            [account, block_identifier],\n        )\n\n    def getStorageAt(self, account, position, block_identifier=None):\n        if block_identifier is None:\n            block_identifier = self.defaultBlock\n        return self.web3.manager.request_blocking(\n            \"eth_getStorageAt\",\n            [account, position, block_identifier]\n        )\n\n    def getCode(self, account, block_identifier=None):\n        if block_identifier is None:\n            block_identifier = self.defaultBlock\n        return self.web3.manager.request_blocking(\n            \"eth_getCode\",\n            [account, block_identifier],\n        )\n\n    def getBlock(self, block_identifier, full_transactions=False):\n        \"\"\"\n        `eth_getBlockByHash`\n        `eth_getBlockByNumber`\n        \"\"\"\n        method = select_method_for_block_identifier(\n            block_identifier,\n            if_predefined='eth_getBlockByNumber',\n            if_hash='eth_getBlockByHash',\n            if_number='eth_getBlockByNumber',\n        )\n\n        return self.web3.manager.request_blocking(\n            method,\n            [block_identifier, full_transactions],\n        )\n\n    def getBlockTransactionCount(self, block_identifier):\n        \"\"\"\n        `eth_getBlockTransactionCountByHash`\n        `eth_getBlockTransactionCountByNumber`\n        \"\"\"\n        method = select_method_for_block_identifier(\n            block_identifier,\n            if_predefined='eth_getBlockTransactionCountByNumber',\n            if_hash='eth_getBlockTransactionCountByHash',\n            if_number='eth_getBlockTransactionCountByNumber',\n        )\n        return self.web3.manager.request_blocking(\n            method,\n            [block_identifier],\n        )\n\n    def getUncleCount(self, block_identifier):\n        \"\"\"\n        `eth_getUncleCountByBlockHash`\n        `eth_getUncleCountByBlockNumber`\n        \"\"\"\n        method = select_method_for_block_identifier(\n            block_identifier,\n            if_predefined='eth_getUncleCountByBlockNumber',\n            if_hash='eth_getUncleCountByBlockHash',\n            if_number='eth_getUncleCountByBlockNumber',\n        )\n        return self.web3.manager.request_blocking(\n            method,\n            [block_identifier],\n        )\n\n    def getTransaction(self, transaction_hash):\n        return self.web3.manager.request_blocking(\n            \"eth_getTransactionByHash\",\n            [transaction_hash],\n        )\n\n    def getTransactionFromBlock(self, block_identifier, transaction_index):\n        \"\"\"\n        `eth_getTransactionByBlockHashAndIndex`\n        `eth_getTransactionByBlockNumberAndIndex`\n        \"\"\"\n        method = select_method_for_block_identifier(\n            block_identifier,\n            if_predefined='eth_getTransactionByBlockNumberAndIndex',\n            if_hash='eth_getTransactionByBlockHashAndIndex',\n            if_number='eth_getTransactionByBlockNumberAndIndex',\n        )\n        return self.web3.manager.request_blocking(\n            method,\n            [block_identifier, transaction_index],\n        )\n\n    def getTransactionReceipt(self, transaction_hash):\n        return self.web3.manager.request_blocking(\n            \"eth_getTransactionReceipt\",\n            [transaction_hash],\n        )\n\n    def getTransactionCount(self, account, block_identifier=None):\n        if block_identifier is None:\n            block_identifier = self.defaultBlock\n        return self.web3.manager.request_blocking(\n            \"eth_getTransactionCount\",\n            [\n                account,\n                block_identifier,\n            ],\n        )\n\n    def sendTransaction(self, transaction):\n        # TODO: move to middleware\n        if 'from' not in transaction and is_address(self.defaultAccount):\n            transaction = assoc(transaction, 'from', self.defaultAccount)\n\n        # TODO: move gas estimation in middleware\n        if 'gas' not in transaction:\n            transaction = assoc(\n                transaction,\n                'gas',\n                get_buffered_gas_estimate(self.web3, transaction),\n            )\n\n        return self.web3.manager.request_blocking(\n            \"eth_sendTransaction\",\n            [transaction],\n        )\n\n    def sendRawTransaction(self, raw_transaction):\n        return self.web3.manager.request_blocking(\n            \"eth_sendRawTransaction\",\n            [raw_transaction],\n        )\n\n    def sign(self, account, data=None, hexstr=None, text=None):\n        message_hex = to_hex(data, hexstr=hexstr, text=text)\n        return self.web3.manager.request_blocking(\n            \"eth_sign\", [account, message_hex],\n        )\n\n    @staticmethod\n    def _recoveryMessageHash(data=None, hexstr=None, text=None):\n        message_bytes = to_bytes(data, hexstr=hexstr, text=text)\n        recovery_hasher = compose(to_hex, keccak, signature_wrapper)\n        return recovery_hasher(message_bytes)\n\n    def call(self, transaction, block_identifier=None):\n        # TODO: move to middleware\n        if 'from' not in transaction and is_address(self.defaultAccount):\n            transaction = assoc(transaction, 'from', self.defaultAccount)\n\n        # TODO: move to middleware\n        if block_identifier is None:\n            block_identifier = self.defaultBlock\n\n        return self.web3.manager.request_blocking(\n            \"eth_call\",\n            [transaction, block_identifier],\n        )\n\n    def estimateGas(self, transaction):\n        # TODO: move to middleware\n        if is_address(self.defaultAccount):\n            transaction = assoc(transaction, 'from', self.defaultAccount)\n\n        return self.web3.manager.request_blocking(\n            \"eth_estimateGas\",\n            [transaction],\n        )\n\n    def filter(self, filter_params):\n        if is_string(filter_params):\n            if filter_params == \"latest\":\n                filter_id = self.web3.manager.request_blocking(\n                    \"eth_newBlockFilter\", [],\n                )\n                return BlockFilter(self.web3, filter_id)\n            elif filter_params == \"pending\":\n                filter_id = self.web3.manager.request_blocking(\n                    \"eth_newPendingTransactionFilter\", [],\n                )\n                return TransactionFilter(self.web3, filter_id)\n            else:\n                raise ValueError(\n                    \"The filter API only accepts the values of `pending` or \"\n                    \"`latest` for string based filters\"\n                )\n        elif isinstance(filter_params, dict):\n            filter_id = self.web3.manager.request_blocking(\n                \"eth_newFilter\",\n                [filter_params],\n            )\n            return LogFilter(self.web3, filter_id)\n        else:\n            raise ValueError(\"Must provide either a string or a valid filter object\")\n\n    def getFilterChanges(self, filter_id):\n        return self.web3.manager.request_blocking(\n            \"eth_getFilterChanges\", [filter_id],\n        )\n\n    def getFilterLogs(self, filter_id):\n        return self.web3.manager.request_blocking(\n            \"eth_getFilterLogs\", [filter_id],\n        )\n\n    def getLogs(self, filter_params):\n        raise NotImplementedError(\"Not yet implemented\")\n\n    def uninstallFilter(self, filter_id):\n        return self.web3.manager.request_blocking(\n            \"eth_uninstallFilter\", [filter_id],\n        )\n\n    def contract(self,\n                 *args,\n                 **kwargs):\n        ContractFactoryClass = kwargs.pop('ContractFactoryClass', self.defaultContractFactory)\n        contract_name = kwargs.pop('contract_name', None)\n\n        has_address = any((\n            'address' in kwargs,\n            len(args) >= 1 and is_address(args[0]),\n            len(args) >= 2 and is_address(args[1]),\n        ))\n\n        for potential_address in args:\n            validate_address_checksum(potential_address)\n\n        if has_address:\n            if 'address' in kwargs:\n                address = kwargs.pop('address')\n            elif is_address(args[0]):\n                address = args[0]\n            elif is_address(args[1]):\n                address = args[1]\n                kwargs['abi'] = args[0]\n            validate_address(address)\n\n            return ContractFactoryClass.factory(self.web3, contract_name, **kwargs)(address)\n        else:\n            try:\n                kwargs['abi'] = args[0]\n            except IndexError:\n                pass\n            return ContractFactoryClass.factory(self.web3, contract_name, **kwargs)\n\n    def setContractFactory(self, contractFactory):\n        self.defaultContractFactory = contractFactory\n\n    def getCompilers(self):\n        return self.web3.manager.request_blocking(\"eth_getCompilers\", [])\n\n    def getWork(self):\n        return self.web3.manager.request_blocking(\"eth_getWork\", [])\n", "path": "web3/eth.py"}], "after_files": [{"content": "from __future__ import unicode_literals\n\nfrom cytoolz import compose\nfrom cytoolz.dicttoolz import (\n    assoc,\n)\n\nfrom eth_utils import (\n    is_address,\n    is_string,\n    keccak,\n)\n\nfrom web3.iban import Iban\n\nfrom web3.contract import (\n    Contract,\n)\nfrom web3.module import (\n    Module,\n)\n\nfrom web3.utils.blocks import (\n    select_method_for_block_identifier,\n)\nfrom web3.utils.signing import (\n    signature_wrapper,\n)\nfrom web3.utils.empty import (\n    empty,\n)\nfrom web3.utils.encoding import (\n    to_bytes,\n    to_hex,\n)\nfrom web3.utils.filters import (\n    BlockFilter,\n    TransactionFilter,\n    LogFilter,\n)\nfrom web3.utils.transactions import (\n    get_buffered_gas_estimate,\n)\nfrom web3.utils.validation import (\n    validate_address,\n    validate_address_checksum,\n)\n\n\nclass Eth(Module):\n    defaultAccount = empty\n    defaultBlock = \"latest\"\n    defaultContractFactory = Contract\n    iban = Iban\n\n    def namereg(self):\n        raise NotImplementedError()\n\n    def icapNamereg(self):\n        raise NotImplementedError()\n\n    @property\n    def protocolVersion(self):\n        return self.web3.manager.request_blocking(\"eth_protocolVersion\", [])\n\n    @property\n    def syncing(self):\n        return self.web3.manager.request_blocking(\"eth_syncing\", [])\n\n    @property\n    def coinbase(self):\n        return self.web3.manager.request_blocking(\"eth_coinbase\", [])\n\n    @property\n    def mining(self):\n        return self.web3.manager.request_blocking(\"eth_mining\", [])\n\n    @property\n    def hashrate(self):\n        return self.web3.manager.request_blocking(\"eth_hashrate\", [])\n\n    @property\n    def gasPrice(self):\n        return self.web3.manager.request_blocking(\"eth_gasPrice\", [])\n\n    @property\n    def accounts(self):\n        return self.web3.manager.request_blocking(\"eth_accounts\", [])\n\n    @property\n    def blockNumber(self):\n        return self.web3.manager.request_blocking(\"eth_blockNumber\", [])\n\n    def getBalance(self, account, block_identifier=None):\n        if block_identifier is None:\n            block_identifier = self.defaultBlock\n        return self.web3.manager.request_blocking(\n            \"eth_getBalance\",\n            [account, block_identifier],\n        )\n\n    def getStorageAt(self, account, position, block_identifier=None):\n        if block_identifier is None:\n            block_identifier = self.defaultBlock\n        return self.web3.manager.request_blocking(\n            \"eth_getStorageAt\",\n            [account, position, block_identifier]\n        )\n\n    def getCode(self, account, block_identifier=None):\n        if block_identifier is None:\n            block_identifier = self.defaultBlock\n        return self.web3.manager.request_blocking(\n            \"eth_getCode\",\n            [account, block_identifier],\n        )\n\n    def getBlock(self, block_identifier, full_transactions=False):\n        \"\"\"\n        `eth_getBlockByHash`\n        `eth_getBlockByNumber`\n        \"\"\"\n        method = select_method_for_block_identifier(\n            block_identifier,\n            if_predefined='eth_getBlockByNumber',\n            if_hash='eth_getBlockByHash',\n            if_number='eth_getBlockByNumber',\n        )\n\n        return self.web3.manager.request_blocking(\n            method,\n            [block_identifier, full_transactions],\n        )\n\n    def getBlockTransactionCount(self, block_identifier):\n        \"\"\"\n        `eth_getBlockTransactionCountByHash`\n        `eth_getBlockTransactionCountByNumber`\n        \"\"\"\n        method = select_method_for_block_identifier(\n            block_identifier,\n            if_predefined='eth_getBlockTransactionCountByNumber',\n            if_hash='eth_getBlockTransactionCountByHash',\n            if_number='eth_getBlockTransactionCountByNumber',\n        )\n        return self.web3.manager.request_blocking(\n            method,\n            [block_identifier],\n        )\n\n    def getUncleCount(self, block_identifier):\n        \"\"\"\n        `eth_getUncleCountByBlockHash`\n        `eth_getUncleCountByBlockNumber`\n        \"\"\"\n        method = select_method_for_block_identifier(\n            block_identifier,\n            if_predefined='eth_getUncleCountByBlockNumber',\n            if_hash='eth_getUncleCountByBlockHash',\n            if_number='eth_getUncleCountByBlockNumber',\n        )\n        return self.web3.manager.request_blocking(\n            method,\n            [block_identifier],\n        )\n\n    def getTransaction(self, transaction_hash):\n        return self.web3.manager.request_blocking(\n            \"eth_getTransactionByHash\",\n            [transaction_hash],\n        )\n\n    def getTransactionFromBlock(self, block_identifier, transaction_index):\n        \"\"\"\n        `eth_getTransactionByBlockHashAndIndex`\n        `eth_getTransactionByBlockNumberAndIndex`\n        \"\"\"\n        method = select_method_for_block_identifier(\n            block_identifier,\n            if_predefined='eth_getTransactionByBlockNumberAndIndex',\n            if_hash='eth_getTransactionByBlockHashAndIndex',\n            if_number='eth_getTransactionByBlockNumberAndIndex',\n        )\n        return self.web3.manager.request_blocking(\n            method,\n            [block_identifier, transaction_index],\n        )\n\n    def getTransactionReceipt(self, transaction_hash):\n        return self.web3.manager.request_blocking(\n            \"eth_getTransactionReceipt\",\n            [transaction_hash],\n        )\n\n    def getTransactionCount(self, account, block_identifier=None):\n        if block_identifier is None:\n            block_identifier = self.defaultBlock\n        return self.web3.manager.request_blocking(\n            \"eth_getTransactionCount\",\n            [\n                account,\n                block_identifier,\n            ],\n        )\n\n    def sendTransaction(self, transaction):\n        # TODO: move to middleware\n        if 'from' not in transaction and is_address(self.defaultAccount):\n            transaction = assoc(transaction, 'from', self.defaultAccount)\n\n        # TODO: move gas estimation in middleware\n        if 'gas' not in transaction:\n            transaction = assoc(\n                transaction,\n                'gas',\n                get_buffered_gas_estimate(self.web3, transaction),\n            )\n\n        return self.web3.manager.request_blocking(\n            \"eth_sendTransaction\",\n            [transaction],\n        )\n\n    def sendRawTransaction(self, raw_transaction):\n        return self.web3.manager.request_blocking(\n            \"eth_sendRawTransaction\",\n            [raw_transaction],\n        )\n\n    def sign(self, account, data=None, hexstr=None, text=None):\n        message_hex = to_hex(data, hexstr=hexstr, text=text)\n        return self.web3.manager.request_blocking(\n            \"eth_sign\", [account, message_hex],\n        )\n\n    @staticmethod\n    def _recoveryMessageHash(data=None, hexstr=None, text=None):\n        message_bytes = to_bytes(data, hexstr=hexstr, text=text)\n        recovery_hasher = compose(to_hex, keccak, signature_wrapper)\n        return recovery_hasher(message_bytes)\n\n    def call(self, transaction, block_identifier=None):\n        # TODO: move to middleware\n        if 'from' not in transaction and is_address(self.defaultAccount):\n            transaction = assoc(transaction, 'from', self.defaultAccount)\n\n        # TODO: move to middleware\n        if block_identifier is None:\n            block_identifier = self.defaultBlock\n\n        return self.web3.manager.request_blocking(\n            \"eth_call\",\n            [transaction, block_identifier],\n        )\n\n    def estimateGas(self, transaction):\n        # TODO: move to middleware\n        if 'from' not in transaction and is_address(self.defaultAccount):\n            transaction = assoc(transaction, 'from', self.defaultAccount)\n\n        return self.web3.manager.request_blocking(\n            \"eth_estimateGas\",\n            [transaction],\n        )\n\n    def filter(self, filter_params):\n        if is_string(filter_params):\n            if filter_params == \"latest\":\n                filter_id = self.web3.manager.request_blocking(\n                    \"eth_newBlockFilter\", [],\n                )\n                return BlockFilter(self.web3, filter_id)\n            elif filter_params == \"pending\":\n                filter_id = self.web3.manager.request_blocking(\n                    \"eth_newPendingTransactionFilter\", [],\n                )\n                return TransactionFilter(self.web3, filter_id)\n            else:\n                raise ValueError(\n                    \"The filter API only accepts the values of `pending` or \"\n                    \"`latest` for string based filters\"\n                )\n        elif isinstance(filter_params, dict):\n            filter_id = self.web3.manager.request_blocking(\n                \"eth_newFilter\",\n                [filter_params],\n            )\n            return LogFilter(self.web3, filter_id)\n        else:\n            raise ValueError(\"Must provide either a string or a valid filter object\")\n\n    def getFilterChanges(self, filter_id):\n        return self.web3.manager.request_blocking(\n            \"eth_getFilterChanges\", [filter_id],\n        )\n\n    def getFilterLogs(self, filter_id):\n        return self.web3.manager.request_blocking(\n            \"eth_getFilterLogs\", [filter_id],\n        )\n\n    def getLogs(self, filter_params):\n        raise NotImplementedError(\"Not yet implemented\")\n\n    def uninstallFilter(self, filter_id):\n        return self.web3.manager.request_blocking(\n            \"eth_uninstallFilter\", [filter_id],\n        )\n\n    def contract(self,\n                 *args,\n                 **kwargs):\n        ContractFactoryClass = kwargs.pop('ContractFactoryClass', self.defaultContractFactory)\n        contract_name = kwargs.pop('contract_name', None)\n\n        has_address = any((\n            'address' in kwargs,\n            len(args) >= 1 and is_address(args[0]),\n            len(args) >= 2 and is_address(args[1]),\n        ))\n\n        for potential_address in args:\n            validate_address_checksum(potential_address)\n\n        if has_address:\n            if 'address' in kwargs:\n                address = kwargs.pop('address')\n            elif is_address(args[0]):\n                address = args[0]\n            elif is_address(args[1]):\n                address = args[1]\n                kwargs['abi'] = args[0]\n            validate_address(address)\n\n            return ContractFactoryClass.factory(self.web3, contract_name, **kwargs)(address)\n        else:\n            try:\n                kwargs['abi'] = args[0]\n            except IndexError:\n                pass\n            return ContractFactoryClass.factory(self.web3, contract_name, **kwargs)\n\n    def setContractFactory(self, contractFactory):\n        self.defaultContractFactory = contractFactory\n\n    def getCompilers(self):\n        return self.web3.manager.request_blocking(\"eth_getCompilers\", [])\n\n    def getWork(self):\n        return self.web3.manager.request_blocking(\"eth_getWork\", [])\n", "path": "web3/eth.py"}]}