Skip to content

Commit 4bbb6e3

Browse files
holgerd77s1na
authored andcommitted
Update ethereumjs-tx library to v2.0.0 (ethereumjs#541)
* Updated ethereumjs-tx dependency from 1.3.7 to v2.1.0, move to runtime dependencies, updated ethereumjs-common to v1.3.0 * Updated ethereumjs-tx imports in tests * Added Transaction type to runTx * Access tx from address via getSenderAddress()
1 parent 81ecb35 commit 4bbb6e3

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

lib/runTx.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import BN = require('bn.js')
22
import { toBuffer } from 'ethereumjs-util'
33
import Account from 'ethereumjs-account'
4+
import { Transaction } from 'ethereumjs-tx'
45
import VM from './index'
56
import Bloom from './bloom'
67
import { default as EVM, EVMResult } from './evm/evm'
@@ -20,7 +21,7 @@ export interface RunTxOpts {
2021
/**
2122
* A [`Transaction`](https://github.com/ethereum/ethereumjs-tx) to run
2223
*/
23-
tx: any // TODO: Update ethereumjs-tx
24+
tx: Transaction
2425
/**
2526
* If true, skips the nonce check
2627
*/
@@ -108,7 +109,7 @@ async function _runTx(this: VM, opts: RunTxOpts): Promise<RunTxResult> {
108109
gasLimit.isub(basefee)
109110

110111
// Check from account's balance and nonce
111-
let fromAccount = await state.getAccount(tx.from)
112+
let fromAccount = await state.getAccount(tx.getSenderAddress())
112113
if (!opts.skipBalance && new BN(fromAccount.balance).lt(tx.getUpfrontCost())) {
113114
throw new Error(
114115
`sender doesn't have enough funds to send tx. The upfront cost is: ${tx
@@ -129,14 +130,14 @@ async function _runTx(this: VM, opts: RunTxOpts): Promise<RunTxResult> {
129130
fromAccount.balance = toBuffer(
130131
new BN(fromAccount.balance).sub(new BN(tx.gasLimit).mul(new BN(tx.gasPrice))),
131132
)
132-
await state.putAccount(tx.from, fromAccount)
133+
await state.putAccount(tx.getSenderAddress(), fromAccount)
133134

134135
/*
135136
* Execute message
136137
*/
137-
const txContext = new TxContext(tx.gasPrice, tx.from)
138+
const txContext = new TxContext(tx.gasPrice, tx.getSenderAddress())
138139
const message = new Message({
139-
caller: tx.from,
140+
caller: tx.getSenderAddress(),
140141
gasLimit: gasLimit,
141142
to: tx.to.toString('hex') !== '' ? tx.to : undefined,
142143
value: tx.value,
@@ -165,13 +166,13 @@ async function _runTx(this: VM, opts: RunTxOpts): Promise<RunTxResult> {
165166
results.amountSpent = results.gasUsed.mul(new BN(tx.gasPrice))
166167

167168
// Update sender's balance
168-
fromAccount = await state.getAccount(tx.from)
169+
fromAccount = await state.getAccount(tx.getSenderAddress())
169170
const finalFromBalance = new BN(tx.gasLimit)
170171
.sub(results.gasUsed)
171172
.mul(new BN(tx.gasPrice))
172173
.add(new BN(fromAccount.balance))
173174
fromAccount.balance = toBuffer(finalFromBalance)
174-
await state.putAccount(toBuffer(tx.from), fromAccount)
175+
await state.putAccount(toBuffer(tx.getSenderAddress()), fromAccount)
175176

176177
// Update miner's balance
177178
const minerAccount = await state.getAccount(block.header.coinbase)

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
"ethereumjs-account": "^3.0.0",
5454
"ethereumjs-block": "~2.2.0",
5555
"ethereumjs-blockchain": "^4.0.1",
56-
"ethereumjs-common": "1.2.1",
56+
"ethereumjs-common": "^1.3.0",
57+
"ethereumjs-tx": "^2.1.0",
5758
"ethereumjs-util": "^6.1.0",
5859
"fake-merkle-patricia-tree": "^1.0.1",
5960
"functional-red-black-tree": "^1.0.1",
@@ -74,7 +75,6 @@
7475
"browserify": "^16.2.3",
7576
"coveralls": "^3.0.0",
7677
"ethereumjs-testing": "git+https://github.com/ethereumjs/ethereumjs-testing.git#v1.2.7",
77-
"ethereumjs-tx": "1.3.7",
7878
"husky": "^2.1.0",
7979
"karma": "^4.0.1",
8080
"karma-browserify": "^6.0.0",

tests/api/runTx.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const promisify = require('util.promisify')
22
const tape = require('tape')
3-
const Transaction = require('ethereumjs-tx')
3+
const Transaction = require('ethereumjs-tx').Transaction
44
const ethUtil = require('ethereumjs-util')
55
const runTx = require('../../dist/runTx').default
66
const { StateManager } = require('../../dist/state')

tests/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const utils = require('ethereumjs-util')
33
const BN = utils.BN
44
const rlp = utils.rlp
55
const Account = require('ethereumjs-account').default
6-
const Transaction = require('ethereumjs-tx')
6+
const Transaction = require('ethereumjs-tx').Transaction
77
const Block = require('ethereumjs-block')
88

99
exports.dumpState = function (state, cb) {

0 commit comments

Comments
 (0)