1818from web3 .logs import DISCARD
1919
2020from ..types import HistoricalInputQuery , InferenceMode , InferenceResult , ModelOutput , SchedulerParams
21- from ._conversions import convert_array_to_model_output , convert_to_model_input , convert_to_model_output
21+ from ._conversions import convert_array_to_model_output , convert_to_model_input , convert_to_model_output # type: ignore[attr-defined]
2222from ._utils import get_abi , get_bin , run_with_retry
2323
2424DEFAULT_RPC_URL = "https://ogevmdevnet.opengradient.ai"
@@ -57,8 +57,8 @@ def __init__(
5757 self ._wallet_account : LocalAccount = self ._blockchain .eth .account .from_key (private_key )
5858 self ._inference_hub_contract_address = inference_contract_address
5959 self ._api_url = api_url
60- self ._inference_abi = None
61- self ._precompile_abi = None
60+ self ._inference_abi : Optional [ dict ] = None
61+ self ._precompile_abi : Optional [ dict ] = None
6262
6363 @property
6464 def inference_abi (self ) -> dict :
@@ -98,8 +98,12 @@ def infer(
9898 """
9999
100100 def execute_transaction ():
101- contract = self ._blockchain .eth .contract (address = self ._inference_hub_contract_address , abi = self .inference_abi )
102- precompile_contract = self ._blockchain .eth .contract (address = PRECOMPILE_CONTRACT_ADDRESS , abi = self .precompile_abi )
101+ contract = self ._blockchain .eth .contract (
102+ address = Web3 .to_checksum_address (self ._inference_hub_contract_address ), abi = self .inference_abi
103+ )
104+ precompile_contract = self ._blockchain .eth .contract (
105+ address = Web3 .to_checksum_address (PRECOMPILE_CONTRACT_ADDRESS ), abi = self .precompile_abi
106+ )
103107
104108 inference_mode_uint8 = inference_mode .value
105109 converted_model_input = convert_to_model_input (model_input )
@@ -122,7 +126,8 @@ def execute_transaction():
122126
123127 return InferenceResult (tx_hash .hex (), model_output )
124128
125- return run_with_retry (execute_transaction , max_retries )
129+ result : InferenceResult = run_with_retry (execute_transaction , max_retries )
130+ return result
126131
127132 def _send_tx_with_revert_handling (self , run_function ):
128133 """
@@ -161,7 +166,7 @@ def _send_tx_with_revert_handling(self, run_function):
161166 }
162167 )
163168
164- signed_tx = self ._wallet_account .sign_transaction (transaction )
169+ signed_tx = self ._wallet_account .sign_transaction (transaction ) # type: ignore[arg-type]
165170 tx_hash = self ._blockchain .eth .send_raw_transaction (signed_tx .raw_transaction )
166171 tx_receipt = self ._blockchain .eth .wait_for_transaction_receipt (tx_hash , timeout = INFERENCE_TX_TIMEOUT )
167172
@@ -176,7 +181,7 @@ def _send_tx_with_revert_handling(self, run_function):
176181
177182 return tx_hash , tx_receipt
178183
179- def _get_inference_result_from_node (self , inference_id : str , inference_mode : InferenceMode ) -> Dict :
184+ def _get_inference_result_from_node (self , inference_id : str , inference_mode : InferenceMode ) -> Optional [ Dict ] :
180185 """
181186 Get the inference result from node.
182187
@@ -317,7 +322,7 @@ def deploy_transaction():
317322
318323 return tx_receipt .contractAddress
319324
320- contract_address = run_with_retry (deploy_transaction )
325+ contract_address : str = run_with_retry (deploy_transaction )
321326
322327 if scheduler_params :
323328 self ._register_with_scheduler (contract_address , scheduler_params )
@@ -343,7 +348,7 @@ def _register_with_scheduler(self, contract_address: str, scheduler_params: Sche
343348
344349 # Scheduler contract address
345350 scheduler_address = DEFAULT_SCHEDULER_ADDRESS
346- scheduler_contract = self ._blockchain .eth .contract (address = scheduler_address , abi = scheduler_abi )
351+ scheduler_contract = self ._blockchain .eth .contract (address = Web3 . to_checksum_address ( scheduler_address ) , abi = scheduler_abi )
347352
348353 try :
349354 # Register the workflow with the scheduler
@@ -359,7 +364,7 @@ def _register_with_scheduler(self, contract_address: str, scheduler_params: Sche
359364 }
360365 )
361366
362- signed_scheduler_tx = self ._wallet_account .sign_transaction (scheduler_tx )
367+ signed_scheduler_tx = self ._wallet_account .sign_transaction (scheduler_tx ) # type: ignore[arg-type]
363368 scheduler_tx_hash = self ._blockchain .eth .send_raw_transaction (signed_scheduler_tx .raw_transaction )
364369 self ._blockchain .eth .wait_for_transaction_receipt (scheduler_tx_hash , timeout = REGULAR_TX_TIMEOUT )
365370 except Exception as e :
@@ -388,7 +393,8 @@ def read_workflow_result(self, contract_address: str) -> ModelOutput:
388393 # Get the result
389394 result = contract .functions .getInferenceResult ().call ()
390395
391- return convert_array_to_model_output (result )
396+ output : ModelOutput = convert_array_to_model_output (result )
397+ return output
392398
393399 def run_workflow (self , contract_address : str ) -> ModelOutput :
394400 """
@@ -423,17 +429,18 @@ def run_workflow(self, contract_address: str) -> ModelOutput:
423429 }
424430 )
425431
426- signed_txn = self ._wallet_account .sign_transaction (transaction )
432+ signed_txn = self ._wallet_account .sign_transaction (transaction ) # type: ignore[arg-type]
427433 tx_hash = self ._blockchain .eth .send_raw_transaction (signed_txn .raw_transaction )
428434 tx_receipt = self ._blockchain .eth .wait_for_transaction_receipt (tx_hash , timeout = INFERENCE_TX_TIMEOUT )
429435
430- if tx_receipt . status == 0 :
436+ if tx_receipt [ " status" ] == 0 :
431437 raise ContractLogicError (f"Run transaction failed. Receipt: { tx_receipt } " )
432438
433439 # Get the inference result from the contract
434440 result = contract .functions .getInferenceResult ().call ()
435441
436- return convert_array_to_model_output (result )
442+ run_output : ModelOutput = convert_array_to_model_output (result )
443+ return run_output
437444
438445 def read_workflow_history (self , contract_address : str , num_results : int ) -> List [ModelOutput ]:
439446 """
0 commit comments