@@ -134,112 +134,113 @@ func ApplyMessage(evm *vm.EVM, msg Message, gp *GasPool) ([]byte, *big.Int, erro
134
134
return ret , gasUsed , err
135
135
}
136
136
137
- func (self * StateTransition ) from () vm.AccountRef {
138
- f := self .msg .From ()
139
- if ! self .state .Exist (f ) {
140
- self .state .CreateAccount (f )
137
+ func (st * StateTransition ) from () vm.AccountRef {
138
+ f := st .msg .From ()
139
+ if ! st .state .Exist (f ) {
140
+ st .state .CreateAccount (f )
141
141
}
142
142
return vm .AccountRef (f )
143
143
}
144
144
145
- func (self * StateTransition ) to () vm.AccountRef {
146
- if self .msg == nil {
145
+ func (st * StateTransition ) to () vm.AccountRef {
146
+ if st .msg == nil {
147
147
return vm.AccountRef {}
148
148
}
149
- to := self .msg .To ()
149
+ to := st .msg .To ()
150
150
if to == nil {
151
151
return vm.AccountRef {} // contract creation
152
152
}
153
153
154
154
reference := vm .AccountRef (* to )
155
- if ! self .state .Exist (* to ) {
156
- self .state .CreateAccount (* to )
155
+ if ! st .state .Exist (* to ) {
156
+ st .state .CreateAccount (* to )
157
157
}
158
158
return reference
159
159
}
160
160
161
- func (self * StateTransition ) useGas (amount uint64 ) error {
162
- if self .gas < amount {
161
+ func (st * StateTransition ) useGas (amount uint64 ) error {
162
+ if st .gas < amount {
163
163
return vm .ErrOutOfGas
164
164
}
165
- self .gas -= amount
165
+ st .gas -= amount
166
166
167
167
return nil
168
168
}
169
169
170
- func (self * StateTransition ) buyGas () error {
171
- mgas := self .msg .Gas ()
170
+ func (st * StateTransition ) buyGas () error {
171
+ mgas := st .msg .Gas ()
172
172
if mgas .BitLen () > 64 {
173
173
return vm .ErrOutOfGas
174
174
}
175
175
176
- mgval := new (big.Int ).Mul (mgas , self .gasPrice )
176
+ mgval := new (big.Int ).Mul (mgas , st .gasPrice )
177
177
178
178
var (
179
- state = self .state
180
- sender = self .from ()
179
+ state = st .state
180
+ sender = st .from ()
181
181
)
182
182
if state .GetBalance (sender .Address ()).Cmp (mgval ) < 0 {
183
183
return errInsufficientBalanceForGas
184
184
}
185
- if err := self .gp .SubGas (mgas ); err != nil {
185
+ if err := st .gp .SubGas (mgas ); err != nil {
186
186
return err
187
187
}
188
- self .gas += mgas .Uint64 ()
188
+ st .gas += mgas .Uint64 ()
189
189
190
- self .initialGas .Set (mgas )
190
+ st .initialGas .Set (mgas )
191
191
state .SubBalance (sender .Address (), mgval )
192
192
return nil
193
193
}
194
194
195
- func (self * StateTransition ) preCheck () error {
196
- msg := self .msg
197
- sender := self .from ()
195
+ func (st * StateTransition ) preCheck () error {
196
+ msg := st .msg
197
+ sender := st .from ()
198
198
199
199
// Make sure this transaction's nonce is correct
200
200
if msg .CheckNonce () {
201
- if n := self .state .GetNonce (sender .Address ()); n != msg .Nonce () {
201
+ if n := st .state .GetNonce (sender .Address ()); n != msg .Nonce () {
202
202
return fmt .Errorf ("invalid nonce: have %d, expected %d" , msg .Nonce (), n )
203
203
}
204
204
}
205
- return self .buyGas ()
205
+ return st .buyGas ()
206
206
}
207
207
208
208
// TransitionDb will transition the state by applying the current message and returning the result
209
209
// including the required gas for the operation as well as the used gas. It returns an error if it
210
210
// failed. An error indicates a consensus issue.
211
- func (self * StateTransition ) TransitionDb () (ret []byte , requiredGas , usedGas * big.Int , err error ) {
212
- if err = self .preCheck (); err != nil {
211
+ func (st * StateTransition ) TransitionDb () (ret []byte , requiredGas , usedGas * big.Int , err error ) {
212
+ if err = st .preCheck (); err != nil {
213
213
return
214
214
}
215
- msg := self .msg
216
- sender := self .from () // err checked in preCheck
215
+ msg := st .msg
216
+ sender := st .from () // err checked in preCheck
217
217
218
- homestead := self .evm .ChainConfig ().IsHomestead (self .evm .BlockNumber )
218
+ homestead := st .evm .ChainConfig ().IsHomestead (st .evm .BlockNumber )
219
219
contractCreation := msg .To () == nil
220
+
220
221
// Pay intrinsic gas
221
222
// TODO convert to uint64
222
- intrinsicGas := IntrinsicGas (self .data , contractCreation , homestead )
223
+ intrinsicGas := IntrinsicGas (st .data , contractCreation , homestead )
223
224
if intrinsicGas .BitLen () > 64 {
224
225
return nil , nil , nil , vm .ErrOutOfGas
225
226
}
226
- if err = self .useGas (intrinsicGas .Uint64 ()); err != nil {
227
+ if err = st .useGas (intrinsicGas .Uint64 ()); err != nil {
227
228
return nil , nil , nil , err
228
229
}
229
230
230
231
var (
231
- evm = self .evm
232
+ evm = st .evm
232
233
// vm errors do not effect consensus and are therefor
233
234
// not assigned to err, except for insufficient balance
234
235
// error.
235
236
vmerr error
236
237
)
237
238
if contractCreation {
238
- ret , _ , self .gas , vmerr = evm .Create (sender , self .data , self .gas , self .value )
239
+ ret , _ , st .gas , vmerr = evm .Create (sender , st .data , st .gas , st .value )
239
240
} else {
240
241
// Increment the nonce for the next transaction
241
- self .state .SetNonce (sender .Address (), self .state .GetNonce (sender .Address ())+ 1 )
242
- ret , self .gas , vmerr = evm .Call (sender , self .to ().Address (), self .data , self .gas , self .value )
242
+ st .state .SetNonce (sender .Address (), st .state .GetNonce (sender .Address ())+ 1 )
243
+ ret , st .gas , vmerr = evm .Call (sender , st .to ().Address (), st .data , st .gas , st .value )
243
244
}
244
245
if vmerr != nil {
245
246
log .Debug ("VM returned with error" , "err" , err )
@@ -250,33 +251,33 @@ func (self *StateTransition) TransitionDb() (ret []byte, requiredGas, usedGas *b
250
251
return nil , nil , nil , vmerr
251
252
}
252
253
}
253
- requiredGas = new (big.Int ).Set (self .gasUsed ())
254
+ requiredGas = new (big.Int ).Set (st .gasUsed ())
254
255
255
- self .refundGas ()
256
- self .state .AddBalance (self .evm .Coinbase , new (big.Int ).Mul (self .gasUsed (), self .gasPrice ))
256
+ st .refundGas ()
257
+ st .state .AddBalance (st .evm .Coinbase , new (big.Int ).Mul (st .gasUsed (), st .gasPrice ))
257
258
258
- return ret , requiredGas , self .gasUsed (), err
259
+ return ret , requiredGas , st .gasUsed (), err
259
260
}
260
261
261
- func (self * StateTransition ) refundGas () {
262
+ func (st * StateTransition ) refundGas () {
262
263
// Return eth for remaining gas to the sender account,
263
264
// exchanged at the original rate.
264
- sender := self .from () // err already checked
265
- remaining := new (big.Int ).Mul (new (big.Int ).SetUint64 (self .gas ), self .gasPrice )
266
- self .state .AddBalance (sender .Address (), remaining )
265
+ sender := st .from () // err already checked
266
+ remaining := new (big.Int ).Mul (new (big.Int ).SetUint64 (st .gas ), st .gasPrice )
267
+ st .state .AddBalance (sender .Address (), remaining )
267
268
268
269
// Apply refund counter, capped to half of the used gas.
269
- uhalf := remaining .Div (self .gasUsed (), common .Big2 )
270
- refund := math .BigMin (uhalf , self .state .GetRefund ())
271
- self .gas += refund .Uint64 ()
270
+ uhalf := remaining .Div (st .gasUsed (), common .Big2 )
271
+ refund := math .BigMin (uhalf , st .state .GetRefund ())
272
+ st .gas += refund .Uint64 ()
272
273
273
- self .state .AddBalance (sender .Address (), refund .Mul (refund , self .gasPrice ))
274
+ st .state .AddBalance (sender .Address (), refund .Mul (refund , st .gasPrice ))
274
275
275
276
// Also return remaining gas to the block gas counter so it is
276
277
// available for the next transaction.
277
- self .gp .AddGas (new (big.Int ).SetUint64 (self .gas ))
278
+ st .gp .AddGas (new (big.Int ).SetUint64 (st .gas ))
278
279
}
279
280
280
- func (self * StateTransition ) gasUsed () * big.Int {
281
- return new (big.Int ).Sub (self .initialGas , new (big.Int ).SetUint64 (self .gas ))
281
+ func (st * StateTransition ) gasUsed () * big.Int {
282
+ return new (big.Int ).Sub (st .initialGas , new (big.Int ).SetUint64 (st .gas ))
282
283
}
0 commit comments