pub struct StorageLayout {
pub variables: Vec<StorageVariable>,
pub types: BTreeMap<String, StorageType>,
pub source: Value,
pub enum_variants: BTreeMap<String, Vec<String>>,
}Expand description
The layout of one contract’s storage as solc emitted it.
Fields§
§variables: Vec<StorageVariable>State variables in declaration order.
types: BTreeMap<String, StorageType>Types by solc’s identifier, such as t_uint256 or t_mapping(t_address,t_uint256).
source: ValueThe layout exactly as the compiler wrote it, for handing to a client that decodes slots itself.
enum_variants: BTreeMap<String, Vec<String>>The variants of each enum, in declaration order, keyed by the name a type label
spells (Shop.Color) and by its bare name (Color). The layout itself only
numbers enum values; whoever has the sources fills this in, and a value then
decodes as Color.Blue rather than 2.
Implementations§
Source§impl StorageLayout
impl StorageLayout
Sourcepub fn parse(value: &Value) -> SoldbResult<Self>
pub fn parse(value: &Value) -> SoldbResult<Self>
Parses the <Contract>_storage.json solc writes, or the storageLayout object of
standard JSON output.
pub fn variable(&self, label: &str) -> Option<&StorageVariable>
pub fn type_of(&self, type_id: &str) -> Option<&StorageType>
Sourcepub fn variable_type(
&self,
variable: &StorageVariable,
) -> SoldbResult<&StorageType>
pub fn variable_type( &self, variable: &StorageVariable, ) -> SoldbResult<&StorageType>
The type of a variable, when the layout describes it.
Sourcepub fn resolve(&self, path: &str) -> SoldbResult<StorageRef>
pub fn resolve(&self, path: &str) -> SoldbResult<StorageRef>
Resolves a path to a place in storage: a variable, a mapping entry (m[key]), an
array element (a[i]), a struct member (s.member), or any chain of those.
Sourcepub fn walk(
&self,
start: StorageRef,
segments: impl IntoIterator<Item = PathSegment>,
) -> SoldbResult<StorageRef>
pub fn walk( &self, start: StorageRef, segments: impl IntoIterator<Item = PathSegment>, ) -> SoldbResult<StorageRef>
Follows segments from start: a mapping entry ([key]), an array element
([i]), a struct member (.member), or any chain of those. This is how a path
continues from a place that is not a state variable, such as a storage pointer
held by a local variable.
Sourcepub fn decode(
&self,
reference: &StorageRef,
read: &dyn Fn(&Word) -> Option<Word>,
) -> Result<DecodedStorage, Word>
pub fn decode( &self, reference: &StorageRef, read: &dyn Fn(&Word) -> Option<Word>, ) -> Result<DecodedStorage, Word>
Decodes the value at reference, reading each storage word it needs through
read. Err names the first slot whose word was not available.