@@ -132,28 +132,12 @@ func ApplyMessage(evm *vm.EVM, msg Message, gp *GasPool) ([]byte, uint64, bool,
132
132
return NewStateTransition (evm , msg , gp ).TransitionDb ()
133
133
}
134
134
135
- func ( st * StateTransition ) from () vm. AccountRef {
136
- f := st . msg . From ()
137
- if ! st .state . Exist ( f ) {
138
- st . state . CreateAccount ( f )
135
+ // to returns the recipient of the message.
136
+ func ( st * StateTransition ) to () common. Address {
137
+ if st .msg == nil || st . msg . To () == nil /* contract creation */ {
138
+ return common. Address {}
139
139
}
140
- return vm .AccountRef (f )
141
- }
142
-
143
- func (st * StateTransition ) to () vm.AccountRef {
144
- if st .msg == nil {
145
- return vm.AccountRef {}
146
- }
147
- to := st .msg .To ()
148
- if to == nil {
149
- return vm.AccountRef {} // contract creation
150
- }
151
-
152
- reference := vm .AccountRef (* to )
153
- if ! st .state .Exist (* to ) {
154
- st .state .CreateAccount (* to )
155
- }
156
- return reference
140
+ return * st .msg .To ()
157
141
}
158
142
159
143
func (st * StateTransition ) useGas (amount uint64 ) error {
@@ -166,12 +150,8 @@ func (st *StateTransition) useGas(amount uint64) error {
166
150
}
167
151
168
152
func (st * StateTransition ) buyGas () error {
169
- var (
170
- state = st .state
171
- sender = st .from ()
172
- )
173
153
mgval := new (big.Int ).Mul (new (big.Int ).SetUint64 (st .msg .Gas ()), st .gasPrice )
174
- if state .GetBalance (sender . Address ()).Cmp (mgval ) < 0 {
154
+ if st . state .GetBalance (st . msg . From ()).Cmp (mgval ) < 0 {
175
155
return errInsufficientBalanceForGas
176
156
}
177
157
if err := st .gp .SubGas (st .msg .Gas ()); err != nil {
@@ -180,20 +160,17 @@ func (st *StateTransition) buyGas() error {
180
160
st .gas += st .msg .Gas ()
181
161
182
162
st .initialGas = st .msg .Gas ()
183
- state .SubBalance (sender . Address (), mgval )
163
+ st . state .SubBalance (st . msg . From (), mgval )
184
164
return nil
185
165
}
186
166
187
167
func (st * StateTransition ) preCheck () error {
188
- msg := st .msg
189
- sender := st .from ()
190
-
191
- // Make sure this transaction's nonce is correct
192
- if msg .CheckNonce () {
193
- nonce := st .state .GetNonce (sender .Address ())
194
- if nonce < msg .Nonce () {
168
+ // Make sure this transaction's nonce is correct.
169
+ if st .msg .CheckNonce () {
170
+ nonce := st .state .GetNonce (st .msg .From ())
171
+ if nonce < st .msg .Nonce () {
195
172
return ErrNonceTooHigh
196
- } else if nonce > msg .Nonce () {
173
+ } else if nonce > st . msg .Nonce () {
197
174
return ErrNonceTooLow
198
175
}
199
176
}
@@ -208,8 +185,7 @@ func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, failed bo
208
185
return
209
186
}
210
187
msg := st .msg
211
- sender := st .from () // err checked in preCheck
212
-
188
+ sender := vm .AccountRef (msg .From ())
213
189
homestead := st .evm .ChainConfig ().IsHomestead (st .evm .BlockNumber )
214
190
contractCreation := msg .To () == nil
215
191
@@ -233,8 +209,8 @@ func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, failed bo
233
209
ret , _ , st .gas , vmerr = evm .Create (sender , st .data , st .gas , st .value )
234
210
} else {
235
211
// Increment the nonce for the next transaction
236
- st .state .SetNonce (sender . Address (), st .state .GetNonce (sender .Address ())+ 1 )
237
- ret , st .gas , vmerr = evm .Call (sender , st .to (). Address () , st .data , st .gas , st .value )
212
+ st .state .SetNonce (msg . From (), st .state .GetNonce (sender .Address ())+ 1 )
213
+ ret , st .gas , vmerr = evm .Call (sender , st .to (), st .data , st .gas , st .value )
238
214
}
239
215
if vmerr != nil {
240
216
log .Debug ("VM returned with error" , "err" , vmerr )
@@ -260,10 +236,8 @@ func (st *StateTransition) refundGas() {
260
236
st .gas += refund
261
237
262
238
// Return ETH for remaining gas, exchanged at the original rate.
263
- sender := st .from ()
264
-
265
239
remaining := new (big.Int ).Mul (new (big.Int ).SetUint64 (st .gas ), st .gasPrice )
266
- st .state .AddBalance (sender . Address (), remaining )
240
+ st .state .AddBalance (st . msg . From (), remaining )
267
241
268
242
// Also return remaining gas to the block gas counter so it is
269
243
// available for the next transaction.
0 commit comments