Setting, updating & deleting state object methods. updateStateObject writes the given object to the trie.
(obj *stateObject)
| 697 | |
| 698 | // updateStateObject writes the given object to the trie. |
| 699 | func (s *StateDB) updateStateObject(obj *stateObject) { |
| 700 | if s.noTrie { |
| 701 | return |
| 702 | } |
| 703 | // Track the amount of time wasted on updating the account from the trie |
| 704 | if metrics.EnabledExpensive { |
| 705 | defer func(start time.Time) { s.AccountUpdates += time.Since(start) }(time.Now()) |
| 706 | } |
| 707 | // Encode the account and update the account trie |
| 708 | addr := obj.Address() |
| 709 | if err := s.trie.UpdateAccount(addr, &obj.data); err != nil { |
| 710 | s.setError(fmt.Errorf("updateStateObject (%x) error: %v", addr[:], err)) |
| 711 | } |
| 712 | if obj.dirtyCode { |
| 713 | s.trie.UpdateContractCode(obj.Address(), common.BytesToHash(obj.CodeHash()), obj.code) |
| 714 | } |
| 715 | |
| 716 | // Track the original value of mutated account, nil means it was not present. |
| 717 | // Skip if it has been tracked (because updateStateObject may be called |
| 718 | // multiple times in a block). |
| 719 | if _, ok := s.accountsOrigin[obj.address]; !ok { |
| 720 | if obj.origin == nil { |
| 721 | s.accountsOrigin[obj.address] = nil |
| 722 | } else { |
| 723 | s.accountsOrigin[obj.address] = types.SlimAccountRLP(*obj.origin) |
| 724 | } |
| 725 | } |
| 726 | } |
| 727 | |
| 728 | // deleteStateObject removes the given object from the state trie. |
| 729 | func (s *StateDB) deleteStateObject(obj *stateObject) { |