Skip to content

Commit 2e08cc6

Browse files
committed
remove asList parameter in raw(), preferring to use serialize()
1 parent e27fa1a commit 2e08cc6

File tree

5 files changed

+11
-46
lines changed

5 files changed

+11
-46
lines changed

packages/tx/src/baseTransaction.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,9 @@ export abstract class BaseTransaction<TransactionObject> {
112112
}
113113

114114
/**
115-
* Returns the raw `Buffer[]` (Transaction) or `Buffer` (typed transaction).
116-
* This is the data which is found in the transactions of the block body.
117-
*
118-
* Note that if you want to use this function in a tx type independent way
119-
* to then use the raw data output for tx instantiation with
120-
* `Tx.fromValuesArray()` you should set the `asList` parameter to `true` -
121-
* which is ignored on a legacy tx but provides the correct format on
122-
* a typed tx.
123-
*
124-
* To prepare a tx to be added as block data with `Block.fromValuesArray()`
125-
* just use the plain `raw()` method.
115+
* Returns a Buffer Array of the raw Buffers of this transaction, in order.
126116
*/
127-
abstract raw(asList: boolean): Buffer[] | Buffer
117+
abstract raw(): Buffer[]
128118

129119
/**
130120
* Returns the encoding of the transaction.

packages/tx/src/eip2930Transaction.ts

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -246,52 +246,36 @@ export default class AccessListEIP2930Transaction extends BaseTransaction<Access
246246
/**
247247
* Returns a Buffer Array of the raw Buffers of this transaction, in order.
248248
*
249-
* Note that if you want to use this function in a tx type independent way
250-
* to then use the raw data output for tx instantiation with
251-
* `Tx.fromValuesArray()` you should set the `asList` parameter to `true` -
252-
* which is ignored on a legacy tx but provides the correct format on
253-
* a typed tx.
254-
*
255-
* To prepare a tx to be added as block data with `Block.fromValuesArray()`
256-
* just use the plain `raw()` method.
257-
*
258-
* @param asList - By default, this method returns a concatenated Buffer
259-
* If this is not desired, then set this to `true`, to get a Buffer array.
249+
* Use `serialize()` to add to block data for `Block.fromValuesArray()`.
260250
*/
261-
raw(asList = false): Buffer[] | Buffer {
262-
const base = <Buffer[]>[
251+
raw(): Buffer[] {
252+
return [
263253
bnToRlp(this.chainId),
264254
bnToRlp(this.nonce),
265255
bnToRlp(this.gasPrice),
266256
bnToRlp(this.gasLimit),
267257
this.to !== undefined ? this.to.buf : Buffer.from([]),
268258
bnToRlp(this.value),
269259
this.data,
270-
this.accessList,
260+
<any>this.accessList,
271261
this.v !== undefined ? bnToRlp(this.v) : Buffer.from([]),
272262
this.r !== undefined ? bnToRlp(this.r) : Buffer.from([]),
273263
this.s !== undefined ? bnToRlp(this.s) : Buffer.from([]),
274264
]
275-
if (!asList) {
276-
return Buffer.concat([Buffer.from('01', 'hex'), rlp.encode(base)])
277-
} else {
278-
return base
279-
}
280265
}
281266

282267
/**
283-
* Returns the encoding of the transaction. For typed transaction, this is the raw Buffer.
284-
* In Transaction, this is a Buffer array.
268+
* Returns the serialized encoding of the transaction.
285269
*/
286270
serialize(): Buffer {
287-
return <Buffer>this.raw()
271+
return Buffer.concat([Buffer.from('01', 'hex'), rlp.encode(this.raw())])
288272
}
289273

290274
/**
291275
* Computes a sha3-256 hash of the serialized unsigned tx, which is used to sign the transaction.
292276
*/
293277
getMessageToSign() {
294-
const base = this.raw(true).slice(0, 8)
278+
const base = this.raw().slice(0, 8)
295279
return keccak256(Buffer.concat([Buffer.from('01', 'hex'), rlp.encode(base)]))
296280
}
297281

packages/tx/src/legacyTransaction.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,6 @@ export default class Transaction extends BaseTransaction<Transaction> {
108108

109109
/**
110110
* Returns a Buffer Array of the raw Buffers of this transaction, in order.
111-
*
112-
* Note that if you want to use this function in a tx type independent way
113-
* to then use the raw data output for tx instantiation with
114-
* `Tx.fromValuesArray()` you should set the `asList` parameter to `true` -
115-
* which is ignored on a legacy tx but provides the correct format on
116-
* a typed tx.
117-
*
118-
* To prepare a tx to be added as block data with `Block.fromValuesArray()`
119-
* just use the plain `raw()` method.
120111
*/
121112
raw(): Buffer[] {
122113
return [

packages/tx/test/base.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ tape('[BaseTransaction]', function (t) {
121121
for (const txType of txTypes) {
122122
txType.txs.forEach(function (tx: any) {
123123
st.ok(
124-
txType.class.fromValuesArray(tx.raw(true), { common }),
124+
txType.class.fromValuesArray(tx.raw(), { common }),
125125
`${txType.name}: should do roundtrip raw() -> fromValuesArray()`
126126
)
127127
})

packages/tx/test/transactionFactory.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ tape('[TransactionFactory]: Basic functions', function (t) {
8686

8787
t.test('should decode raw block body data', function (st) {
8888
const rawLegacy = simpleSignedTransaction.raw()
89-
const rawEIP2930 = simpleSignedAccessListEIP2930Transaction.raw()
89+
const rawEIP2930 = simpleSignedAccessListEIP2930Transaction.serialize()
9090

9191
const legacyTx = TransactionFactory.fromBlockBodyData(rawLegacy)
9292
const eip2930Tx = TransactionFactory.fromBlockBodyData(rawEIP2930, { common: EIP2930Common })

0 commit comments

Comments
 (0)