diff options
author | obscuren <geffobscura@gmail.com> | 2014-06-16 17:14:01 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-06-16 17:14:01 +0800 |
commit | 9f62d441a7c785b88f89d52643a9deaa822af15e (patch) | |
tree | 66510d5afe5d931e50e652a9cdc135fbc3fc9e3f /ethchain/state_object.go | |
parent | b836267401b731a2cd17c4866a9727b4a05ec124 (diff) | |
download | go-tangerine-9f62d441a7c785b88f89d52643a9deaa822af15e.tar.gz go-tangerine-9f62d441a7c785b88f89d52643a9deaa822af15e.tar.zst go-tangerine-9f62d441a7c785b88f89d52643a9deaa822af15e.zip |
Moved gas limit err check to buy gas
Diffstat (limited to 'ethchain/state_object.go')
-rw-r--r-- | ethchain/state_object.go | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/ethchain/state_object.go b/ethchain/state_object.go index 3775d436c..03f4c9219 100644 --- a/ethchain/state_object.go +++ b/ethchain/state_object.go @@ -17,6 +17,11 @@ type StateObject struct { state *State script []byte initScript []byte + + // Total gas pool is the total amount of gas currently + // left if this object is the coinbase. Gas is directly + // purchased of the coinbase. + gasPool *big.Int } // Converts an transaction in to a state object @@ -139,14 +144,22 @@ func (c *StateObject) ConvertGas(gas, price *big.Int) error { return nil } +func (self *StateObject) SetGasPool(gasLimit *big.Int) { + self.gasPool = new(big.Int).Set(gasLimit) + + ethutil.Config.Log.Printf(ethutil.LogLevelSystem, "%x fuel (+ %v)", self.Address(), self.gasPool) +} + func (self *StateObject) BuyGas(gas, price *big.Int) error { + if self.gasPool.Cmp(gas) < 0 { + return GasLimitError(self.gasPool, gas) + } + rGas := new(big.Int).Set(gas) rGas.Mul(rGas, price) self.AddAmount(rGas) - // TODO Do sub from TotalGasPool - // and check if enough left return nil } @@ -158,7 +171,9 @@ func (self *StateObject) Copy() *StateObject { stCopy.ScriptHash = make([]byte, len(self.ScriptHash)) copy(stCopy.ScriptHash, self.ScriptHash) stCopy.Nonce = self.Nonce - stCopy.state = self.state.Copy() + if self.state != nil { + stCopy.state = self.state.Copy() + } stCopy.script = make([]byte, len(self.script)) copy(stCopy.script, self.script) stCopy.initScript = make([]byte, len(self.initScript)) |