aboutsummaryrefslogtreecommitdiffstats
path: root/core/state_transition.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/state_transition.go')
-rw-r--r--core/state_transition.go34
1 files changed, 20 insertions, 14 deletions
diff --git a/core/state_transition.go b/core/state_transition.go
index 9e81ddf28..7b7026c29 100644
--- a/core/state_transition.go
+++ b/core/state_transition.go
@@ -112,7 +112,7 @@ func (self *StateTransition) BuyGas() error {
sender := self.From()
if sender.Balance().Cmp(MessageGasValue(self.msg)) < 0 {
- return fmt.Errorf("Insufficient funds to pre-pay gas. Req %v, has %v", MessageGasValue(self.msg), sender.Balance())
+ return fmt.Errorf("insufficient ETH for gas (%x). Req %v, has %v", sender.Address()[:4], MessageGasValue(self.msg), sender.Balance())
}
coinbase := self.Coinbase()
@@ -186,15 +186,22 @@ func (self *StateTransition) TransitionState() (ret []byte, err error) {
vmenv := self.VmEnv()
var ref vm.ClosureRef
if MessageCreatesContract(msg) {
- self.rec = MakeContract(msg, self.state)
-
- ret, err, ref = vmenv.Create(sender, self.rec.Address(), self.msg.Data(), self.gas, self.gasPrice, self.value)
- ref.SetCode(ret)
+ contract := MakeContract(msg, self.state)
+ ret, err, ref = vmenv.Create(sender, contract.Address(), self.msg.Data(), self.gas, self.gasPrice, self.value)
+ if err == nil {
+ dataGas := big.NewInt(int64(len(ret)))
+ dataGas.Mul(dataGas, vm.GasCreateByte)
+ if err = self.UseGas(dataGas); err == nil {
+ //self.state.SetCode(ref.Address(), ret)
+ ref.SetCode(ret)
+ }
+ }
} else {
ret, err = vmenv.Call(self.From(), self.To().Address(), self.msg.Data(), self.gas, self.gasPrice, self.value)
}
+
if err != nil {
- statelogger.Debugln(err)
+ self.UseGas(self.gas)
}
return
@@ -211,20 +218,19 @@ func MakeContract(msg Message, state *state.StateDB) *state.StateObject {
}
func (self *StateTransition) RefundGas() {
- coinbaseSub := new(big.Int).Set(self.gas)
+ coinbase, sender := self.Coinbase(), self.From()
+ // Return remaining gas
+ remaining := new(big.Int).Mul(self.gas, self.msg.GasPrice())
+ sender.AddAmount(remaining)
+
uhalf := new(big.Int).Div(self.GasUsed(), ethutil.Big2)
for addr, ref := range self.state.Refunds() {
refund := ethutil.BigMin(uhalf, ref)
- coinbaseSub.Add(self.gas, refund)
+ self.gas.Add(self.gas, refund)
self.state.AddBalance([]byte(addr), refund.Mul(refund, self.msg.GasPrice()))
}
- coinbase, sender := self.Coinbase(), self.From()
- coinbase.RefundGas(coinbaseSub, self.msg.GasPrice())
-
- // Return remaining gas
- remaining := new(big.Int).Mul(self.gas, self.msg.GasPrice())
- sender.AddAmount(remaining)
+ coinbase.RefundGas(self.gas, self.msg.GasPrice())
}
func (self *StateTransition) GasUsed() *big.Int {