1
1
import BN = require( 'bn.js' )
2
2
import { toBuffer } from 'ethereumjs-util'
3
3
import Account from 'ethereumjs-account'
4
+ import { Transaction } from 'ethereumjs-tx'
4
5
import VM from './index'
5
6
import Bloom from './bloom'
6
7
import { default as EVM , EVMResult } from './evm/evm'
@@ -20,7 +21,7 @@ export interface RunTxOpts {
20
21
/**
21
22
* A [`Transaction`](https://github.com/ethereum/ethereumjs-tx) to run
22
23
*/
23
- tx : any // TODO: Update ethereumjs-tx
24
+ tx : Transaction
24
25
/**
25
26
* If true, skips the nonce check
26
27
*/
@@ -108,7 +109,7 @@ async function _runTx(this: VM, opts: RunTxOpts): Promise<RunTxResult> {
108
109
gasLimit . isub ( basefee )
109
110
110
111
// Check from account's balance and nonce
111
- let fromAccount = await state . getAccount ( tx . from )
112
+ let fromAccount = await state . getAccount ( tx . getSenderAddress ( ) )
112
113
if ( ! opts . skipBalance && new BN ( fromAccount . balance ) . lt ( tx . getUpfrontCost ( ) ) ) {
113
114
throw new Error (
114
115
`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> {
129
130
fromAccount . balance = toBuffer (
130
131
new BN ( fromAccount . balance ) . sub ( new BN ( tx . gasLimit ) . mul ( new BN ( tx . gasPrice ) ) ) ,
131
132
)
132
- await state . putAccount ( tx . from , fromAccount )
133
+ await state . putAccount ( tx . getSenderAddress ( ) , fromAccount )
133
134
134
135
/*
135
136
* Execute message
136
137
*/
137
- const txContext = new TxContext ( tx . gasPrice , tx . from )
138
+ const txContext = new TxContext ( tx . gasPrice , tx . getSenderAddress ( ) )
138
139
const message = new Message ( {
139
- caller : tx . from ,
140
+ caller : tx . getSenderAddress ( ) ,
140
141
gasLimit : gasLimit ,
141
142
to : tx . to . toString ( 'hex' ) !== '' ? tx . to : undefined ,
142
143
value : tx . value ,
@@ -165,13 +166,13 @@ async function _runTx(this: VM, opts: RunTxOpts): Promise<RunTxResult> {
165
166
results . amountSpent = results . gasUsed . mul ( new BN ( tx . gasPrice ) )
166
167
167
168
// Update sender's balance
168
- fromAccount = await state . getAccount ( tx . from )
169
+ fromAccount = await state . getAccount ( tx . getSenderAddress ( ) )
169
170
const finalFromBalance = new BN ( tx . gasLimit )
170
171
. sub ( results . gasUsed )
171
172
. mul ( new BN ( tx . gasPrice ) )
172
173
. add ( new BN ( fromAccount . balance ) )
173
174
fromAccount . balance = toBuffer ( finalFromBalance )
174
- await state . putAccount ( toBuffer ( tx . from ) , fromAccount )
175
+ await state . putAccount ( toBuffer ( tx . getSenderAddress ( ) ) , fromAccount )
175
176
176
177
// Update miner's balance
177
178
const minerAccount = await state . getAccount ( block . header . coinbase )
0 commit comments