//! Translates the storage operations. use crate::polkavm::context::runtime::RuntimeFunction; use crate::polkavm::context::Context; use crate::polkavm::Dependency; use crate::PolkaVMArgument; use crate::PolkaVMLoadStorageWordFunction; use crate::PolkaVMLoadTransientStorageWordFunction; use crate::PolkaVMStoreStorageWordFunction; use crate::PolkaVMStoreTransientStorageWordFunction; /// Translates the storage load. pub fn load<'ctx, D>( context: &mut Context<'ctx, D>, position: &PolkaVMArgument<'ctx>, ) -> anyhow::Result> where D: Dependency + Clone, { let name = >::NAME; let declaration = >::declaration(context); let arguments = [position.as_pointer(context)?.value.into()]; Ok(context .build_call(declaration, &arguments, "storage_load") .unwrap_or_else(|| panic!("runtime function {name} should return a value"))) } /// Translates the storage store. pub fn store<'ctx, D>( context: &mut Context<'ctx, D>, position: &PolkaVMArgument<'ctx>, value: &PolkaVMArgument<'ctx>, ) -> anyhow::Result<()> where D: Dependency + Clone, { let declaration = >::declaration(context); let arguments = [ position.as_pointer(context)?.value.into(), value.as_pointer(context)?.value.into(), ]; context.build_call(declaration, &arguments, "storage_store"); Ok(()) } /// Translates the transient storage load. pub fn transient_load<'ctx, D>( context: &mut Context<'ctx, D>, position: &PolkaVMArgument<'ctx>, ) -> anyhow::Result> where D: Dependency + Clone, { let name = >::NAME; let arguments = [position.as_pointer(context)?.value.into()]; let declaration = >::declaration(context); Ok(context .build_call(declaration, &arguments, "transient_storage_load") .unwrap_or_else(|| panic!("runtime function {name} should return a value"))) } /// Translates the transient storage store. pub fn transient_store<'ctx, D>( context: &mut Context<'ctx, D>, position: &PolkaVMArgument<'ctx>, value: &PolkaVMArgument<'ctx>, ) -> anyhow::Result<()> where D: Dependency + Clone, { let declaration = >::declaration(context); let arguments = [ position.as_pointer(context)?.value.into(), value.as_pointer(context)?.value.into(), ]; context.build_call(declaration, &arguments, "transient_storage_store"); Ok(()) }