Skip to content

Commit

Permalink
tx: remove gasPrice from baseTransaction
Browse files Browse the repository at this point in the history
tx: export EIP1559
  • Loading branch information
jochem-brouwer committed Mar 21, 2021
1 parent 4b48879 commit ec78daf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
5 changes: 1 addition & 4 deletions packages/tx/src/baseTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
export abstract class BaseTransaction<TransactionObject> {
public readonly nonce: BN
public readonly gasLimit: BN
public readonly gasPrice: BN
public readonly to?: Address
public readonly value: BN
public readonly data: Buffer
Expand All @@ -30,10 +29,9 @@ export abstract class BaseTransaction<TransactionObject> {
public readonly s?: BN

constructor(txData: TxData, txOptions: TxOptions = {}) {
const { nonce, gasLimit, gasPrice, to, value, data, v, r, s } = txData
const { nonce, gasLimit, to, value, data, v, r, s } = txData

this.nonce = new BN(toBuffer(nonce))
this.gasPrice = new BN(toBuffer(gasPrice))
this.gasLimit = new BN(toBuffer(gasLimit))
this.to = to ? new Address(toBuffer(to)) : undefined
this.value = new BN(toBuffer(value))
Expand All @@ -45,7 +43,6 @@ export abstract class BaseTransaction<TransactionObject> {

this._validateCannotExceedMaxInteger({
nonce: this.nonce,
gasPrice: this.gasPrice,
gasLimit: this.gasLimit,
value: this.value,
})
Expand Down
6 changes: 5 additions & 1 deletion packages/tx/src/eip2930Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default class AccessListEIP2930Transaction extends BaseTransaction<Access
public readonly chainId: BN
public readonly accessList: AccessListBuffer
public readonly AccessListJSON: AccessList
public readonly gasPrice: BN

get transactionType(): number {
return 1
Expand Down Expand Up @@ -123,7 +124,7 @@ export default class AccessListEIP2930Transaction extends BaseTransaction<Access
* Use the static factory methods to assist in creating a Transaction object from varying data types.
*/
public constructor(txData: AccessListEIP2930TxData, opts: TxOptions = {}) {
const { chainId, accessList } = txData
const { chainId, accessList, gasPrice } = txData

super(txData, opts)

Expand All @@ -140,6 +141,9 @@ export default class AccessListEIP2930Transaction extends BaseTransaction<Access
AccessLists.verifyAccessList(this.accessList)

this.chainId = chainId ? new BN(toBuffer(chainId)) : this.common.chainIdBN()
this.gasPrice = new BN(toBuffer(gasPrice))

this._validateCannotExceedMaxInteger({ gasPrice: this.gasPrice })

if (!this.chainId.eq(this.common.chainIdBN())) {
throw new Error('The chain ID does not match the chain ID of Common')
Expand Down
1 change: 1 addition & 0 deletions packages/tx/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { default as Transaction } from './legacyTransaction'
export { default as AccessListEIP2930Transaction } from './eip2930Transaction'
export { default as TransactionFactory } from './transactionFactory'
export { default as FeeMarketEIP1559Transaction } from './eip1559Transaction'
export * from './types'
6 changes: 5 additions & 1 deletion packages/tx/src/legacyTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { BaseTransaction } from './baseTransaction'
* An Ethereum non-typed (legacy) transaction
*/
export default class Transaction extends BaseTransaction<Transaction> {
public readonly gasPrice: BN

get transactionType(): number {
return 0
}
Expand Down Expand Up @@ -96,7 +98,9 @@ export default class Transaction extends BaseTransaction<Transaction> {
public constructor(txData: TxData, opts: TxOptions = {}) {
super(txData, opts)

this._validateCannotExceedMaxInteger({ r: this.r, s: this.s })
this.gasPrice = new BN(toBuffer(txData.gasPrice))

this._validateCannotExceedMaxInteger({ r: this.r, s: this.s, gasPrice: this.gasPrice })

this._validateTxV(this.v)

Expand Down

0 comments on commit ec78daf

Please sign in to comment.