referrerpolicy=no-referrer-when-downgrade

Trait sp_runtime::offchain::DbExternalities

pub trait DbExternalities: Send {
    // Required methods
    fn local_storage_set(&mut self, kind: StorageKind, key: &[u8], value: &[u8]);
    fn local_storage_clear(&mut self, kind: StorageKind, key: &[u8]);
    fn local_storage_compare_and_set(
        &mut self,
        kind: StorageKind,
        key: &[u8],
        old_value: Option<&[u8]>,
        new_value: &[u8],
    ) -> bool;
    fn local_storage_get(
        &mut self,
        kind: StorageKind,
        key: &[u8],
    ) -> Option<Vec<u8>>;
}
Expand description

A externalities extension for accessing the Offchain DB.

Required Methods§

fn local_storage_set(&mut self, kind: StorageKind, key: &[u8], value: &[u8])

Sets a value in the local storage.

Note this storage is not part of the consensus, it’s only accessible by offchain worker tasks running on the same machine. It is persisted between runs.

fn local_storage_clear(&mut self, kind: StorageKind, key: &[u8])

Removes a value in the local storage.

Note this storage is not part of the consensus, it’s only accessible by offchain worker tasks running on the same machine. It is persisted between runs.

fn local_storage_compare_and_set( &mut self, kind: StorageKind, key: &[u8], old_value: Option<&[u8]>, new_value: &[u8], ) -> bool

Sets a value in the local storage if it matches current value.

Since multiple offchain workers may be running concurrently, to prevent data races use CAS to coordinate between them.

Returns true if the value has been set, false otherwise.

Note this storage is not part of the consensus, it’s only accessible by offchain worker tasks running on the same machine. It is persisted between runs.

fn local_storage_get( &mut self, kind: StorageKind, key: &[u8], ) -> Option<Vec<u8>>

Gets a value from the local storage.

If the value does not exist in the storage None will be returned. Note this storage is not part of the consensus, it’s only accessible by offchain worker tasks running on the same machine. It is persisted between runs.

Implementations on Foreign Types§

§

impl<T> DbExternalities for Box<T>
where T: DbExternalities + ?Sized,

§

fn local_storage_set(&mut self, kind: StorageKind, key: &[u8], value: &[u8])

§

fn local_storage_clear(&mut self, kind: StorageKind, key: &[u8])

§

fn local_storage_compare_and_set( &mut self, kind: StorageKind, key: &[u8], old_value: Option<&[u8]>, new_value: &[u8], ) -> bool

§

fn local_storage_get( &mut self, kind: StorageKind, key: &[u8], ) -> Option<Vec<u8>>

Implementors§

§

impl DbExternalities for TestOffchainExt

§

impl<Storage> DbExternalities for OffchainDb<Storage>
where Storage: OffchainStorage,

§

impl<T> DbExternalities for LimitedExternalities<T>
where T: DbExternalities,