@@ -267,6 +267,76 @@ def as_signed_transaction(self, private_key: PrivateKey) -> 'SignedTransactionAP
267
267
...
268
268
269
269
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
+
270
340
class SignedTransactionAPI (BaseTransactionAPI , TransactionFieldsAPI ):
271
341
272
342
def __init__ (self , * args : Any , ** kwargs : Any ) -> None :
@@ -345,21 +415,6 @@ def get_message_for_signing(self) -> bytes:
345
415
"""
346
416
...
347
417
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
-
363
418
# We can remove this API and inherit from rlp.Serializable when it becomes typesafe
364
419
def as_dict (self ) -> Dict [Hashable , Any ]:
365
420
"""
@@ -374,7 +429,7 @@ class BlockAPI(ABC):
374
429
"""
375
430
header : BlockHeaderAPI
376
431
transactions : Tuple [SignedTransactionAPI , ...]
377
- transaction_class : Type [SignedTransactionAPI ] = None
432
+ transaction_builder : Type [TransactionBuilderAPI ] = None
378
433
uncles : Tuple [BlockHeaderAPI , ...]
379
434
380
435
@abstractmethod
@@ -386,9 +441,9 @@ def __init__(self,
386
441
387
442
@classmethod
388
443
@abstractmethod
389
- def get_transaction_class (cls ) -> Type [SignedTransactionAPI ]:
444
+ def get_transaction_builder (cls ) -> Type [TransactionBuilderAPI ]:
390
445
"""
391
- Return the transaction class that is valid for the block.
446
+ Return the transaction builder for the block.
392
447
"""
393
448
...
394
449
@@ -812,7 +867,7 @@ def add_transaction(self,
812
867
def get_block_transactions (
813
868
self ,
814
869
block_header : BlockHeaderAPI ,
815
- transaction_class : Type [SignedTransactionAPI ]) -> Tuple [SignedTransactionAPI , ...]:
870
+ transaction_builder : Type [TransactionBuilderAPI ]) -> Tuple [SignedTransactionAPI , ...]:
816
871
"""
817
872
Return an iterable of transactions for the block speficied by the
818
873
given block header.
@@ -851,7 +906,7 @@ def get_transaction_by_index(
851
906
self ,
852
907
block_number : BlockNumber ,
853
908
transaction_index : int ,
854
- transaction_class : Type [SignedTransactionAPI ]) -> SignedTransactionAPI :
909
+ transaction_builder : Type [TransactionBuilderAPI ]) -> SignedTransactionAPI :
855
910
"""
856
911
Return the transaction at the specified `transaction_index` from the
857
912
block specified by `block_number` from the canonical chain.
@@ -2987,9 +3042,9 @@ def create_unsigned_transaction(cls,
2987
3042
2988
3043
@classmethod
2989
3044
@abstractmethod
2990
- def get_transaction_class (cls ) -> Type [SignedTransactionAPI ]:
3045
+ def get_transaction_builder (cls ) -> Type [TransactionBuilderAPI ]:
2991
3046
"""
2992
- Return the class that this VM uses for transactions.
3047
+ Return the class that this VM uses to build and encode transactions.
2993
3048
"""
2994
3049
...
2995
3050
0 commit comments