Skip to main content

Layout

Struct Layout 

Source
pub struct Layout { /* private fields */ }
Expand description

A parsed storage layout.

Implementations§

Source§

impl Layout

Source

pub fn erc7201_slot(id: &str) -> B256

ERC-7201 base slot: keccak256(abi.encode(uint256(keccak256(id)) - 1)) & ~0xff.

Source

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).

Source

pub fn from_manifest(path: impl AsRef<Path>) -> Result<Self>

Build from a manifest file (see [Manifest]).

Source

pub fn is_dynamic_bytes(&self, loc: &Location) -> bool

Is this location a dynamic bytes / string?

Source

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.

Source

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.

Source

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

Source

pub fn from_json(s: &str) -> Result<Self>

Accepts either a bare storageLayout object or a whole forge/hardhat artifact that contains one.

Source

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).

Source

pub fn fields(&self) -> impl Iterator<Item = &StorageEntry>

Top-level variables in declaration order.

Source

pub fn locate(&self, path: &str) -> Result<Location>

Resolve a dotted/indexed path to its storage location.

Source

pub fn decode(&self, loc: &Location, word: B256) -> Value

Decode the value at loc out of a full 32-byte storage word.

Source

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.

Source

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.

Source

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.

Source

pub fn describe_slot( &self, slot: B256, array_probe: u64, ) -> Vec<(String, Location)>

Human name(s) for a raw slot: top-level values, struct members, and dynamic-array elements within array_probe slots of the data start. Mapping entries cannot be named without a candidate key.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.