Commit c4edcd2e authored by OptimismBot's avatar OptimismBot Committed by GitHub

Merge pull request #6435 from ethereum-optimism/feat/storage-layout-getter

op-bindings: storage layout entry getter
parents 64649169 bd4a39a4
...@@ -2,6 +2,7 @@ package solc ...@@ -2,6 +2,7 @@ package solc
import ( import (
"encoding/json" "encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi"
) )
...@@ -36,7 +37,8 @@ type CompilerOutput struct { ...@@ -36,7 +37,8 @@ type CompilerOutput struct {
type CompilerOutputContracts map[string]CompilerOutputContract 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 { type CompilerOutputContract struct {
Abi abi.ABI `json:"abi"` Abi abi.ABI `json:"abi"`
Evm CompilerOutputEvm `json:"evm"` Evm CompilerOutputEvm `json:"evm"`
...@@ -44,11 +46,24 @@ type CompilerOutputContract struct { ...@@ -44,11 +46,24 @@ type CompilerOutputContract struct {
StorageLayout StorageLayout `json:"storageLayout"` StorageLayout StorageLayout `json:"storageLayout"`
} }
// StorageLayout represents the solc compilers output storage layout for
// a contract.
type StorageLayout struct { type StorageLayout struct {
Storage []StorageLayoutEntry `json:"storage"` Storage []StorageLayoutEntry `json:"storage"`
Types map[string]StorageLayoutType `json:"types"` 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 { type StorageLayoutEntry struct {
AstId uint `json:"astId"` AstId uint `json:"astId"`
Contract string `json:"contract"` 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