Skip to content

Commit

Permalink
Create TYPE_NOT_SUPPORTED error (#1021)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamWilsn committed Oct 17, 2024
1 parent ce1bb2e commit 47863f7
Show file tree
Hide file tree
Showing 15 changed files with 188 additions and 14 deletions.
24 changes: 24 additions & 0 deletions src/ethereum/arrow_glacier/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Exceptions specific to this fork.
"""

from typing import Final

from ethereum.exceptions import InvalidTransaction


class TransactionTypeError(InvalidTransaction):
"""
Unknown [EIP-2718] transaction type byte.
[EIP-2718]: https://eips.ethereum.org/EIPS/eip-2718
"""

transaction_type: Final[int]
"""
The type byte of the transaction that caused the error.
"""

def __init__(self, transaction_type: int):
super().__init__(f"unknown transaction type `{transaction_type}`")
self.transaction_type = transaction_type
4 changes: 2 additions & 2 deletions src/ethereum/arrow_glacier/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ethereum_types.numeric import U64, U256, Uint

from .. import rlp
from ..exceptions import InvalidBlock
from .exceptions import TransactionTypeError
from .fork_types import Address

TX_BASE_COST = 21000
Expand Down Expand Up @@ -110,6 +110,6 @@ def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction:
elif tx[0] == 2:
return rlp.decode_to(FeeMarketTransaction, tx[1:])
else:
raise InvalidBlock
raise TransactionTypeError(tx[0])
else:
return tx
24 changes: 24 additions & 0 deletions src/ethereum/berlin/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Exceptions specific to this fork.
"""

from typing import Final

from ethereum.exceptions import InvalidTransaction


class TransactionTypeError(InvalidTransaction):
"""
Unknown [EIP-2718] transaction type byte.
[EIP-2718]: https://eips.ethereum.org/EIPS/eip-2718
"""

transaction_type: Final[int]
"""
The type byte of the transaction that caused the error.
"""

def __init__(self, transaction_type: int):
super().__init__(f"unknown transaction type `{transaction_type}`")
self.transaction_type = transaction_type
4 changes: 2 additions & 2 deletions src/ethereum/berlin/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ethereum_types.numeric import U64, U256, Uint

from .. import rlp
from ..exceptions import InvalidBlock
from .exceptions import TransactionTypeError
from .fork_types import Address

TX_BASE_COST = 21000
Expand Down Expand Up @@ -81,7 +81,7 @@ def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction:
"""
if isinstance(tx, Bytes):
if tx[0] != 1:
raise InvalidBlock
raise TransactionTypeError(tx[0])
return rlp.decode_to(AccessListTransaction, tx[1:])
else:
return tx
24 changes: 24 additions & 0 deletions src/ethereum/cancun/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Exceptions specific to this fork.
"""

from typing import Final

from ethereum.exceptions import InvalidTransaction


class TransactionTypeError(InvalidTransaction):
"""
Unknown [EIP-2718] transaction type byte.
[EIP-2718]: https://eips.ethereum.org/EIPS/eip-2718
"""

transaction_type: Final[int]
"""
The type byte of the transaction that caused the error.
"""

def __init__(self, transaction_type: int):
super().__init__(f"unknown transaction type `{transaction_type}`")
self.transaction_type = transaction_type
4 changes: 2 additions & 2 deletions src/ethereum/cancun/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ethereum_types.numeric import U64, U256, Uint

from .. import rlp
from ..exceptions import InvalidBlock
from .exceptions import TransactionTypeError
from .fork_types import Address, VersionedHash

TX_BASE_COST = 21000
Expand Down Expand Up @@ -140,6 +140,6 @@ def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction:
elif tx[0] == 3:
return rlp.decode_to(BlobTransaction, tx[1:])
else:
raise InvalidBlock
raise TransactionTypeError(tx[0])
else:
return tx
6 changes: 6 additions & 0 deletions src/ethereum/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ class InvalidBlock(EthereumException):
"""


class InvalidTransaction(EthereumException):
"""
Thrown when a transaction being processed is found to be invalid.
"""


class RLPDecodingError(InvalidBlock):
"""
Indicates that RLP decoding failed.
Expand Down
24 changes: 24 additions & 0 deletions src/ethereum/gray_glacier/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Exceptions specific to this fork.
"""

from typing import Final

from ethereum.exceptions import InvalidTransaction


class TransactionTypeError(InvalidTransaction):
"""
Unknown [EIP-2718] transaction type byte.
[EIP-2718]: https://eips.ethereum.org/EIPS/eip-2718
"""

transaction_type: Final[int]
"""
The type byte of the transaction that caused the error.
"""

def __init__(self, transaction_type: int):
super().__init__(f"unknown transaction type `{transaction_type}`")
self.transaction_type = transaction_type
4 changes: 2 additions & 2 deletions src/ethereum/gray_glacier/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ethereum_types.numeric import U64, U256, Uint

from .. import rlp
from ..exceptions import InvalidBlock
from .exceptions import TransactionTypeError
from .fork_types import Address

TX_BASE_COST = 21000
Expand Down Expand Up @@ -110,6 +110,6 @@ def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction:
elif tx[0] == 2:
return rlp.decode_to(FeeMarketTransaction, tx[1:])
else:
raise InvalidBlock
raise TransactionTypeError(tx[0])
else:
return tx
24 changes: 24 additions & 0 deletions src/ethereum/london/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Exceptions specific to this fork.
"""

from typing import Final

from ethereum.exceptions import InvalidTransaction


class TransactionTypeError(InvalidTransaction):
"""
Unknown [EIP-2718] transaction type byte.
[EIP-2718]: https://eips.ethereum.org/EIPS/eip-2718
"""

transaction_type: Final[int]
"""
The type byte of the transaction that caused the error.
"""

def __init__(self, transaction_type: int):
super().__init__(f"unknown transaction type `{transaction_type}`")
self.transaction_type = transaction_type
4 changes: 2 additions & 2 deletions src/ethereum/london/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ethereum_types.numeric import U64, U256, Uint

from .. import rlp
from ..exceptions import InvalidBlock
from .exceptions import TransactionTypeError
from .fork_types import Address

TX_BASE_COST = 21000
Expand Down Expand Up @@ -110,6 +110,6 @@ def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction:
elif tx[0] == 2:
return rlp.decode_to(FeeMarketTransaction, tx[1:])
else:
raise InvalidBlock
raise TransactionTypeError(tx[0])
else:
return tx
24 changes: 24 additions & 0 deletions src/ethereum/paris/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Exceptions specific to this fork.
"""

from typing import Final

from ethereum.exceptions import InvalidTransaction


class TransactionTypeError(InvalidTransaction):
"""
Unknown [EIP-2718] transaction type byte.
[EIP-2718]: https://eips.ethereum.org/EIPS/eip-2718
"""

transaction_type: Final[int]
"""
The type byte of the transaction that caused the error.
"""

def __init__(self, transaction_type: int):
super().__init__(f"unknown transaction type `{transaction_type}`")
self.transaction_type = transaction_type
4 changes: 2 additions & 2 deletions src/ethereum/paris/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ethereum_types.numeric import U64, U256, Uint

from .. import rlp
from ..exceptions import InvalidBlock
from .exceptions import TransactionTypeError
from .fork_types import Address

TX_BASE_COST = 21000
Expand Down Expand Up @@ -110,6 +110,6 @@ def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction:
elif tx[0] == 2:
return rlp.decode_to(FeeMarketTransaction, tx[1:])
else:
raise InvalidBlock
raise TransactionTypeError(tx[0])
else:
return tx
24 changes: 24 additions & 0 deletions src/ethereum/shanghai/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Exceptions specific to this fork.
"""

from typing import Final

from ethereum.exceptions import InvalidTransaction


class TransactionTypeError(InvalidTransaction):
"""
Unknown [EIP-2718] transaction type byte.
[EIP-2718]: https://eips.ethereum.org/EIPS/eip-2718
"""

transaction_type: Final[int]
"""
The type byte of the transaction that caused the error.
"""

def __init__(self, transaction_type: int):
super().__init__(f"unknown transaction type `{transaction_type}`")
self.transaction_type = transaction_type
4 changes: 2 additions & 2 deletions src/ethereum/shanghai/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ethereum_types.numeric import U64, U256, Uint

from .. import rlp
from ..exceptions import InvalidBlock
from .exceptions import TransactionTypeError
from .fork_types import Address

TX_BASE_COST = 21000
Expand Down Expand Up @@ -110,6 +110,6 @@ def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction:
elif tx[0] == 2:
return rlp.decode_to(FeeMarketTransaction, tx[1:])
else:
raise InvalidBlock
raise TransactionTypeError(tx[0])
else:
return tx

0 comments on commit 47863f7

Please sign in to comment.