Skip to content

Commit

Permalink
beamer: fix TxReceipt typings
Browse files Browse the repository at this point in the history
  • Loading branch information
bilbeyt committed Jun 29, 2023
1 parent 1d6952d commit 42cbb88
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 23 deletions.
12 changes: 5 additions & 7 deletions beamer/agent/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)

Expand Down Expand Up @@ -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(),
)


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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(),
)
4 changes: 2 additions & 2 deletions beamer/agent/state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions beamer/config/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 3 additions & 3 deletions beamer/deploy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions beamer/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
8 changes: 4 additions & 4 deletions beamer/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions beamer/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def transact(
else:
break

if receipt.status == 0: # type: ignore
if receipt["status"] == 0:
raise TransactionFailed("unknown error")
return receipt

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 42cbb88

Please sign in to comment.