Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit 0ed334f

Browse files
committed
Add v to special legacy transaction API
1 parent 07a1884 commit 0ed334f

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

eth/abc.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,19 @@ def chain_id(self) -> Optional[int]:
380380
...
381381

382382

383+
class LegacyTransactionFieldsAPI(TransactionFieldsAPI):
384+
@property
385+
@abstractmethod
386+
def v(self) -> int:
387+
"""
388+
In old transactions, this v field combines the y_parity bit and the
389+
chain ID. All new usages should prefer accessing those fields directly.
390+
But if you must access the original v, then you can cast to this API
391+
first (after checking that type_id is None).
392+
"""
393+
...
394+
395+
383396
class UnsignedTransactionAPI(BaseTransactionAPI):
384397

385398
"""

eth/rlp/transactions.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from eth.abc import (
2525
BaseTransactionAPI,
2626
ComputationAPI,
27+
LegacyTransactionFieldsAPI,
2728
SignedTransactionAPI,
2829
TransactionBuilderAPI,
2930
TransactionFieldsAPI,
@@ -103,13 +104,21 @@ def is_signature_valid(self) -> bool:
103104
return True
104105

105106

106-
class BaseTransaction(BaseTransactionFields, SignedTransactionMethods, TransactionBuilderAPI):
107+
class BaseTransaction(
108+
LegacyTransactionFieldsAPI,
109+
BaseTransactionFields,
110+
SignedTransactionMethods,
111+
TransactionBuilderAPI):
107112
# "Legacy" transactions implemented by BaseTransaction are a combination of
108113
# the transaction codec (TransactionBuilderAPI) *and* the transaction
109114
# object (SignedTransactionAPI). In a multi-transaction-type world, that
110115
# becomes less desirable, and that responsibility splits up. See Berlin
111116
# transactions, for example.
112117

118+
# Note that it includes at least one legacy field (v) that is not
119+
# explicitly accessible in new transaction types. See the v docstring in
120+
# LegacyTransactionFieldsAPI for more.
121+
113122
# this is duplicated to make the rlp library happy, otherwise it complains
114123
# about no fields being defined but inheriting from multiple `Serializable`
115124
# bases.

newsfragments/1997.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add new LegacyTransactionFieldsAPI, with a v field for callers that want to access v directly.

0 commit comments

Comments
 (0)