aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/state_transition.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-06-16 18:25:18 +0800
committerobscuren <geffobscura@gmail.com>2014-06-16 18:25:18 +0800
commit0d7763283952a57e5421565cdda19ecabe3222f7 (patch)
tree859f056bb7587dabca96f54e7dc5213f3563cbb6 /ethchain/state_transition.go
parent8b15732c1e8a1a666ae7469bc43d989918ce754a (diff)
downloadgo-tangerine-0d7763283952a57e5421565cdda19ecabe3222f7.tar.gz
go-tangerine-0d7763283952a57e5421565cdda19ecabe3222f7.tar.zst
go-tangerine-0d7763283952a57e5421565cdda19ecabe3222f7.zip
Refund gas
Diffstat (limited to 'ethchain/state_transition.go')
-rw-r--r--ethchain/state_transition.go17
1 files changed, 13 insertions, 4 deletions
diff --git a/ethchain/state_transition.go b/ethchain/state_transition.go
index c88f4727f..25efd64cc 100644
--- a/ethchain/state_transition.go
+++ b/ethchain/state_transition.go
@@ -110,6 +110,15 @@ func (self *StateTransition) BuyGas() error {
return nil
}
+func (self *StateTransition) RefundGas() {
+ coinbase, sender := self.Coinbase(), self.Sender()
+ coinbase.RefundGas(self.gas, self.tx.GasPrice)
+
+ // Return remaining gas
+ remaining := new(big.Int).Mul(self.gas, self.tx.GasPrice)
+ sender.AddAmount(remaining)
+}
+
func (self *StateTransition) TransitionState() (err error) {
//snapshot := st.state.Snapshot()
@@ -141,6 +150,8 @@ func (self *StateTransition) TransitionState() (err error) {
// XXX Transactions after this point are considered valid.
defer func() {
+ self.RefundGas()
+
if sender != nil {
self.state.UpdateStateObject(sender)
}
@@ -148,6 +159,8 @@ func (self *StateTransition) TransitionState() (err error) {
if receiver != nil {
self.state.UpdateStateObject(receiver)
}
+
+ self.state.UpdateStateObject(self.Coinbase())
}()
// Increment the nonce for the next transaction
@@ -203,10 +216,6 @@ func (self *StateTransition) TransitionState() (err error) {
}
}
- // Return remaining gas
- remaining := new(big.Int).Mul(self.gas, tx.GasPrice)
- sender.AddAmount(remaining)
-
return nil
}