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>;

    // 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 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_data_for_pages<'a>(
        program_id: ProgramId,
        memory_infix: MemoryInfix,
        pages: impl Iterator<Item = &'a GearPage>
    ) -> 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 remove_program_pages(program_id: ProgramId, memory_infix: MemoryInfix) { ... }
}
Expand description

Trait to work with program data in a storage.

Required Associated Types§

source

type InternalError: Error

source

type Error: From<Self::InternalError> + Debug

source

type BlockNumber: Copy + Saturating

source

type AccountId: Eq + PartialEq

source

type ProgramMap: MapStorage<Key = ProgramId, Value = Program<Self::BlockNumber>>

source

type MemoryPageMap: TripleMapStorage<Key1 = ProgramId, Key2 = MemoryInfix, Key3 = GearPage, Value = PageBuf>

Required Methods§

source

fn pages_final_prefix() -> [u8; 32]

Final full prefix that prefixes all keys of memory pages.

Provided Methods§

source

fn reset()

Attempt to remove all items from all the associated maps.

source

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.

source

fn get_program(program_id: ProgramId) -> Option<Program<Self::BlockNumber>>

Load the program associated with the given key program_id from the map.

source

fn program_exists(program_id: ProgramId) -> bool

Does the program (explicitly) exist in storage?

source

fn update_active_program<F, ReturnType>( program_id: ProgramId, update_action: F ) -> Result<ReturnType, Self::Error>
where F: FnOnce(&mut ActiveProgram<Self::BlockNumber>) -> ReturnType,

Update the active program under the given key program_id.

source

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,

Update the program under the given key program_id only if the stored program is an active one.

source

fn get_program_data_for_pages<'a>( program_id: ProgramId, memory_infix: MemoryInfix, pages: impl Iterator<Item = &'a GearPage> ) -> Result<MemoryMap, Self::Error>

Return program data for each page from pages.

source

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.

source

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.

source

fn remove_program_pages(program_id: ProgramId, memory_infix: MemoryInfix)

Remove all memory page buffers under the given keys program_id and memory_infix.

Object Safety§

This trait is not object safe.

Implementors§