mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-06 02:52:19 +00:00
Added a buy gas method
This commit is contained in:
parent
4d3209ad1d
commit
1bf6f8b4a6
@ -108,10 +108,14 @@ func (c *StateObject) ReturnGas(gas, price *big.Int, state *State) {
|
|||||||
|
|
||||||
func (c *StateObject) AddAmount(amount *big.Int) {
|
func (c *StateObject) AddAmount(amount *big.Int) {
|
||||||
c.SetAmount(new(big.Int).Add(c.Amount, amount))
|
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) {
|
func (c *StateObject) SubAmount(amount *big.Int) {
|
||||||
c.SetAmount(new(big.Int).Sub(c.Amount, amount))
|
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) {
|
func (c *StateObject) SetAmount(amount *big.Int) {
|
||||||
@ -129,6 +133,17 @@ func (c *StateObject) ConvertGas(gas, price *big.Int) error {
|
|||||||
return nil
|
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
|
// Returns the address of the contract/account
|
||||||
func (c *StateObject) Address() []byte {
|
func (c *StateObject) Address() []byte {
|
||||||
return c.address
|
return c.address
|
||||||
@ -153,14 +168,14 @@ func (c *StateObject) RlpEncode() []byte {
|
|||||||
root = ""
|
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) {
|
func (c *StateObject) RlpDecode(data []byte) {
|
||||||
decoder := ethutil.NewValueFromBytes(data)
|
decoder := ethutil.NewValueFromBytes(data)
|
||||||
|
|
||||||
c.Amount = decoder.Get(0).BigInt()
|
c.Nonce = decoder.Get(0).Uint()
|
||||||
c.Nonce = decoder.Get(1).Uint()
|
c.Amount = decoder.Get(1).BigInt()
|
||||||
c.state = NewState(ethutil.NewTrie(ethutil.Config.Db, decoder.Get(2).Interface()))
|
c.state = NewState(ethutil.NewTrie(ethutil.Config.Db, decoder.Get(2).Interface()))
|
||||||
|
|
||||||
c.ScriptHash = decoder.Get(3).Bytes()
|
c.ScriptHash = decoder.Get(3).Bytes()
|
||||||
|
Loading…
Reference in New Issue
Block a user