Skip to content

Commit

Permalink
Modify Arrow Glacier's fork to use new Access type.
Browse files Browse the repository at this point in the history
  • Loading branch information
richardgreg committed Aug 8, 2024
1 parent 862d998 commit d8cd373
Showing 1 changed file with 4 additions and 34 deletions.
38 changes: 4 additions & 34 deletions src/ethereum/arrow_glacier/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,28 +93,6 @@ class FeeMarketTransaction:
s: U256


# Helper function to handle the RLP encoding of the Access class instances.
def encode_access_list(
access_list: Tuple[Access, ...]
) -> Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...]:
"""
Encode the Access list for RLP encoding.
"""
return tuple((access.account, access.slots) for access in access_list)


# Helper function to handle the RLP decoding of the Access class instances.
def decode_access_list(
encoded_access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...]
) -> Tuple[Access, ...]:
"""
Decode the Access list from RLP encoding.
"""
return tuple(
Access(account=encoded[0], slots=encoded[1]
) for encoded in encoded_access_list)


Transaction = Union[
LegacyTransaction, AccessListTransaction, FeeMarketTransaction
]
Expand All @@ -127,13 +105,9 @@ def encode_transaction(tx: Transaction) -> Union[LegacyTransaction, Bytes]:
if isinstance(tx, LegacyTransaction):
return tx
elif isinstance(tx, AccessListTransaction):
encoded_access_list = encode_access_list(tx.access_list)
return b"\x01" + rlp.encode(tx._replace(
access_list=encoded_access_list))
return b"\x01" + rlp.encode(tx)
elif isinstance(tx, FeeMarketTransaction):
encoded_access_list = encode_access_list(tx.access_list)
return b"\x02" + rlp.encode(tx._replace(
access_list=encoded_access_list))
return b"\x02" + rlp.encode(tx)
else:
raise Exception(f"Unable to encode transaction of type {type(tx)}")

Expand All @@ -144,13 +118,9 @@ def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction:
"""
if isinstance(tx, Bytes):
if tx[0] == 1:
decoded_tx = rlp.decode_to(AccessListTransaction, tx[1:])
decoded_access_list = decode_access_list(decoded_tx.access_list)
return decoded_tx._replace(access_list=decoded_access_list)
return rlp.decode_to(AccessListTransaction, tx[1:])
elif tx[0] == 2:
decoded_tx = rlp.decode_to(FeeMarketTransaction, tx[1:])
decoded_access_list = decode_access_list(decoded_tx.access_list)
return decoded_tx._replace(access_list=decoded_access_list)
return rlp.decode_to(FeeMarketTransaction, tx[1:])
else:
raise InvalidBlock
else:
Expand Down

0 comments on commit d8cd373

Please sign in to comment.