Commit 6bd4296a authored by George Hotz's avatar George Hotz

nonces work

parent 78e78b68
...@@ -121,3 +121,11 @@ func newObject(db *StateDB, address common.Address, data Account) *stateObject { ...@@ -121,3 +121,11 @@ func newObject(db *StateDB, address common.Address, data Account) *stateObject {
func (s *stateObject) setBalance(amount *big.Int) { func (s *stateObject) setBalance(amount *big.Int) {
s.data.Balance = amount s.data.Balance = amount
} }
func (s *stateObject) SetNonce(nonce uint64) {
s.setNonce(nonce)
}
func (s *stateObject) setNonce(nonce uint64) {
s.data.Nonce = nonce
}
...@@ -199,6 +199,10 @@ func (s *StateDB) SetCode(addr common.Address, code []byte) { ...@@ -199,6 +199,10 @@ func (s *StateDB) SetCode(addr common.Address, code []byte) {
func (s *StateDB) SetNonce(addr common.Address, nonce uint64) { func (s *StateDB) SetNonce(addr common.Address, nonce uint64) {
fmt.Println("SetNonce", addr, nonce) fmt.Println("SetNonce", addr, nonce)
stateObject := s.GetOrNewStateObject(addr)
if stateObject != nil {
stateObject.SetNonce(nonce)
}
} }
func (s *StateDB) SetState(addr common.Address, key, value common.Hash) { func (s *StateDB) SetState(addr common.Address, key, value common.Hash) {
...@@ -281,3 +285,12 @@ func (s *StateDB) createObject(addr common.Address) (newobj, prev *stateObject) ...@@ -281,3 +285,12 @@ func (s *StateDB) createObject(addr common.Address) (newobj, prev *stateObject)
} }
return newobj, nil return newobj, nil
} }
// GetOrNewStateObject retrieves a state object or create a new state object if nil.
func (s *StateDB) GetOrNewStateObject(addr common.Address) *stateObject {
stateObject := s.getStateObject(addr)
if stateObject == nil {
stateObject, _ = s.createObject(addr)
}
return stateObject
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment