Commit 5adbe662 authored by Mark Tyneway's avatar Mark Tyneway

op-bindings: storage layout entry getter

Adds a getter to the storage layout type for getting
the layout entry by label. This is generally a useful
operation when manipulating state manually, so writing
a function for it here instead of rewriting the same code
many times.

Part of https://github.com/ethereum-optimism/optimism/pull/6412
to make it easier to contribute to.
parent 3891726b
......@@ -2,6 +2,7 @@ package solc
import (
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/accounts/abi"
)
......@@ -36,7 +37,8 @@ type CompilerOutput struct {
type CompilerOutputContracts map[string]CompilerOutputContract
// TODO(tynes): ignoring devdoc and userdoc for now
// CompilerOutputContract represents the solc compiler output for a contract.
// Ignoring some fields such as devdoc and userdoc.
type CompilerOutputContract struct {
Abi abi.ABI `json:"abi"`
Evm CompilerOutputEvm `json:"evm"`
......@@ -44,11 +46,24 @@ type CompilerOutputContract struct {
StorageLayout StorageLayout `json:"storageLayout"`
}
// StorageLayout represents the solc compilers output storage layout for
// a contract.
type StorageLayout struct {
Storage []StorageLayoutEntry `json:"storage"`
Types map[string]StorageLayoutType `json:"types"`
}
// GetStorageLayoutEntry returns the StorageLayoutEntry where the label matches
// the provided name.
func (s *StorageLayout) GetStorageLayoutEntry(name string) (StorageLayoutEntry, error) {
for _, entry := range s.Storage {
if entry.Label == name {
return entry, nil
}
}
return StorageLayoutEntry{}, fmt.Errorf("%s not found", name)
}
type StorageLayoutEntry struct {
AstId uint `json:"astId"`
Contract string `json:"contract"`
......
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