---
source: crates/sdk-derive/derive-core/src/storage_legacy.rs
expression: formatted
---
pub struct Balance {}
impl Balance {
    const SLOT: fluentbase_sdk::U256 = fluentbase_sdk::U256::from_limbs([
        0u64, 0u64, 0u64, 0u64,
    ]);
    fn get<SDK: fluentbase_sdk::SharedAPI>(sdk: &SDK, arg0: Address) -> U256 {
        let key = Self::key(sdk, arg0);
        <U256 as fluentbase_sdk::storage_legacy::DirectStorage<SDK>>::get(sdk, key)
    }
    fn set<SDK: fluentbase_sdk::SharedAPI>(sdk: &mut SDK, arg0: Address, value: U256) {
        let key = Self::key(sdk, arg0);
        <U256 as fluentbase_sdk::storage_legacy::DirectStorage<
            SDK,
        >>::set(sdk, key, value)
    }
    fn calculate_keys<SDK: fluentbase_sdk::SharedAPI>(
        sdk: &SDK,
        slot: fluentbase_sdk::U256,
        args: [fluentbase_sdk::U256; 1usize],
    ) -> fluentbase_sdk::U256 {
        let mut key = slot;
        for arg in args {
            key = Self::key_hash(sdk, key, arg);
        }
        key
    }
    fn key_hash<SDK: fluentbase_sdk::SharedAPI>(
        sdk: &SDK,
        slot: fluentbase_sdk::U256,
        key: fluentbase_sdk::U256,
    ) -> fluentbase_sdk::U256 {
        let mut raw_storage_key: [u8; 64] = [0; 64];
        raw_storage_key[0..32].copy_from_slice(&key.to_be_bytes::<32>());
        raw_storage_key[32..64].copy_from_slice(&slot.to_be_bytes::<32>());
        let storage_key = SDK::keccak256(&raw_storage_key[..]);
        fluentbase_sdk::U256::from_be_bytes(storage_key.0)
    }
    fn key<SDK: fluentbase_sdk::SharedAPI>(
        sdk: &SDK,
        arg0: Address,
    ) -> fluentbase_sdk::U256 {
        let args = [
            fluentbase_sdk::U256::from_be_bytes({
                let mut buf = fluentbase_sdk::codec::bytes::BytesMut::new();
                fluentbase_sdk::codec::SolidityABI::encode(&arg0, &mut buf, 0).unwrap();
                let bytes = buf.freeze().to_vec();
                let mut array = [0u8; 32];
                let start = 32 - bytes.len();
                array[start..].copy_from_slice(&bytes);
                array
            }),
        ];
        Self::calculate_keys(sdk, Self::SLOT, args)
    }
}
pub struct ArbitraryData {}
impl ArbitraryData {
    const SLOT: fluentbase_sdk::U256 = fluentbase_sdk::U256::from_limbs([
        1u64, 0u64, 0u64, 0u64,
    ]);
    fn get<SDK: fluentbase_sdk::SharedAPI>(sdk: &SDK, arg0: Address) -> Bytes {
        let key = Self::key(sdk, arg0);
        <Bytes as fluentbase_sdk::storage_legacy::StorageValueSolidity<
            SDK,
            Bytes,
        >>::get(sdk, key)
    }
    fn set<SDK: fluentbase_sdk::SharedAPI>(sdk: &mut SDK, arg0: Address, value: Bytes) {
        use fluentbase_sdk::storage_legacy::StorageValueSolidity;
        let key = Self::key(sdk, arg0);
        <Bytes as fluentbase_sdk::storage_legacy::StorageValueSolidity<
            SDK,
            Bytes,
        >>::set(sdk, key, value.clone());
    }
    fn calculate_keys<SDK: fluentbase_sdk::SharedAPI>(
        sdk: &SDK,
        slot: fluentbase_sdk::U256,
        args: [fluentbase_sdk::U256; 1usize],
    ) -> fluentbase_sdk::U256 {
        let mut key = slot;
        for arg in args {
            key = Self::key_hash(sdk, key, arg);
        }
        key
    }
    fn key_hash<SDK: fluentbase_sdk::SharedAPI>(
        sdk: &SDK,
        slot: fluentbase_sdk::U256,
        key: fluentbase_sdk::U256,
    ) -> fluentbase_sdk::U256 {
        let mut raw_storage_key: [u8; 64] = [0; 64];
        raw_storage_key[0..32].copy_from_slice(&key.to_be_bytes::<32>());
        raw_storage_key[32..64].copy_from_slice(&slot.to_be_bytes::<32>());
        let storage_key = SDK::keccak256(&raw_storage_key[..]);
        fluentbase_sdk::U256::from_be_bytes(storage_key.0)
    }
    fn key<SDK: fluentbase_sdk::SharedAPI>(
        sdk: &SDK,
        arg0: Address,
    ) -> fluentbase_sdk::U256 {
        let args = [
            fluentbase_sdk::U256::from_be_bytes({
                let mut buf = fluentbase_sdk::codec::bytes::BytesMut::new();
                fluentbase_sdk::codec::SolidityABI::encode(&arg0, &mut buf, 0).unwrap();
                let bytes = buf.freeze().to_vec();
                let mut array = [0u8; 32];
                let start = 32 - bytes.len();
                array[start..].copy_from_slice(&bytes);
                array
            }),
        ];
        Self::calculate_keys(sdk, Self::SLOT, args)
    }
}
pub struct Allowance {}
impl Allowance {
    const SLOT: fluentbase_sdk::U256 = fluentbase_sdk::U256::from_limbs([
        2u64, 0u64, 0u64, 0u64,
    ]);
    fn get<SDK: fluentbase_sdk::SharedAPI>(
        sdk: &SDK,
        arg0: Address,
        arg1: Address,
    ) -> U256 {
        let key = Self::key(sdk, arg0, arg1);
        <U256 as fluentbase_sdk::storage_legacy::DirectStorage<SDK>>::get(sdk, key)
    }
    fn set<SDK: fluentbase_sdk::SharedAPI>(
        sdk: &mut SDK,
        arg0: Address,
        arg1: Address,
        value: U256,
    ) {
        let key = Self::key(sdk, arg0, arg1);
        <U256 as fluentbase_sdk::storage_legacy::DirectStorage<
            SDK,
        >>::set(sdk, key, value)
    }
    fn calculate_keys<SDK: fluentbase_sdk::SharedAPI>(
        sdk: &SDK,
        slot: fluentbase_sdk::U256,
        args: [fluentbase_sdk::U256; 2usize],
    ) -> fluentbase_sdk::U256 {
        let mut key = slot;
        for arg in args {
            key = Self::key_hash(sdk, key, arg);
        }
        key
    }
    fn key_hash<SDK: fluentbase_sdk::SharedAPI>(
        sdk: &SDK,
        slot: fluentbase_sdk::U256,
        key: fluentbase_sdk::U256,
    ) -> fluentbase_sdk::U256 {
        let mut raw_storage_key: [u8; 64] = [0; 64];
        raw_storage_key[0..32].copy_from_slice(&key.to_be_bytes::<32>());
        raw_storage_key[32..64].copy_from_slice(&slot.to_be_bytes::<32>());
        let storage_key = SDK::keccak256(&raw_storage_key[..]);
        fluentbase_sdk::U256::from_be_bytes(storage_key.0)
    }
    fn key<SDK: fluentbase_sdk::SharedAPI>(
        sdk: &SDK,
        arg0: Address,
        arg1: Address,
    ) -> fluentbase_sdk::U256 {
        let args = [
            fluentbase_sdk::U256::from_be_bytes({
                let mut buf = fluentbase_sdk::codec::bytes::BytesMut::new();
                fluentbase_sdk::codec::SolidityABI::encode(&arg0, &mut buf, 0).unwrap();
                let bytes = buf.freeze().to_vec();
                let mut array = [0u8; 32];
                let start = 32 - bytes.len();
                array[start..].copy_from_slice(&bytes);
                array
            }),
            fluentbase_sdk::U256::from_be_bytes({
                let mut buf = fluentbase_sdk::codec::bytes::BytesMut::new();
                fluentbase_sdk::codec::SolidityABI::encode(&arg1, &mut buf, 0).unwrap();
                let bytes = buf.freeze().to_vec();
                let mut array = [0u8; 32];
                let start = 32 - bytes.len();
                array[start..].copy_from_slice(&bytes);
                array
            }),
        ];
        Self::calculate_keys(sdk, Self::SLOT, args)
    }
}
