StorageMap

StorageMap是Substrate编程中常用的类型,所以列举出来,以便之后查询起来更加的方便;

Substrate项目中的路径:/substrate/srml/support/src/storage/mod.rs
最常用的方法如下,具体的实现请参考代码。

  • exists 根据Key查询数据在Map 中是否存在
  • insert 向Map中插入一条新的记录
  • remove 从Map中移除一条记录
  • get 根据Key查询Map中的记录

/// A strongly-typed map in storage.
pub trait StorageMap {
/// The type that get/take return.
type Query;

/// Get the prefix key in storage.
fn prefix() -> &'static [u8];

/// Get the storage key used to fetch a value corresponding to a specific key.
fn key_for>(key: KeyArg) -> Vec;

/// Does the value (explicitly) exist in storage?
fn exists>(key: KeyArg) -> bool;

/// Load the value associated with the given key from the map.
fn get>(key: KeyArg) -> Self::Query;

/// Swap the values of two keys.
fn swap, KeyArg2: Borrow>(key1: KeyArg1, key2: KeyArg2);

/// Store a value to be associated with the given key from the map.
fn insert, ValArg: Borrow>(key: KeyArg, val: ValArg);

/// Store a value under this key into the provided storage instance; this can take any reference
/// type that derefs to `T` (and has `Encode` implemented).
fn insert_ref, ValArg: ?Sized + Encode>(key: KeyArg, val: &ValArg) where V: AsRef;

/// Remove the value under a key.
fn remove>(key: KeyArg);

/// Mutate the value under a key.
fn mutate, R, F: FnOnce(&mut Self::Query) -> R>(key: KeyArg, f: F) -> R;

/// Take the value under a key.
fn take>(key: KeyArg) -> Self::Query;

}

你可能感兴趣的:(StorageMap)