aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-06-12 03:55:34 +0800
committerobscuren <geffobscura@gmail.com>2014-06-12 03:55:34 +0800
commit1bf6f8b4a6936d8ad14b345b2cfa4dc9d1f8a360 (patch)
treed0ffa6ddb0d241b46dd090f043e77d639221c75e /ethchain
parent4d3209ad1d6ea6f7e4fc311c387392f23ebc7dde (diff)
downloadgo-tangerine-1bf6f8b4a6936d8ad14b345b2cfa4dc9d1f8a360.tar
go-tangerine-1bf6f8b4a6936d8ad14b345b2cfa4dc9d1f8a360.tar.gz
go-tangerine-1bf6f8b4a6936d8ad14b345b2cfa4dc9d1f8a360.tar.bz2
go-tangerine-1bf6f8b4a6936d8ad14b345b2cfa4dc9d1f8a360.tar.lz
go-tangerine-1bf6f8b4a6936d8ad14b345b2cfa4dc9d1f8a360.tar.xz
go-tangerine-1bf6f8b4a6936d8ad14b345b2cfa4dc9d1f8a360.tar.zst
go-tangerine-1bf6f8b4a6936d8ad14b345b2cfa4dc9d1f8a360.zip
Added a buy gas method
Diffstat (limited to 'ethchain')
-rw-r--r--ethchain/state_object.go21
1 files changed, 18 insertions, 3 deletions
diff --git a/ethchain/state_object.go b/ethchain/state_object.go
index 3e9c6df40..a1dd531de 100644
--- a/ethchain/state_object.go
+++ b/ethchain/state_object.go
@@ -108,10 +108,14 @@ func (c *StateObject) ReturnGas(gas, price *big.Int, state *State) {
func (c *StateObject) AddAmount(amount *big.Int) {
c.SetAmount(new(big.Int).Add(c.Amount, amount))
+
+ ethutil.Config.Log.Debugf("%x: #%d %v (+ %v)", c.Address(), c.Nonce, c.Amount, amount)
}
func (c *StateObject) SubAmount(amount *big.Int) {
c.SetAmount(new(big.Int).Sub(c.Amount, amount))
+
+ ethutil.Config.Log.Debugf("%x: #%d %v (- %v)", c.Address(), c.Nonce, c.Amount, amount)
}
func (c *StateObject) SetAmount(amount *big.Int) {
@@ -129,6 +133,17 @@ func (c *StateObject) ConvertGas(gas, price *big.Int) error {
return nil
}
+func (self *StateObject) BuyGas(gas, price *big.Int) error {
+ rGas := new(big.Int).Set(gas)
+ rGas.Mul(gas, price)
+
+ self.AddAmount(rGas)
+
+ // TODO Do sub from TotalGasPool
+ // and check if enough left
+ return nil
+}
+
// Returns the address of the contract/account
func (c *StateObject) Address() []byte {
return c.address
@@ -153,14 +168,14 @@ func (c *StateObject) RlpEncode() []byte {
root = ""
}
- return ethutil.Encode([]interface{}{c.Amount, c.Nonce, root, ethutil.Sha3Bin(c.script)})
+ return ethutil.Encode([]interface{}{c.Nonce, c.Amount, root, ethutil.Sha3Bin(c.script)})
}
func (c *StateObject) RlpDecode(data []byte) {
decoder := ethutil.NewValueFromBytes(data)
- c.Amount = decoder.Get(0).BigInt()
- c.Nonce = decoder.Get(1).Uint()
+ c.Nonce = decoder.Get(0).Uint()
+ c.Amount = decoder.Get(1).BigInt()
c.state = NewState(ethutil.NewTrie(ethutil.Config.Db, decoder.Get(2).Interface()))
c.ScriptHash = decoder.Get(3).Bytes()