From 42cbb888cd906732ffffa1c3579feee3cf6c749c Mon Sep 17 00:00:00 2001 From: Tolga Date: Thu, 29 Jun 2023 11:38:45 +0200 Subject: [PATCH] beamer: fix TxReceipt typings --- beamer/agent/chain.py | 12 +++++------- beamer/agent/state_machine.py | 4 ++-- beamer/config/commands.py | 4 ++-- beamer/deploy/util.py | 6 +++--- beamer/events.py | 6 +++--- beamer/middleware.py | 8 ++++---- beamer/util.py | 4 ++-- 7 files changed, 21 insertions(+), 23 deletions(-) diff --git a/beamer/agent/chain.py b/beamer/agent/chain.py index 56b961fad..44e7a511c 100644 --- a/beamer/agent/chain.py +++ b/beamer/agent/chain.py @@ -418,7 +418,7 @@ def fill_request(request: Request, context: Context) -> None: context.logger.info( "Filled request", request=request, - txn_hash=receipt.transactionHash.hex(), # type: ignore + txn_hash=receipt["transactionHash"].hex(), token=token.functions.symbol().call(), ) @@ -452,7 +452,7 @@ def claim_request(request: Request, context: Context) -> None: context.logger.info( "Claimed request", request=request, - txn_hash=receipt.transactionHash.hex(), # type: ignore + txn_hash=receipt["transactionHash"].hex(), ) @@ -520,7 +520,7 @@ def maybe_challenge(claim: Claim, context: Context) -> bool: context.logger.info( "Challenged claim", claim=claim, - txn_hash=receipt.transactionHash.hex(), # type: ignore + txn_hash=receipt["transactionHash"].hex(), ) return True @@ -760,9 +760,7 @@ def _withdraw(claim: Claim, context: Context) -> None: return claim.transaction_pending = True - context.logger.info( - "Withdrew", claim=claim.id, txn_hash=receipt.transactionHash.hex() # type: ignore - ) + context.logger.info("Withdrew", claim=claim.id, txn_hash=receipt["transactionHash"].hex()) def _invalidate(request: Request, claim: Claim, context: Context) -> None: @@ -780,5 +778,5 @@ def _invalidate(request: Request, claim: Claim, context: Context) -> None: request=request.id, fill_id=claim.fill_id, claim=claim.id, - txn_hash=receipt.transactionHash.hex(), # type: ignore + txn_hash=receipt["transactionHash"].hex(), ) diff --git a/beamer/agent/state_machine.py b/beamer/agent/state_machine.py index 40d6a571e..bf9912217 100644 --- a/beamer/agent/state_machine.py +++ b/beamer/agent/state_machine.py @@ -215,7 +215,7 @@ def _handle_request_filled(event: RequestFilled, context: Context) -> HandlerRes filler=event.filler, fill_tx=event.tx_hash, fill_id=event.fill_id, - fill_timestamp=fill_block.timestamp, # type: ignore + fill_timestamp=fill_block["timestamp"], ) except TransitionNotAllowed: return False, None @@ -335,7 +335,7 @@ def _handle_request_resolved(event: RequestResolved, context: Context) -> Handle def _handle_fill_invalidated(event: FillInvalidated, context: Context) -> HandlerResult: fill_block = context.fill_manager.w3.eth.get_block(event.block_number) - timestamp = fill_block.timestamp # type: ignore + timestamp = fill_block["timestamp"] request = context.requests.get(event.request_id) if request is not None: diff --git a/beamer/config/commands.py b/beamer/config/commands.py index a1ae555b5..64fea5356 100644 --- a/beamer/config/commands.py +++ b/beamer/config/commands.py @@ -404,5 +404,5 @@ def write( log.error("Transaction failed", exc=exc) sys.exit(1) else: - txhash = receipt.transactionHash.hex() # type: ignore - log.info("Transaction sent", block=receipt.blockNumber, txhash=txhash) # type: ignore + txhash = receipt["transactionHash"].hex() + log.info("Transaction sent", block=receipt["blockNumber"], txhash=txhash) diff --git a/beamer/deploy/util.py b/beamer/deploy/util.py index bf48ab15d..f42d33489 100644 --- a/beamer/deploy/util.py +++ b/beamer/deploy/util.py @@ -73,11 +73,11 @@ def deploy_contract(web3: Web3, constructor_spec: Union[str, Sequence]) -> Deplo ContractFactory = cast(Contract, web3.eth.contract(abi=data[0], bytecode=data[1])) receipt = _transact(ContractFactory.constructor(*args)) - txhash = encode_hex(receipt.transactionHash) + txhash = encode_hex(receipt["transactionHash"]) - address = receipt.contractAddress + address = receipt["contractAddress"] deployed = cast(DeployedContract, web3.eth.contract(address=address, abi=data[0])) - deployed.deployment_block = receipt.blockNumber + deployed.deployment_block = receipt["blockNumber"] deployed.deployment_txhash = txhash deployed.deployment_args = list(args) deployed.name = name diff --git a/beamer/events.py b/beamer/events.py index 8a8aef0f2..5b762d98e 100644 --- a/beamer/events.py +++ b/beamer/events.py @@ -233,14 +233,14 @@ def _decode_event( topic = log_entry["topics"][0] event_abi = event_abis[topic] data = get_event_data(abi_codec=codec, event_abi=event_abi, log_entry=log_entry) - if data.event in _EVENT_TYPES: - kwargs = {_camel_to_snake(name): value for name, value in data.args.items()} + if data["event"] in _EVENT_TYPES: + kwargs = {_camel_to_snake(name): value for name, value in data["args"].items()} kwargs["event_chain_id"] = chain_id kwargs["event_address"] = log_entry["address"] kwargs["block_number"] = log_entry["blockNumber"] kwargs["tx_hash"] = log_entry["transactionHash"] _convert_bytes(kwargs) - return _EVENT_TYPES[data.event](**kwargs) + return _EVENT_TYPES[data["event"]](**kwargs) return None diff --git a/beamer/middleware.py b/beamer/middleware.py index bdb632c5c..653ad362b 100644 --- a/beamer/middleware.py +++ b/beamer/middleware.py @@ -32,9 +32,9 @@ def __init__(self) -> None: def add_block(self, key: tuple[str, bool], data: RPCResponse) -> None: with self._lock: self._block_cache[key] = data - if self._latest_block_number < data["result"].number: + if self._latest_block_number < data["result"]["number"]: self._latest_key = key - self._latest_block_number = data["result"].number + self._latest_block_number = data["result"]["number"] def get_block(self, key: tuple[str, bool]) -> RPCResponse: return self._block_cache.get(key) @@ -77,7 +77,7 @@ def middleware(method: RPCEndpoint, params: Any) -> RPCResponse: if params[0] == "latest": response = make_request(method, params) if _result_ok(response): - key = hex(response["result"].number), params[1] + key = hex(response["result"]["number"]), params[1] cache.add_block(key, response) elif params[0].startswith("0x"): response = cache.get_block(params) @@ -341,7 +341,7 @@ def middleware(method: RPCEndpoint, params: Any) -> RPCResponse: latest_block = latest_block_response else: return latest_block_response - base_fee = latest_block["result"].baseFeePerGas + base_fee = latest_block["result"]["baseFeePerGas"] max_fee = 2 * base_fee + priority_fee params[0]["maxPriorityFeePerGas"] = priority_fee params[0]["maxFeePerGas"] = max_fee diff --git a/beamer/util.py b/beamer/util.py index bdc4b1b8b..7077c27fd 100644 --- a/beamer/util.py +++ b/beamer/util.py @@ -80,7 +80,7 @@ def transact( else: break - if receipt.status == 0: # type: ignore + if receipt["status"] == 0: raise TransactionFailed("unknown error") return receipt @@ -147,7 +147,7 @@ def make_web3( timeout: int = 5, ) -> Web3: w3 = Web3(HTTPProvider(url, request_kwargs=dict(timeout=timeout))) - + w3.middleware_onion.remove("attrdict") # Add POA middleware for geth POA chains, no/op for other chains w3.middleware_onion.inject(geth_poa_middleware, layer=0) if account is not None: