Skip to content

Commit abea333

Browse files
committed
Fix type hints of transactions
1 parent cf4a24c commit abea333

File tree

9 files changed

+93
-54
lines changed

9 files changed

+93
-54
lines changed

eth/chains/base.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import logging
2525

2626
from eth_typing import (
27+
Address,
2728
BlockNumber,
2829
Hash32,
2930
)
@@ -241,9 +242,14 @@ def create_transaction(self, *args: Any, **kwargs: Any) -> BaseTransaction:
241242
raise NotImplementedError("Chain classes must implement this method")
242243

243244
@abstractmethod
244-
def create_unsigned_transaction(self,
245-
*args: Any,
246-
**kwargs: Any) -> BaseUnsignedTransaction:
245+
def create_unsigned_transaction(cls,
246+
*,
247+
nonce: int,
248+
gas_price: int,
249+
gas: int,
250+
to: Address,
251+
value: int,
252+
data: bytes) -> BaseUnsignedTransaction:
247253
raise NotImplementedError("Chain classes must implement this method")
248254

249255
@abstractmethod
@@ -573,12 +579,24 @@ def create_transaction(self, *args: Any, **kwargs: Any) -> BaseTransaction:
573579
return self.get_vm().create_transaction(*args, **kwargs)
574580

575581
def create_unsigned_transaction(self,
576-
*args: Any,
577-
**kwargs: Any) -> BaseUnsignedTransaction:
582+
*,
583+
nonce: int,
584+
gas_price: int,
585+
gas: int,
586+
to: Address,
587+
value: int,
588+
data: bytes) -> BaseUnsignedTransaction:
578589
"""
579590
Passthrough helper to the current VM class.
580591
"""
581-
return self.get_vm().create_unsigned_transaction(*args, **kwargs)
592+
return self.get_vm().create_unsigned_transaction(
593+
nonce=nonce,
594+
gas_price=gas_price,
595+
gas=gas,
596+
to=to,
597+
value=value,
598+
data=data,
599+
)
582600

583601
#
584602
# Execution API

eth/rlp/transactions.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
ABC,
33
abstractmethod
44
)
5-
from typing import (
6-
Any,
7-
)
85

96
import rlp
107
from rlp.sedes import (
@@ -17,7 +14,9 @@
1714
)
1815

1916
from eth_hash.auto import keccak
20-
17+
from eth_keys.datatypes import (
18+
PrivateKey
19+
)
2120
from eth_utils import (
2221
ValidationError,
2322
)
@@ -150,7 +149,14 @@ def get_message_for_signing(self) -> bytes:
150149

151150
@classmethod
152151
@abstractmethod
153-
def create_unsigned_transaction(self, *args: Any, **kwargs: Any) -> 'BaseTransaction':
152+
def create_unsigned_transaction(cls,
153+
*,
154+
nonce: int,
155+
gas_price: int,
156+
gas: int,
157+
to: Address,
158+
value: int,
159+
data: bytes) -> 'BaseUnsignedTransaction':
154160
"""
155161
Create an unsigned transaction.
156162
"""
@@ -171,7 +177,7 @@ class BaseUnsignedTransaction(rlp.Serializable, BaseTransactionMethods, ABC):
171177
# API that must be implemented by all Transaction subclasses.
172178
#
173179
@abstractmethod
174-
def as_signed_transaction(self, private_key: bytes) -> 'BaseTransaction':
180+
def as_signed_transaction(self, private_key: PrivateKey) -> 'BaseTransaction':
175181
"""
176182
Return a version of this transaction which has been signed using the
177183
provided `private_key`

eth/vm/base.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@
5555
from eth.rlp.sedes import (
5656
int32,
5757
)
58-
from eth.rlp.transactions import BaseTransaction
58+
from eth.rlp.transactions import (
59+
BaseTransaction,
60+
BaseUnsignedTransaction,
61+
)
5962
from eth.utils.datatypes import (
6063
Configurable,
6164
)
@@ -263,12 +266,19 @@ def get_uncle_reward(block_number: int, uncle: BaseBlock) -> int:
263266
# Transactions
264267
#
265268
@abstractmethod
266-
def create_transaction(self, *args: Any, **kwargs: Any) -> Any:
269+
def create_transaction(self, *args: Any, **kwargs: Any) -> BaseTransaction:
267270
raise NotImplementedError("VM classes must implement this method")
268271

269272
@classmethod
270273
@abstractmethod
271-
def create_unsigned_transaction(cls, *args: Any, **kwargs: Any) -> Any:
274+
def create_unsigned_transaction(cls,
275+
*,
276+
nonce: int,
277+
gas_price: int,
278+
gas: int,
279+
to: Address,
280+
value: int,
281+
data: bytes) -> BaseUnsignedTransaction:
272282
raise NotImplementedError("VM classes must implement this method")
273283

274284
@classmethod
@@ -693,18 +703,32 @@ def previous_hashes(self) -> Optional[Tuple[Hash32, ...]]:
693703
#
694704
# Transactions
695705
#
696-
def create_transaction(self, *args: Any, **kwargs: Any) -> BaseState:
706+
def create_transaction(self, *args: Any, **kwargs: Any) -> BaseTransaction:
697707
"""
698708
Proxy for instantiating a signed transaction for this VM.
699709
"""
700710
return self.get_transaction_class()(*args, **kwargs)
701711

702712
@classmethod
703-
def create_unsigned_transaction(cls, *args: Any, **kwargs: Any) -> BaseTransaction:
713+
def create_unsigned_transaction(cls,
714+
*,
715+
nonce: int,
716+
gas_price: int,
717+
gas: int,
718+
to: Address,
719+
value: int,
720+
data: bytes) -> 'BaseUnsignedTransaction':
704721
"""
705722
Proxy for instantiating an unsigned transaction for this VM.
706723
"""
707-
return cls.get_transaction_class().create_unsigned_transaction(*args, **kwargs)
724+
return cls.get_transaction_class().create_unsigned_transaction(
725+
nonce=nonce,
726+
gas_price=gas_price,
727+
gas=gas,
728+
to=to,
729+
value=value,
730+
data=data
731+
)
708732

709733
@classmethod
710734
def get_transaction_class(cls) -> Type[BaseTransaction]:

eth/vm/forks/byzantium/transactions.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
from eth_keys.datatypes import PrivateKey
22
from eth_typing import Address
33

4-
from eth.rlp.transactions import (
5-
BaseTransaction,
6-
BaseUnsignedTransaction,
7-
)
8-
94
from eth.utils.transactions import (
105
create_transaction_signature,
116
)
@@ -18,21 +13,21 @@
1813

1914
class ByzantiumTransaction(SpuriousDragonTransaction):
2015
@classmethod
21-
def create_unsigned_transaction(cls, # type: ignore
16+
def create_unsigned_transaction(cls,
2217
*,
2318
nonce: int,
2419
gas_price: int,
2520
gas: int,
2621
to: Address,
2722
value: int,
28-
data: bytes) -> BaseTransaction:
23+
data: bytes) -> 'ByzantiumUnsignedTransaction':
2924
return ByzantiumUnsignedTransaction(nonce, gas_price, gas, to, value, data)
3025

3126

3227
class ByzantiumUnsignedTransaction(SpuriousDragonUnsignedTransaction):
33-
def as_signed_transaction(self, # type: ignore
28+
def as_signed_transaction(self,
3429
private_key: PrivateKey,
35-
chain_id: int=None) -> BaseUnsignedTransaction:
30+
chain_id: int=None) -> ByzantiumTransaction:
3631
v, r, s = create_transaction_signature(self, private_key, chain_id=chain_id)
3732
return ByzantiumTransaction(
3833
nonce=self.nonce,

eth/vm/forks/constantinople/transactions.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
from eth_keys.datatypes import PrivateKey
22
from eth_typing import Address
33

4-
from eth.rlp.transactions import (
5-
BaseTransaction,
6-
BaseUnsignedTransaction,
7-
)
8-
94
from eth.vm.forks.byzantium.transactions import (
105
ByzantiumTransaction,
116
ByzantiumUnsignedTransaction,
@@ -18,21 +13,21 @@
1813

1914
class ConstantinopleTransaction(ByzantiumTransaction):
2015
@classmethod
21-
def create_unsigned_transaction(cls, # type: ignore
16+
def create_unsigned_transaction(cls,
2217
*,
2318
nonce: int,
2419
gas_price: int,
2520
gas: int,
2621
to: Address,
2722
value: int,
28-
data: bytes) -> BaseTransaction:
23+
data: bytes) -> 'ConstantinopleUnsignedTransaction':
2924
return ConstantinopleUnsignedTransaction(nonce, gas_price, gas, to, value, data)
3025

3126

3227
class ConstantinopleUnsignedTransaction(ByzantiumUnsignedTransaction):
33-
def as_signed_transaction(self, # type: ignore
28+
def as_signed_transaction(self,
3429
private_key: PrivateKey,
35-
chain_id: int=None) -> BaseUnsignedTransaction:
30+
chain_id: int=None) -> ConstantinopleTransaction:
3631
v, r, s = create_transaction_signature(self, private_key, chain_id=chain_id)
3732
return ConstantinopleTransaction(
3833
nonce=self.nonce,

eth/vm/forks/frontier/transactions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ def get_message_for_signing(self) -> bytes:
8383
))
8484

8585
@classmethod
86-
def create_unsigned_transaction(cls, # type: ignore
86+
def create_unsigned_transaction(cls,
8787
*,
8888
nonce: int,
8989
gas_price: int,
9090
gas: int,
9191
to: Address,
9292
value: int,
93-
data: bytes) -> BaseTransaction:
93+
data: bytes) -> 'FrontierUnsignedTransaction':
9494
return FrontierUnsignedTransaction(nonce, gas_price, gas, to, value, data)
9595

9696

@@ -106,7 +106,7 @@ def validate(self) -> None:
106106
validate_is_bytes(self.data, title="Transaction.data")
107107
super().validate()
108108

109-
def as_signed_transaction(self, private_key: PrivateKey) -> BaseTransaction: # type: ignore
109+
def as_signed_transaction(self, private_key: PrivateKey) -> FrontierTransaction:
110110
v, r, s = create_transaction_signature(self, private_key)
111111
return FrontierTransaction(
112112
nonce=self.nonce,

eth/vm/forks/homestead/transactions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@ def get_message_for_signing(self) -> bytes:
4747
))
4848

4949
@classmethod
50-
def create_unsigned_transaction(cls, # type: ignore
50+
def create_unsigned_transaction(cls,
5151
*,
5252
nonce: int,
5353
gas_price: int,
5454
gas: int,
5555
to: Address,
5656
value: int,
57-
data: bytes) -> BaseTransaction:
57+
data: bytes) -> 'HomesteadUnsignedTransaction':
5858
return HomesteadUnsignedTransaction(nonce, gas_price, gas, to, value, data)
5959

6060

6161
class HomesteadUnsignedTransaction(FrontierUnsignedTransaction):
62-
def as_signed_transaction(self, private_key: PrivateKey) -> BaseTransaction: # type: ignore
62+
def as_signed_transaction(self, private_key: PrivateKey) -> HomesteadTransaction:
6363
v, r, s = create_transaction_signature(self, private_key)
6464
return HomesteadTransaction(
6565
nonce=self.nonce,

eth/vm/forks/spurious_dragon/transactions.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212

1313
import rlp
1414

15-
from eth.rlp.transactions import (
16-
BaseTransaction,
17-
BaseUnsignedTransaction,
18-
)
19-
2015
from eth.vm.forks.homestead.transactions import (
2116
HomesteadTransaction,
2217
HomesteadUnsignedTransaction,
@@ -46,14 +41,14 @@ def get_message_for_signing(self) -> bytes:
4641
))
4742

4843
@classmethod
49-
def create_unsigned_transaction(cls, # type: ignore
44+
def create_unsigned_transaction(cls,
5045
*,
5146
nonce: int,
5247
gas_price: int,
5348
gas: int,
5449
to: Address,
5550
value: int,
56-
data: bytes) -> BaseTransaction:
51+
data: bytes) -> 'SpuriousDragonUnsignedTransaction':
5752
return SpuriousDragonUnsignedTransaction(nonce, gas_price, gas, to, value, data)
5853

5954
@property
@@ -79,9 +74,9 @@ def v_max(self) -> int: # type: ignore
7974

8075

8176
class SpuriousDragonUnsignedTransaction(HomesteadUnsignedTransaction):
82-
def as_signed_transaction(self, # type: ignore
77+
def as_signed_transaction(self,
8378
private_key: PrivateKey,
84-
chain_id: int=None) -> BaseUnsignedTransaction:
79+
chain_id: int=None) -> SpuriousDragonTransaction:
8580
v, r, s = create_transaction_signature(self, private_key, chain_id=chain_id)
8681
return SpuriousDragonTransaction(
8782
nonce=self.nonce,

trinity/chains/light.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
)
1818

1919
from eth_typing import (
20+
Address,
2021
BlockNumber,
2122
Hash32,
2223
)
@@ -184,9 +185,14 @@ def build_block_with_transactions(
184185
def create_transaction(self, *args: Any, **kwargs: Any) -> BaseTransaction:
185186
raise NotImplementedError("Chain classes must implement " + inspect.stack()[0][3])
186187

187-
def create_unsigned_transaction(self,
188-
*args: Any,
189-
**kwargs: Any) -> BaseUnsignedTransaction:
188+
def create_unsigned_transaction(cls,
189+
*,
190+
nonce: int,
191+
gas_price: int,
192+
gas: int,
193+
to: Address,
194+
value: int,
195+
data: bytes) -> BaseUnsignedTransaction:
190196
raise NotImplementedError("Chain classes must implement " + inspect.stack()[0][3])
191197

192198
def get_canonical_transaction(self, transaction_hash: Hash32) -> BaseTransaction:

0 commit comments

Comments
 (0)