1
1
import Common from '@ethereumjs/common'
2
- import { default as LegacyTransaction } from './legacyTransaction'
3
- import { default as EIP2930Transaction } from './eip2930Transaction'
4
- import { TxOptions , Transaction , TxData } from './types'
2
+ import { default as Transaction } from './legacyTransaction'
3
+ import { default as AccessListEIP2930Transaction } from './eip2930Transaction'
4
+ import { TxOptions , TypedTransaction , TxData } from './types'
5
5
import { BN } from 'ethereumjs-util'
6
6
7
7
const DEFAULT_COMMON = new Common ( { chain : 'mainnet' } )
@@ -12,14 +12,14 @@ export default class TransactionFactory {
12
12
13
13
/**
14
14
* Create a transaction from a `txData` object
15
- * @param txData - The transaction data. The `type` field will determine which transaction type is returned (if undefined, create a LegacyTransaction )
15
+ * @param txData - The transaction data. The `type` field will determine which transaction type is returned (if undefined, create a Transaction )
16
16
* @param txOptions - Options to pass on to the constructor of the transaction
17
17
*/
18
- public static fromTxData ( txData : TxData , txOptions : TxOptions = { } ) : Transaction {
18
+ public static fromTxData ( txData : TxData , txOptions : TxOptions = { } ) : TypedTransaction {
19
19
const common = txOptions . common ?? DEFAULT_COMMON
20
20
if ( txData . type === undefined ) {
21
- // Assume LegacyTransaction
22
- return LegacyTransaction . fromTxData ( txData , txOptions )
21
+ // Assume Transaction
22
+ return Transaction . fromTxData ( txData , txOptions )
23
23
} else {
24
24
const txType = new BN ( txData . type ) . toNumber ( )
25
25
return TransactionFactory . getTransactionClass ( txType , common ) . fromTxData ( txData , txOptions )
@@ -32,7 +32,7 @@ export default class TransactionFactory {
32
32
* @param rawData - The raw data buffer
33
33
* @param txOptions - The transaction options
34
34
*/
35
- public static fromRawData ( rawData : Buffer , txOptions : TxOptions = { } ) : Transaction {
35
+ public static fromRawData ( rawData : Buffer , txOptions : TxOptions = { } ) : TypedTransaction {
36
36
const common = txOptions . common ?? DEFAULT_COMMON
37
37
if ( rawData [ 0 ] <= 0x7f ) {
38
38
// It is an EIP-2718 Typed Transaction
@@ -55,16 +55,16 @@ export default class TransactionFactory {
55
55
)
56
56
}
57
57
58
- return EIP2930Transaction . fromRlpSerializedTx ( rawData , txOptions )
58
+ return AccessListEIP2930Transaction . fromRlpSerializedTx ( rawData , txOptions )
59
59
} else {
60
- return LegacyTransaction . fromRlpSerializedTx ( rawData , txOptions )
60
+ return Transaction . fromRlpSerializedTx ( rawData , txOptions )
61
61
}
62
62
}
63
63
64
64
/**
65
65
* When decoding a BlockBody, in the transactions field, a field is either:
66
66
* A Buffer (a TypedTransaction - encoded as TransactionType || rlp(TransactionPayload))
67
- * A Buffer[] (LegacyTransaction )
67
+ * A Buffer[] (Transaction )
68
68
* This method returns the right transaction.
69
69
* @param rawData - Either a Buffer or a Buffer[]
70
70
* @param txOptions - The transaction options
@@ -73,16 +73,16 @@ export default class TransactionFactory {
73
73
if ( Buffer . isBuffer ( rawData ) ) {
74
74
return this . fromRawData ( rawData , txOptions )
75
75
} else if ( Array . isArray ( rawData ) ) {
76
- // It is a LegacyTransaction
77
- return LegacyTransaction . fromValuesArray ( rawData , txOptions )
76
+ // It is a Transaction
77
+ return Transaction . fromValuesArray ( rawData , txOptions )
78
78
} else {
79
79
throw new Error ( 'Cannot decode transaction: unknown type input' )
80
80
}
81
81
}
82
82
83
83
/**
84
84
* This helper method allows one to retrieve the class which matches the transactionID
85
- * If transactionID is undefined, return the LegacyTransaction class.
85
+ * If transactionID is undefined, return the Transaction class.
86
86
* @param transactionID
87
87
* @param common
88
88
*/
@@ -97,12 +97,12 @@ export default class TransactionFactory {
97
97
const legacyTxn = transactionID == 0 || ( transactionID >= 0x80 && transactionID <= 0xff )
98
98
99
99
if ( legacyTxn ) {
100
- return LegacyTransaction
100
+ return Transaction
101
101
}
102
102
103
103
switch ( transactionID ) {
104
104
case 1 :
105
- return EIP2930Transaction
105
+ return AccessListEIP2930Transaction
106
106
default :
107
107
throw new Error ( `TypedTransaction with ID ${ transactionID } unknown` )
108
108
}
0 commit comments