4646 Contract ,
4747)
4848from web3 .exceptions import (
49+ BlockNotFound ,
4950 TimeExhausted ,
51+ TransactionNotFound ,
5052)
5153from web3 .iban import (
5254 Iban ,
@@ -142,10 +144,13 @@ def getBlock(self, block_identifier, full_transactions=False):
142144 if_number = 'eth_getBlockByNumber' ,
143145 )
144146
145- return self .web3 .manager .request_blocking (
146- method ,
147- [block_identifier , full_transactions ],
148- )
147+ try :
148+ return self .web3 .manager .request_blocking (
149+ method ,
150+ [block_identifier , full_transactions ],
151+ )
152+ except ValueError :
153+ raise BlockNotFound (f"Block with id: { block_identifier } not found." )
149154
150155 def getBlockTransactionCount (self , block_identifier ):
151156 """
@@ -158,10 +163,13 @@ def getBlockTransactionCount(self, block_identifier):
158163 if_hash = 'eth_getBlockTransactionCountByHash' ,
159164 if_number = 'eth_getBlockTransactionCountByNumber' ,
160165 )
161- return self .web3 .manager .request_blocking (
162- method ,
163- [block_identifier ],
164- )
166+ try :
167+ return self .web3 .manager .request_blocking (
168+ method ,
169+ [block_identifier ],
170+ )
171+ except ValueError :
172+ raise BlockNotFound (f"Block with id: { block_identifier } not found." )
165173
166174 def getUncleCount (self , block_identifier ):
167175 """
@@ -174,10 +182,13 @@ def getUncleCount(self, block_identifier):
174182 if_hash = 'eth_getUncleCountByBlockHash' ,
175183 if_number = 'eth_getUncleCountByBlockNumber' ,
176184 )
177- return self .web3 .manager .request_blocking (
178- method ,
179- [block_identifier ],
180- )
185+ try :
186+ return self .web3 .manager .request_blocking (
187+ method ,
188+ [block_identifier ],
189+ )
190+ except ValueError :
191+ raise BlockNotFound (f"Block with id: { block_identifier } not found." )
181192
182193 def getUncleByBlock (self , block_identifier , uncle_index ):
183194 """
@@ -190,16 +201,24 @@ def getUncleByBlock(self, block_identifier, uncle_index):
190201 if_hash = 'eth_getUncleByBlockHashAndIndex' ,
191202 if_number = 'eth_getUncleByBlockNumberAndIndex' ,
192203 )
193- return self .web3 .manager .request_blocking (
194- method ,
195- [block_identifier , uncle_index ],
196- )
204+ try :
205+ return self .web3 .manager .request_blocking (
206+ method ,
207+ [block_identifier , uncle_index ],
208+ )
209+ except ValueError :
210+ raise BlockNotFound (
211+ f"Uncle at index: { uncle_index } of block with id: { block_identifier } not found."
212+ )
197213
198214 def getTransaction (self , transaction_hash ):
199- return self .web3 .manager .request_blocking (
200- "eth_getTransactionByHash" ,
201- [transaction_hash ],
202- )
215+ try :
216+ return self .web3 .manager .request_blocking (
217+ "eth_getTransactionByHash" ,
218+ [transaction_hash ],
219+ )
220+ except ValueError :
221+ raise TransactionNotFound (f"Transaction with hash: { transaction_hash } not found." )
203222
204223 @deprecated_for ("w3.eth.getTransactionByBlock" )
205224 def getTransactionFromBlock (self , block_identifier , transaction_index ):
@@ -220,10 +239,16 @@ def getTransactionByBlock(self, block_identifier, transaction_index):
220239 if_hash = 'eth_getTransactionByBlockHashAndIndex' ,
221240 if_number = 'eth_getTransactionByBlockNumberAndIndex' ,
222241 )
223- return self .web3 .manager .request_blocking (
224- method ,
225- [block_identifier , transaction_index ],
226- )
242+ try :
243+ return self .web3 .manager .request_blocking (
244+ method ,
245+ [block_identifier , transaction_index ],
246+ )
247+ except ValueError :
248+ raise TransactionNotFound (
249+ f"Transaction index: { transaction_index } "
250+ f"on block id: { block_identifier } not found."
251+ )
227252
228253 def waitForTransactionReceipt (self , transaction_hash , timeout = 120 ):
229254 try :
@@ -237,20 +262,20 @@ def waitForTransactionReceipt(self, transaction_hash, timeout=120):
237262 )
238263
239264 def getTransactionReceipt (self , transaction_hash ):
240- return self .web3 .manager .request_blocking (
241- "eth_getTransactionReceipt" ,
242- [transaction_hash ],
243- )
265+ try :
266+ return self .web3 .manager .request_blocking (
267+ "eth_getTransactionReceipt" ,
268+ [transaction_hash ],
269+ )
270+ except ValueError :
271+ raise TransactionNotFound (f"Transaction with hash: { transaction_hash } not found." )
244272
245273 def getTransactionCount (self , account , block_identifier = None ):
246274 if block_identifier is None :
247275 block_identifier = self .defaultBlock
248276 return self .web3 .manager .request_blocking (
249277 "eth_getTransactionCount" ,
250- [
251- account ,
252- block_identifier ,
253- ],
278+ [account , block_identifier ],
254279 )
255280
256281 def replaceTransaction (self , transaction_hash , new_transaction ):
0 commit comments