Skip to content

Commit

Permalink
Merge pull request #10 from cerc-io/ian/v5_dev
Browse files Browse the repository at this point in the history
add `SetStorage` methods to StateDB and StateObject
  • Loading branch information
i-norden authored Mar 13, 2023
2 parents ac6d191 + 04a4cc7 commit 9f53f99
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
18 changes: 18 additions & 0 deletions state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,24 @@ func (s *stateObject) SetState(db Database, key, value common.Hash) {
s.setState(key, value)
}

// SetStorage replaces the entire state storage with the given one.
//
// After this function is called, all original state will be ignored and state
// lookup only happens in the fake state storage.
//
// Note this function should only be used for debugging purpose.
func (s *stateObject) SetStorage(storage map[common.Hash]common.Hash) {
// Allocate fake storage if it's nil.
if s.fakeStorage == nil {
s.fakeStorage = make(Storage)
}
for key, value := range storage {
s.fakeStorage[key] = value
}
// Don't bother journal since this function should only be used for
// debugging and the `fake` storage won't be committed to database.
}

func (s *stateObject) setState(key, value common.Hash) {
s.dirtyStorage[key] = value
}
Expand Down
9 changes: 9 additions & 0 deletions statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@ func (s *StateDB) SetState(addr common.Address, key, value common.Hash) {
}
}

// SetStorage replaces the entire storage for the specified account with given
// storage. This function should only be used for debugging.
func (s *StateDB) SetStorage(addr common.Address, storage map[common.Hash]common.Hash) {
stateObject := s.getOrNewStateObject(addr)
if stateObject != nil {
stateObject.SetStorage(storage)
}
}

// Suicide marks the given account as suicided.
// This clears the account balance.
//
Expand Down

0 comments on commit 9f53f99

Please sign in to comment.