Skip to content

Commit 2b13383

Browse files
committed
fromRawData => fromSerializedData
1 parent 737cd86 commit 2b13383

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

packages/tx/src/transactionFactory.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,37 +34,37 @@ export default class TransactionFactory {
3434
}
3535

3636
/**
37-
* This method tries to decode `raw` data. It is somewhat equivalent to `fromSerializedTx`, however it could be that the data is not directly RLP-encoded (it is a Typed Transaction)
37+
* This method tries to decode serialized data.
3838
*
39-
* @param rawData - The raw data buffer
39+
* @param data - The data Buffer
4040
* @param txOptions - The transaction options
4141
*/
42-
public static fromRawData(rawData: Buffer, txOptions: TxOptions = {}): TypedTransaction {
42+
public static fromSerializedData(data: Buffer, txOptions: TxOptions = {}): TypedTransaction {
4343
const common = txOptions.common ?? DEFAULT_COMMON
44-
if (rawData[0] <= 0x7f) {
44+
if (data[0] <= 0x7f) {
4545
// It is an EIP-2718 Typed Transaction
4646
if (!common.isActivatedEIP(2718)) {
4747
throw new Error('Common support for TypedTransactions (EIP-2718) not activated')
4848
}
4949
// Determine the type.
5050
let EIP: number
51-
switch (rawData[0]) {
51+
switch (data[0]) {
5252
case 1:
5353
EIP = 2930
5454
break
5555
default:
56-
throw new Error(`TypedTransaction with ID ${rawData[0]} unknown`)
56+
throw new Error(`TypedTransaction with ID ${data[0]} unknown`)
5757
}
5858

5959
if (!common.isActivatedEIP(EIP)) {
6060
throw new Error(
61-
`Cannot create TypedTransaction with ID ${rawData[0]}: EIP ${EIP} not activated`
61+
`Cannot create TypedTransaction with ID ${data[0]}: EIP ${EIP} not activated`
6262
)
6363
}
6464

65-
return AccessListEIP2930Transaction.fromSerializedTx(rawData, txOptions)
65+
return AccessListEIP2930Transaction.fromSerializedTx(data, txOptions)
6666
} else {
67-
return Transaction.fromSerializedTx(rawData, txOptions)
67+
return Transaction.fromSerializedTx(data, txOptions)
6868
}
6969
}
7070

packages/tx/test/transactionFactory.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ const simpleSignedTransaction = simpleUnsignedTransaction.sign(pKey)
2626
tape('[TransactionFactory]: Basic functions', function (t) {
2727
t.test('should return the right type', function (st) {
2828
const serialized = simpleUnsignedAccessListEIP2930Transaction.serialize()
29-
const factoryTx = TransactionFactory.fromRawData(serialized, { common: EIP2930Common })
29+
const factoryTx = TransactionFactory.fromSerializedData(serialized, { common: EIP2930Common })
3030
st.equals(factoryTx.constructor.name, AccessListEIP2930Transaction.name)
3131

3232
const legacyTx = Transaction.fromTxData({})
3333
const serializedLegacyTx = legacyTx.serialize()
34-
const factoryLegacyTx = TransactionFactory.fromRawData(serializedLegacyTx, {})
34+
const factoryLegacyTx = TransactionFactory.fromSerializedData(serializedLegacyTx, {})
3535
st.equals(factoryLegacyTx.constructor.name, Transaction.name)
3636

3737
st.end()
@@ -41,7 +41,10 @@ tape('[TransactionFactory]: Basic functions', function (t) {
4141
'should throw when trying to create EIP-2718 typed transactions when not allowed in Common',
4242
function (st) {
4343
st.throws(() => {
44-
TransactionFactory.fromRawData(simpleUnsignedAccessListEIP2930Transaction.serialize(), {})
44+
TransactionFactory.fromSerializedData(
45+
simpleUnsignedAccessListEIP2930Transaction.serialize(),
46+
{}
47+
)
4548
})
4649
st.end()
4750
}
@@ -53,7 +56,7 @@ tape('[TransactionFactory]: Basic functions', function (t) {
5356
st.throws(() => {
5457
const serialized = simpleUnsignedAccessListEIP2930Transaction.serialize()
5558
serialized[0] = 2 // edit the transaction type
56-
TransactionFactory.fromRawData(serialized, { common: EIP2930Common })
59+
TransactionFactory.fromSerializedData(serialized, { common: EIP2930Common })
5760
})
5861
st.end()
5962
}

0 commit comments

Comments
 (0)