Skip to content

Commit 737cd86

Browse files
committed
check array length in fromBlockBodyData for creating the right tx
1 parent 9e4c34f commit 737cd86

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

packages/tx/src/transactionFactory.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,22 @@ export default class TransactionFactory {
7474
* A Buffer[] (Legacy Transaction)
7575
* This method returns the right transaction.
7676
*
77-
* @param rawData - Either a Buffer or a Buffer[]
77+
* @param data - A Buffer or Buffer[]
7878
* @param txOptions - The transaction options
7979
*/
80-
public static fromBlockBodyData(rawData: Buffer | Buffer[], txOptions: TxOptions = {}) {
81-
if (Buffer.isBuffer(rawData)) {
82-
return this.fromRawData(rawData, txOptions)
83-
} else if (Array.isArray(rawData)) {
84-
// It is a legacy transaction
85-
return Transaction.fromValuesArray(rawData, txOptions)
80+
public static fromBlockBodyData(data: Buffer | Buffer[], txOptions: TxOptions = {}) {
81+
if (Buffer.isBuffer(data)) {
82+
return this.fromSerializedData(data, txOptions)
83+
} else if (Array.isArray(data)) {
84+
if (data.length === 6 || data.length === 9) {
85+
// It is a legacy transaction
86+
return Transaction.fromValuesArray(data, txOptions)
87+
} else if (data.length === 8 || data.length === 11) {
88+
// It is an Access List Transaction
89+
return AccessListEIP2930Transaction.fromValuesArray(data, txOptions)
90+
} else {
91+
throw new Error('Cannot decode transaction: unknown array length')
92+
}
8693
} else {
8794
throw new Error('Cannot decode transaction: unknown type input')
8895
}

0 commit comments

Comments
 (0)