@@ -134,112 +134,113 @@ func ApplyMessage(evm *vm.EVM, msg Message, gp *GasPool) ([]byte, *big.Int, erro
134134 return ret , gasUsed , err
135135}
136136
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 )
141141 }
142142 return vm .AccountRef (f )
143143}
144144
145- func (self * StateTransition ) to () vm.AccountRef {
146- if self .msg == nil {
145+ func (st * StateTransition ) to () vm.AccountRef {
146+ if st .msg == nil {
147147 return vm.AccountRef {}
148148 }
149- to := self .msg .To ()
149+ to := st .msg .To ()
150150 if to == nil {
151151 return vm.AccountRef {} // contract creation
152152 }
153153
154154 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 )
157157 }
158158 return reference
159159}
160160
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 {
163163 return vm .ErrOutOfGas
164164 }
165- self .gas -= amount
165+ st .gas -= amount
166166
167167 return nil
168168}
169169
170- func (self * StateTransition ) buyGas () error {
171- mgas := self .msg .Gas ()
170+ func (st * StateTransition ) buyGas () error {
171+ mgas := st .msg .Gas ()
172172 if mgas .BitLen () > 64 {
173173 return vm .ErrOutOfGas
174174 }
175175
176- mgval := new (big.Int ).Mul (mgas , self .gasPrice )
176+ mgval := new (big.Int ).Mul (mgas , st .gasPrice )
177177
178178 var (
179- state = self .state
180- sender = self .from ()
179+ state = st .state
180+ sender = st .from ()
181181 )
182182 if state .GetBalance (sender .Address ()).Cmp (mgval ) < 0 {
183183 return errInsufficientBalanceForGas
184184 }
185- if err := self .gp .SubGas (mgas ); err != nil {
185+ if err := st .gp .SubGas (mgas ); err != nil {
186186 return err
187187 }
188- self .gas += mgas .Uint64 ()
188+ st .gas += mgas .Uint64 ()
189189
190- self .initialGas .Set (mgas )
190+ st .initialGas .Set (mgas )
191191 state .SubBalance (sender .Address (), mgval )
192192 return nil
193193}
194194
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 ()
198198
199199 // Make sure this transaction's nonce is correct
200200 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 () {
202202 return fmt .Errorf ("invalid nonce: have %d, expected %d" , msg .Nonce (), n )
203203 }
204204 }
205- return self .buyGas ()
205+ return st .buyGas ()
206206}
207207
208208// TransitionDb will transition the state by applying the current message and returning the result
209209// including the required gas for the operation as well as the used gas. It returns an error if it
210210// 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 {
213213 return
214214 }
215- msg := self .msg
216- sender := self .from () // err checked in preCheck
215+ msg := st .msg
216+ sender := st .from () // err checked in preCheck
217217
218- homestead := self .evm .ChainConfig ().IsHomestead (self .evm .BlockNumber )
218+ homestead := st .evm .ChainConfig ().IsHomestead (st .evm .BlockNumber )
219219 contractCreation := msg .To () == nil
220+
220221 // Pay intrinsic gas
221222 // TODO convert to uint64
222- intrinsicGas := IntrinsicGas (self .data , contractCreation , homestead )
223+ intrinsicGas := IntrinsicGas (st .data , contractCreation , homestead )
223224 if intrinsicGas .BitLen () > 64 {
224225 return nil , nil , nil , vm .ErrOutOfGas
225226 }
226- if err = self .useGas (intrinsicGas .Uint64 ()); err != nil {
227+ if err = st .useGas (intrinsicGas .Uint64 ()); err != nil {
227228 return nil , nil , nil , err
228229 }
229230
230231 var (
231- evm = self .evm
232+ evm = st .evm
232233 // vm errors do not effect consensus and are therefor
233234 // not assigned to err, except for insufficient balance
234235 // error.
235236 vmerr error
236237 )
237238 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 )
239240 } else {
240241 // 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 )
243244 }
244245 if vmerr != nil {
245246 log .Debug ("VM returned with error" , "err" , err )
@@ -250,33 +251,33 @@ func (self *StateTransition) TransitionDb() (ret []byte, requiredGas, usedGas *b
250251 return nil , nil , nil , vmerr
251252 }
252253 }
253- requiredGas = new (big.Int ).Set (self .gasUsed ())
254+ requiredGas = new (big.Int ).Set (st .gasUsed ())
254255
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 ))
257258
258- return ret , requiredGas , self .gasUsed (), err
259+ return ret , requiredGas , st .gasUsed (), err
259260}
260261
261- func (self * StateTransition ) refundGas () {
262+ func (st * StateTransition ) refundGas () {
262263 // Return eth for remaining gas to the sender account,
263264 // 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 )
267268
268269 // 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 ()
272273
273- self .state .AddBalance (sender .Address (), refund .Mul (refund , self .gasPrice ))
274+ st .state .AddBalance (sender .Address (), refund .Mul (refund , st .gasPrice ))
274275
275276 // Also return remaining gas to the block gas counter so it is
276277 // 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 ))
278279}
279280
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 ))
282283}
0 commit comments