func (self *StateDB) Refund(address common.Address, gas *big.Int) { addr := address.Str() if self.refund[addr] == nil { self.refund[addr] = new(big.Int) } self.refund[addr].Add(self.refund[addr], gas) }
// GetStateObject returns the state object of the given account or nil if the // account does not exist func (self *LightState) GetStateObject(ctx context.Context, addr common.Address) (stateObject *StateObject, err error) { stateObject = self.stateObjects[addr.Str()] if stateObject != nil { if stateObject.deleted { stateObject = nil } return stateObject, nil } data, err := self.trie.Get(ctx, addr[:]) if err != nil { return nil, err } if len(data) == 0 { return nil, nil } stateObject, err = DecodeObject(ctx, addr, self.odr, []byte(data)) if err != nil { return nil, err } self.SetStateObject(stateObject) return stateObject, nil }
// SetNonce sets the new canonical nonce for the managed state func (ms *ManagedState) SetNonce(addr common.Address, nonce uint64) { ms.mu.Lock() defer ms.mu.Unlock() so := ms.GetOrNewStateObject(addr) so.SetNonce(nonce) ms.accounts[addr.Str()] = newAccount(so) }
// NewStateObject create a state object whether it exist in the trie or not func (self *StateDB) newStateObject(addr common.Address) *StateObject { if glog.V(logger.Core) { glog.Infof("(+) %x\n", addr) } stateObject := NewStateObject(addr, self.db) self.stateObjects[addr.Str()] = stateObject return stateObject }
// newStateObject creates a state object whether it exists in the state or not func (self *LightState) newStateObject(addr common.Address) *StateObject { if glog.V(logger.Core) { glog.Infof("(+) %x\n", addr) } stateObject := NewStateObject(addr, self.odr) stateObject.SetNonce(StartingNonce) self.stateObjects[addr.Str()] = stateObject return stateObject }
// populate the managed state func (ms *ManagedState) getAccount(addr common.Address) *account { straddr := addr.Str() if account, ok := ms.accounts[straddr]; !ok { so := ms.GetOrNewStateObject(addr) ms.accounts[straddr] = newAccount(so) } else { // Always make sure the state account nonce isn't actually higher // than the tracked one. so := ms.StateDB.GetStateObject(addr) if so != nil && uint64(len(account.nonces))+account.nstart < so.nonce { ms.accounts[straddr] = newAccount(so) } } return ms.accounts[straddr] }
// Retrieve a state object given my the address. Nil if not found func (self *StateDB) GetStateObject(addr common.Address) *StateObject { //addr = common.Address(addr) stateObject := self.stateObjects[addr.Str()] if stateObject != nil { return stateObject } data := self.trie.Get(addr[:]) if len(data) == 0 { return nil } stateObject = NewStateObjectFromBytes(addr, []byte(data), self.db) self.SetStateObject(stateObject) return stateObject }
// Retrieve a state object given my the address. Nil if not found func (self *StateDB) GetStateObject(addr common.Address) (stateObject *StateObject) { stateObject = self.stateObjects[addr.Str()] if stateObject != nil { if stateObject.deleted { stateObject = nil } return stateObject } data := self.trie.Get(addr[:]) if len(data) == 0 { return nil } stateObject = NewStateObjectFromBytes(addr, []byte(data), self.db) self.SetStateObject(stateObject) return stateObject }
// Retrieve a state object given my the address. Nil if not found func (self *StateDB) GetStateObject(addr common.Address) (stateObject *StateObject) { stateObject = self.stateObjects[addr.Str()] if stateObject != nil { if stateObject.deleted { stateObject = nil } return stateObject } data := self.trie.Get(addr[:]) if len(data) == 0 { return nil } stateObject, err := DecodeObject(addr, self.db, data) if err != nil { glog.Errorf("can't decode object at %x: %v", addr[:], err) return nil } self.SetStateObject(stateObject) return stateObject }
func (ms *ManagedState) hasAccount(addr common.Address) bool { _, ok := ms.accounts[addr.Str()] return ok }