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§

source

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.

source

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.

source

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.

source

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§

source§

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

source§

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

source§

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

source§

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

source§

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

Implementors§