@@ -267,6 +267,76 @@ def as_signed_transaction(self, private_key: PrivateKey) -> 'SignedTransactionAP
267267 ...
268268
269269
270+ class TransactionBuilderAPI (ABC ):
271+ """
272+ Responsible for creating and encoding transactions.
273+
274+ Most simply, the builder is responsible for some pieces of the encoding for
275+ RLP. In legacy transactions, this happens using rlp.Serializeable. It is
276+ also responsible for initializing the transactions. The two transaction
277+ initializers assume legacy transactions, for now.
278+
279+ Some VMs support multiple distinct transaction types. In that case, the
280+ builder is responsible for dispatching on the different types.
281+ """
282+ @classmethod
283+ @abstractmethod
284+ def deserialize (cls , encoded : bytes ) -> 'SignedTransactionAPI' :
285+ """
286+ Extract a transaction from an encoded RLP object.
287+
288+ This method is used by rlp.decode(..., sedes=TransactionBuilderAPI).
289+ """
290+ ...
291+
292+ @classmethod
293+ @abstractmethod
294+ def serialize (cls , obj : 'SignedTransactionAPI' ) -> bytes :
295+ """
296+ Encode a transaction to a series of bytes used by RLP.
297+
298+ In the case of legacy transactions, it will actually be a list of
299+ bytes. That doesn't show up here, because pyrlp doesn't export type
300+ annotations.
301+
302+ This method is used by rlp.encode(obj).
303+ """
304+ ...
305+
306+ @classmethod
307+ @abstractmethod
308+ def create_unsigned_transaction (cls ,
309+ * ,
310+ nonce : int ,
311+ gas_price : int ,
312+ gas : int ,
313+ to : Address ,
314+ value : int ,
315+ data : bytes ) -> UnsignedTransactionAPI :
316+ """
317+ Create an unsigned transaction.
318+ """
319+ ...
320+
321+ @classmethod
322+ @abstractmethod
323+ def new_transaction (
324+ cls ,
325+ nonce : int ,
326+ gas_price : int ,
327+ gas : int ,
328+ to : Address ,
329+ value : int ,
330+ data : bytes ,
331+ v : int ,
332+ r : int ,
333+ s : int ) -> 'SignedTransactionAPI' :
334+ """
335+ Create a signed transaction.
336+ """
337+ ...
338+
339+
270340class SignedTransactionAPI (BaseTransactionAPI , TransactionFieldsAPI ):
271341
272342 def __init__ (self , * args : Any , ** kwargs : Any ) -> None :
@@ -345,21 +415,6 @@ def get_message_for_signing(self) -> bytes:
345415 """
346416 ...
347417
348- @classmethod
349- @abstractmethod
350- def create_unsigned_transaction (cls ,
351- * ,
352- nonce : int ,
353- gas_price : int ,
354- gas : int ,
355- to : Address ,
356- value : int ,
357- data : bytes ) -> UnsignedTransactionAPI :
358- """
359- Create an unsigned transaction.
360- """
361- ...
362-
363418 # We can remove this API and inherit from rlp.Serializable when it becomes typesafe
364419 def as_dict (self ) -> Dict [Hashable , Any ]:
365420 """
@@ -374,7 +429,7 @@ class BlockAPI(ABC):
374429 """
375430 header : BlockHeaderAPI
376431 transactions : Tuple [SignedTransactionAPI , ...]
377- transaction_class : Type [SignedTransactionAPI ] = None
432+ transaction_builder : Type [TransactionBuilderAPI ] = None
378433 uncles : Tuple [BlockHeaderAPI , ...]
379434
380435 @abstractmethod
@@ -386,9 +441,9 @@ def __init__(self,
386441
387442 @classmethod
388443 @abstractmethod
389- def get_transaction_class (cls ) -> Type [SignedTransactionAPI ]:
444+ def get_transaction_builder (cls ) -> Type [TransactionBuilderAPI ]:
390445 """
391- Return the transaction class that is valid for the block.
446+ Return the transaction builder for the block.
392447 """
393448 ...
394449
@@ -812,7 +867,7 @@ def add_transaction(self,
812867 def get_block_transactions (
813868 self ,
814869 block_header : BlockHeaderAPI ,
815- transaction_class : Type [SignedTransactionAPI ]) -> Tuple [SignedTransactionAPI , ...]:
870+ transaction_builder : Type [TransactionBuilderAPI ]) -> Tuple [SignedTransactionAPI , ...]:
816871 """
817872 Return an iterable of transactions for the block speficied by the
818873 given block header.
@@ -851,7 +906,7 @@ def get_transaction_by_index(
851906 self ,
852907 block_number : BlockNumber ,
853908 transaction_index : int ,
854- transaction_class : Type [SignedTransactionAPI ]) -> SignedTransactionAPI :
909+ transaction_builder : Type [TransactionBuilderAPI ]) -> SignedTransactionAPI :
855910 """
856911 Return the transaction at the specified `transaction_index` from the
857912 block specified by `block_number` from the canonical chain.
@@ -2987,9 +3042,9 @@ def create_unsigned_transaction(cls,
29873042
29883043 @classmethod
29893044 @abstractmethod
2990- def get_transaction_class (cls ) -> Type [SignedTransactionAPI ]:
3045+ def get_transaction_builder (cls ) -> Type [TransactionBuilderAPI ]:
29913046 """
2992- Return the class that this VM uses for transactions.
3047+ Return the class that this VM uses to build and encode transactions.
29933048 """
29943049 ...
29953050
0 commit comments