Trait gear_common::program_storage::ProgramStorage
source · pub trait ProgramStorage {
type InternalError: Error;
type Error: From<Self::InternalError> + Debug;
type BlockNumber: Copy + Saturating;
type AccountId: Eq + PartialEq;
type ProgramMap: MapStorage<Key = ProgramId, Value = Program<Self::BlockNumber>>;
type MemoryPageMap: TripleMapStorage<Key1 = ProgramId, Key2 = MemoryInfix, Key3 = GearPage, Value = PageBuf>;
type AllocationsMap: MapStorage<Key = ProgramId, Value = IntervalsTree<WasmPage>>;
Show 16 methods
// Required method
fn pages_final_prefix() -> [u8; 32];
// Provided methods
fn reset() { ... }
fn add_program(
program_id: ProgramId,
program: ActiveProgram<Self::BlockNumber>,
) -> Result<(), Self::Error> { ... }
fn get_program(program_id: ProgramId) -> Option<Program<Self::BlockNumber>> { ... }
fn program_exists(program_id: ProgramId) -> bool { ... }
fn update_active_program<F, ReturnType>(
program_id: ProgramId,
update_action: F,
) -> Result<ReturnType, Self::Error>
where F: FnOnce(&mut ActiveProgram<Self::BlockNumber>) -> ReturnType { ... }
fn remove_data_for_pages(
program_id: ProgramId,
memory_infix: MemoryInfix,
pages: impl Iterator<Item = GearPage>,
) { ... }
fn allocations(program_id: ProgramId) -> Option<IntervalsTree<WasmPage>> { ... }
fn set_allocations(
program_id: ProgramId,
allocations: IntervalsTree<WasmPage>,
) { ... }
fn clear_allocations(program_id: ProgramId) { ... }
fn memory_infix(program_id: ProgramId) -> Option<MemoryInfix> { ... }
fn update_program_if_active<F, ReturnType>(
program_id: ProgramId,
update_action: F,
) -> Result<ReturnType, Self::Error>
where F: FnOnce(&mut Program<Self::BlockNumber>, Self::BlockNumber) -> ReturnType { ... }
fn get_program_pages_data(
program_id: ProgramId,
memory_infix: MemoryInfix,
) -> Result<MemoryMap, Self::Error> { ... }
fn set_program_page_data(
program_id: ProgramId,
memory_infix: MemoryInfix,
page: GearPage,
page_buf: PageBuf,
) { ... }
fn remove_program_page_data(
program_id: ProgramId,
memory_infix: MemoryInfix,
page_num: GearPage,
) { ... }
fn clear_program_memory(program_id: ProgramId, memory_infix: MemoryInfix) { ... }
}
Expand description
Trait to work with program data in a storage.
Required Associated Types§
type InternalError: Error
type Error: From<Self::InternalError> + Debug
type BlockNumber: Copy + Saturating
type AccountId: Eq + PartialEq
type ProgramMap: MapStorage<Key = ProgramId, Value = Program<Self::BlockNumber>>
type MemoryPageMap: TripleMapStorage<Key1 = ProgramId, Key2 = MemoryInfix, Key3 = GearPage, Value = PageBuf>
type AllocationsMap: MapStorage<Key = ProgramId, Value = IntervalsTree<WasmPage>>
Required Methods§
sourcefn pages_final_prefix() -> [u8; 32]
fn pages_final_prefix() -> [u8; 32]
Final full prefix that prefixes all keys of memory pages.
Provided Methods§
sourcefn add_program(
program_id: ProgramId,
program: ActiveProgram<Self::BlockNumber>,
) -> Result<(), Self::Error>
fn add_program( program_id: ProgramId, program: ActiveProgram<Self::BlockNumber>, ) -> Result<(), Self::Error>
Store a program to be associated with the given key program_id
from the map.
sourcefn get_program(program_id: ProgramId) -> Option<Program<Self::BlockNumber>>
fn get_program(program_id: ProgramId) -> Option<Program<Self::BlockNumber>>
Load the program associated with the given key program_id
from the map.
sourcefn program_exists(program_id: ProgramId) -> bool
fn program_exists(program_id: ProgramId) -> bool
Does the program (explicitly) exist in storage?
sourcefn update_active_program<F, ReturnType>(
program_id: ProgramId,
update_action: F,
) -> Result<ReturnType, Self::Error>
fn update_active_program<F, ReturnType>( program_id: ProgramId, update_action: F, ) -> Result<ReturnType, Self::Error>
Update the active program under the given key program_id
.
fn remove_data_for_pages( program_id: ProgramId, memory_infix: MemoryInfix, pages: impl Iterator<Item = GearPage>, )
fn allocations(program_id: ProgramId) -> Option<IntervalsTree<WasmPage>>
fn set_allocations(program_id: ProgramId, allocations: IntervalsTree<WasmPage>)
fn clear_allocations(program_id: ProgramId)
fn memory_infix(program_id: ProgramId) -> Option<MemoryInfix>
sourcefn update_program_if_active<F, ReturnType>(
program_id: ProgramId,
update_action: F,
) -> Result<ReturnType, Self::Error>
fn update_program_if_active<F, ReturnType>( program_id: ProgramId, update_action: F, ) -> Result<ReturnType, Self::Error>
Update the program under the given key program_id
only if the
stored program is an active one.
sourcefn get_program_pages_data(
program_id: ProgramId,
memory_infix: MemoryInfix,
) -> Result<MemoryMap, Self::Error>
fn get_program_pages_data( program_id: ProgramId, memory_infix: MemoryInfix, ) -> Result<MemoryMap, Self::Error>
Return data buffer for each memory page, which has data.
sourcefn set_program_page_data(
program_id: ProgramId,
memory_infix: MemoryInfix,
page: GearPage,
page_buf: PageBuf,
)
fn set_program_page_data( program_id: ProgramId, memory_infix: MemoryInfix, page: GearPage, page_buf: PageBuf, )
Store a memory page buffer to be associated with the given keys program_id
, memory_infix
and page
from the map.
sourcefn remove_program_page_data(
program_id: ProgramId,
memory_infix: MemoryInfix,
page_num: GearPage,
)
fn remove_program_page_data( program_id: ProgramId, memory_infix: MemoryInfix, page_num: GearPage, )
Remove a memory page buffer under the given keys program_id
, memory_infix
and page
.
sourcefn clear_program_memory(program_id: ProgramId, memory_infix: MemoryInfix)
fn clear_program_memory(program_id: ProgramId, memory_infix: MemoryInfix)
Remove all memory page buffers under the given keys program_id
and memory_infix
.