Skip to content

Commit 1c6aee1

Browse files
committed
enhancement: DRY raw() values
1 parent dff5ca7 commit 1c6aee1

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

packages/tx/src/transaction.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,7 @@ export default class Transaction {
135135
* Computes a sha3-256 hash of the serialized tx
136136
*/
137137
hash(): Buffer {
138-
const values = [
139-
bnToRlp(this.nonce),
140-
bnToRlp(this.gasPrice),
141-
bnToRlp(this.gasLimit),
142-
this.to !== undefined ? this.to.buf : Buffer.from([]),
143-
bnToRlp(this.value),
144-
this.data,
145-
this.v ? bnToRlp(this.v) : Buffer.from([]),
146-
this.r ? bnToRlp(this.r) : Buffer.from([]),
147-
this.s ? bnToRlp(this.s) : Buffer.from([]),
148-
]
149-
150-
return rlphash(values)
138+
return rlphash(this.raw())
151139
}
152140

153141
getMessageToSign() {
@@ -383,14 +371,7 @@ export default class Transaction {
383371
}
384372

385373
private _getMessageToSign(withEIP155: boolean) {
386-
const values = [
387-
bnToRlp(this.nonce),
388-
bnToRlp(this.gasPrice),
389-
bnToRlp(this.gasLimit),
390-
this.to !== undefined ? this.to.buf : Buffer.from([]),
391-
bnToRlp(this.value),
392-
this.data,
393-
]
374+
const values = this.raw().slice(0, 6)
394375

395376
if (withEIP155) {
396377
values.push(toBuffer(this.getChainId()))

0 commit comments

Comments
 (0)