GetOrNew for accessors. Fixes #404

This commit is contained in:
obscuren 2015-03-01 19:07:38 +01:00
parent 65cad14f9b
commit ac88ae86a3
2 changed files with 9 additions and 17 deletions

View File

@ -54,7 +54,7 @@ func (self *StateDB) Refund(addr []byte, gas *big.Int) {
// Retrieve the balance from the given address or 0 if object not found // Retrieve the balance from the given address or 0 if object not found
func (self *StateDB) GetBalance(addr []byte) *big.Int { func (self *StateDB) GetBalance(addr []byte) *big.Int {
stateObject := self.GetStateObject(addr) stateObject := self.GetOrNewStateObject(addr)
if stateObject != nil { if stateObject != nil {
return stateObject.balance return stateObject.balance
} }
@ -63,14 +63,14 @@ func (self *StateDB) GetBalance(addr []byte) *big.Int {
} }
func (self *StateDB) AddBalance(addr []byte, amount *big.Int) { func (self *StateDB) AddBalance(addr []byte, amount *big.Int) {
stateObject := self.GetStateObject(addr) stateObject := self.GetOrNewStateObject(addr)
if stateObject != nil { if stateObject != nil {
stateObject.AddBalance(amount) stateObject.AddBalance(amount)
} }
} }
func (self *StateDB) GetNonce(addr []byte) uint64 { func (self *StateDB) GetNonce(addr []byte) uint64 {
stateObject := self.GetStateObject(addr) stateObject := self.GetOrNewStateObject(addr)
if stateObject != nil { if stateObject != nil {
return stateObject.nonce return stateObject.nonce
} }
@ -79,7 +79,7 @@ func (self *StateDB) GetNonce(addr []byte) uint64 {
} }
func (self *StateDB) GetCode(addr []byte) []byte { func (self *StateDB) GetCode(addr []byte) []byte {
stateObject := self.GetStateObject(addr) stateObject := self.GetOrNewStateObject(addr)
if stateObject != nil { if stateObject != nil {
return stateObject.code return stateObject.code
} }
@ -88,7 +88,7 @@ func (self *StateDB) GetCode(addr []byte) []byte {
} }
func (self *StateDB) GetState(a, b []byte) []byte { func (self *StateDB) GetState(a, b []byte) []byte {
stateObject := self.GetStateObject(a) stateObject := self.GetOrNewStateObject(a)
if stateObject != nil { if stateObject != nil {
return stateObject.GetState(b).Bytes() return stateObject.GetState(b).Bytes()
} }
@ -97,28 +97,28 @@ func (self *StateDB) GetState(a, b []byte) []byte {
} }
func (self *StateDB) SetNonce(addr []byte, nonce uint64) { func (self *StateDB) SetNonce(addr []byte, nonce uint64) {
stateObject := self.GetStateObject(addr) stateObject := self.GetOrNewStateObject(addr)
if stateObject != nil { if stateObject != nil {
stateObject.SetNonce(nonce) stateObject.SetNonce(nonce)
} }
} }
func (self *StateDB) SetCode(addr, code []byte) { func (self *StateDB) SetCode(addr, code []byte) {
stateObject := self.GetStateObject(addr) stateObject := self.GetOrNewStateObject(addr)
if stateObject != nil { if stateObject != nil {
stateObject.SetCode(code) stateObject.SetCode(code)
} }
} }
func (self *StateDB) SetState(addr, key []byte, value interface{}) { func (self *StateDB) SetState(addr, key []byte, value interface{}) {
stateObject := self.GetStateObject(addr) stateObject := self.GetOrNewStateObject(addr)
if stateObject != nil { if stateObject != nil {
stateObject.SetState(key, ethutil.NewValue(value)) stateObject.SetState(key, ethutil.NewValue(value))
} }
} }
func (self *StateDB) Delete(addr []byte) bool { func (self *StateDB) Delete(addr []byte) bool {
stateObject := self.GetStateObject(addr) stateObject := self.GetOrNewStateObject(addr)
if stateObject != nil { if stateObject != nil {
stateObject.MarkForDeletion() stateObject.MarkForDeletion()

View File

@ -300,14 +300,6 @@ func (self *XEth) Transact(toStr, valueStr, gasStr, gasPriceStr, codeStr string)
tx.SetNonce(nonce) tx.SetNonce(nonce)
tx.Sign(key.PrivateKey) tx.Sign(key.PrivateKey)
//fmt.Printf("create tx: %x %v\n", tx.Hash()[:4], tx.Nonce())
// Do some pre processing for our "pre" events and hooks
//block := self.chainManager.NewBlock(key.Address())
//coinbase := state.GetOrNewStateObject(key.Address())
//coinbase.SetGasPool(block.GasLimit())
//self.blockProcessor.ApplyTransactions(coinbase, state, block, types.Transactions{tx}, true)
err = self.eth.TxPool().Add(tx) err = self.eth.TxPool().Add(tx)
if err != nil { if err != nil {
return "", err return "", err