pub struct Layout { /* private fields */ }Expand description
A parsed storage layout.
Implementations§
Source§impl Layout
impl Layout
Sourcepub fn erc7201_slot(id: &str) -> B256
pub fn erc7201_slot(id: &str) -> B256
ERC-7201 base slot: keccak256(abi.encode(uint256(keccak256(id)) - 1)) & ~0xff.
Sourcepub fn mount(&mut self, prefix: &str, other: &Layout, base: B256) -> Result<()>
pub fn mount(&mut self, prefix: &str, other: &Layout, base: B256) -> Result<()>
Mount other’s top-level variables as members of a struct named
prefix that starts at base: prefix.var, prefix.map[key], …
Types are merged by id (solc ids are canonical, so equal types agree).
Sourcepub fn from_manifest(path: impl AsRef<Path>) -> Result<Self>
pub fn from_manifest(path: impl AsRef<Path>) -> Result<Self>
Build from a manifest file (see [Manifest]).
Sourcepub fn is_dynamic_bytes(&self, loc: &Location) -> bool
pub fn is_dynamic_bytes(&self, loc: &Location) -> bool
Is this location a dynamic bytes / string?
Sourcepub fn bytes_data_slots(&self, loc: &Location, word: B256) -> Vec<B256> ⓘ
pub fn bytes_data_slots(&self, loc: &Location, word: B256) -> Vec<B256> ⓘ
For a dynamic bytes/string whose slot holds word: the extra
slots holding the data, in order. Empty for a short value (≤ 31
bytes, stored in place) or for anything that is not dynamic bytes.
Sourcepub fn decode_bytes(&self, loc: &Location, word: B256, chunks: &[B256]) -> Value
pub fn decode_bytes(&self, loc: &Location, word: B256, chunks: &[B256]) -> Value
Assemble a dynamic bytes/string from its slot word and the data
slots from Layout::bytes_data_slots (in order). Strings that are
not valid UTF-8 come back as bytes.
Sourcepub fn describe_slot_with_keys(
&self,
slot: B256,
array_probe: u64,
keys: &[B256],
) -> Vec<(String, Location)>
pub fn describe_slot_with_keys( &self, slot: B256, array_probe: u64, keys: &[B256], ) -> Vec<(String, Location)>
Layout::describe_slot plus mapping entries whose key is one of
keys (each a 32-byte word: an address left-padded, a number, …).
Two mapping levels are tried with the same candidates, and a struct
or array under a mapping is walked as usual.
Source§impl Layout
impl Layout
Sourcepub fn from_json(s: &str) -> Result<Self>
pub fn from_json(s: &str) -> Result<Self>
Accepts either a bare storageLayout object or a whole forge/hardhat
artifact that contains one.
Sourcepub fn from_artifact(path: impl AsRef<Path>) -> Result<Self>
pub fn from_artifact(path: impl AsRef<Path>) -> Result<Self>
Layout::from_json on the contents of path; a file with a
namespaces list is a manifest (Layout::from_manifest).
Sourcepub fn fields(&self) -> impl Iterator<Item = &StorageEntry>
pub fn fields(&self) -> impl Iterator<Item = &StorageEntry>
Top-level variables in declaration order.
Sourcepub fn locate(&self, path: &str) -> Result<Location>
pub fn locate(&self, path: &str) -> Result<Location>
Resolve a dotted/indexed path to its storage location.
Sourcepub fn decode(&self, loc: &Location, word: B256) -> Value
pub fn decode(&self, loc: &Location, word: B256) -> Value
Decode the value at loc out of a full 32-byte storage word.
Sourcepub fn kind_of(&self, path: &str) -> Result<PathKind>
pub fn kind_of(&self, path: &str) -> Result<PathKind>
What kind of thing a path names — a leaf value, or a container that
takes another path segment. Drives the Node view proxy.
Sourcepub fn decode_typed(&self, loc: &Location, word: B256) -> (ValueKind, Value)
pub fn decode_typed(&self, loc: &Location, word: B256) -> (ValueKind, Value)
Decode with an explicit kind, so callers that marshal across a language boundary know what the text is.
Sourcepub fn typescript(&self, name: &str) -> String
pub fn typescript(&self, name: &str) -> String
TypeScript declaration of the contract’s storage as the Node view
exposes it: bigint for integers, boolean, string for addresses
and bytes, nested objects for structs, index signatures for mappings
and arrays. name is the interface name.