@@ -1771,10 +1771,11 @@ impl SimpleCast {
17711771 Ok ( hex:: encode_prefixed ( calldata) )
17721772 }
17731773
1774- /// Prints the slot number for the specified mapping type and input data .
1774+ /// Returns the slot number for a given mapping key and slot .
17751775 ///
1776- /// For value types `v`, slot number of `v` is `keccak256(concat(h(v), p))` where `h` is the
1777- /// padding function for `v`'s type, and `p` is slot number of the mapping.
1776+ /// Given `mapping(k => v) m`, for a key `k` the slot number of its associated `v` is
1777+ /// `keccak256(concat(h(k), p))`, where `h` is the padding function for `k`'s type, and `p`
1778+ /// is slot number of the mapping `m`.
17781779 ///
17791780 /// See [the Solidity documentation](https://docs.soliditylang.org/en/latest/internals/layout_in_storage.html#mappings-and-dynamic-arrays)
17801781 /// for more details.
@@ -1801,29 +1802,29 @@ impl SimpleCast {
18011802 /// );
18021803 /// # Ok::<_, eyre::Report>(())
18031804 /// ```
1804- pub fn index ( from_type : & str , from_value : & str , slot_number : & str ) -> Result < String > {
1805+ pub fn index ( key_type : & str , key : & str , slot_number : & str ) -> Result < String > {
18051806 let mut hasher = Keccak256 :: new ( ) ;
18061807
1807- let v_ty = DynSolType :: parse ( from_type ) . wrap_err ( "Could not parse type" ) ?;
1808- let v = v_ty . coerce_str ( from_value ) . wrap_err ( "Could not parse value" ) ?;
1809- match v_ty {
1808+ let k_ty = DynSolType :: parse ( key_type ) . wrap_err ( "Could not parse type" ) ?;
1809+ let k = k_ty . coerce_str ( key ) . wrap_err ( "Could not parse value" ) ?;
1810+ match k_ty {
18101811 // For value types, `h` pads the value to 32 bytes in the same way as when storing the
18111812 // value in memory.
18121813 DynSolType :: Bool |
18131814 DynSolType :: Int ( _) |
18141815 DynSolType :: Uint ( _) |
18151816 DynSolType :: FixedBytes ( _) |
18161817 DynSolType :: Address |
1817- DynSolType :: Function => hasher. update ( v . as_word ( ) . unwrap ( ) ) ,
1818+ DynSolType :: Function => hasher. update ( k . as_word ( ) . unwrap ( ) ) ,
18181819
18191820 // For strings and byte arrays, `h(k)` is just the unpadded data.
1820- DynSolType :: String | DynSolType :: Bytes => hasher. update ( v . as_packed_seq ( ) . unwrap ( ) ) ,
1821+ DynSolType :: String | DynSolType :: Bytes => hasher. update ( k . as_packed_seq ( ) . unwrap ( ) ) ,
18211822
18221823 DynSolType :: Array ( ..) |
18231824 DynSolType :: FixedArray ( ..) |
18241825 DynSolType :: Tuple ( ..) |
18251826 DynSolType :: CustomStruct { .. } => {
1826- eyre:: bail!( "Type `{v_ty }` is not supported as a mapping key" )
1827+ eyre:: bail!( "Type `{k_ty }` is not supported as a mapping key" )
18271828 }
18281829 }
18291830
0 commit comments