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 (
147+ result = self .web3 .manager .request_blocking (
146148 method ,
147149 [block_identifier , full_transactions ],
148150 )
151+ if result is None :
152+ raise BlockNotFound (f"Block with id: { block_identifier } not found." )
153+ return result
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 (
166+ result = self .web3 .manager .request_blocking (
162167 method ,
163168 [block_identifier ],
164169 )
170+ if result is None :
171+ raise BlockNotFound (f"Block with id: { block_identifier } not found." )
172+ return result
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 (
185+ result = self .web3 .manager .request_blocking (
178186 method ,
179187 [block_identifier ],
180188 )
189+ if result is None :
190+ raise BlockNotFound (f"Block with id: { block_identifier } not found." )
191+ return result
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 (
204+ result = self .web3 .manager .request_blocking (
194205 method ,
195206 [block_identifier , uncle_index ],
196207 )
208+ if result is None :
209+ raise BlockNotFound (
210+ f"Uncle at index: { uncle_index } of block with id: { block_identifier } not found."
211+ )
212+ return result
197213
198214 def getTransaction (self , transaction_hash ):
199- return self .web3 .manager .request_blocking (
215+ result = self .web3 .manager .request_blocking (
200216 "eth_getTransactionByHash" ,
201217 [transaction_hash ],
202218 )
219+ if result is None :
220+ raise TransactionNotFound (f"Transaction with hash: { transaction_hash } not found." )
221+ return result
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 (
242+ result = self .web3 .manager .request_blocking (
224243 method ,
225244 [block_identifier , transaction_index ],
226245 )
246+ if result is None :
247+ raise TransactionNotFound (
248+ f"Transaction index: { transaction_index } "
249+ f"on block id: { block_identifier } not found."
250+ )
251+ return result
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 (
265+ result = self .web3 .manager .request_blocking (
241266 "eth_getTransactionReceipt" ,
242267 [transaction_hash ],
243268 )
269+ if result is None :
270+ raise TransactionNotFound (f"Transaction with hash: { transaction_hash } not found." )
271+ return result
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