mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 09:21:05 +00:00
Light client friendly events (#2491)
* Sketch of indexed events. * Get EventIndex by holding another variable. * Add some docs. * Use DoubleMap to store reverse topic index * Implement StorageDoubleMap::append * Use append for EventTopics. * Refactor. * Avoid `mutate` * Docs. * Add topics to EventRecord * Update tests. * Rebuild. * Bump version. * Event topics test. * Mix in BlockNumber to distinguish updates * Fix srml-system test. * Post merge fixes. * Comments/TODO.
This commit is contained in:
committed by
Gavin Wood
parent
d974189e3c
commit
21773b3a07
@@ -401,6 +401,20 @@ pub trait StorageDoubleMap<K1: Codec, K2: Codec, V: Codec> {
|
||||
KArg1: Borrow<K1>,
|
||||
KArg2: Borrow<K2>,
|
||||
F: FnOnce(&mut Self::Query) -> R;
|
||||
|
||||
/// Append the given items to the value under the key specified.
|
||||
///
|
||||
/// `V` is required to implement `codec::EncodeAppend<Item=I>`.
|
||||
fn append<KArg1, KArg2, I>(
|
||||
k1: KArg1,
|
||||
k2: KArg2,
|
||||
items: &[I],
|
||||
) -> Result<(), &'static str>
|
||||
where
|
||||
KArg1: Borrow<K1>,
|
||||
KArg2: Borrow<K2>,
|
||||
I: codec::Encode,
|
||||
V: EncodeAppend<Item=I>;
|
||||
}
|
||||
|
||||
impl<K1: Codec, K2: Codec, V: Codec, U> StorageDoubleMap<K1, K2, V> for U
|
||||
@@ -453,6 +467,20 @@ where
|
||||
{
|
||||
U::mutate(k1.borrow(), k2.borrow(), f, &RuntimeStorage)
|
||||
}
|
||||
|
||||
fn append<KArg1, KArg2, I>(
|
||||
k1: KArg1,
|
||||
k2: KArg2,
|
||||
items: &[I],
|
||||
) -> Result<(), &'static str>
|
||||
where
|
||||
KArg1: Borrow<K1>,
|
||||
KArg2: Borrow<K2>,
|
||||
I: codec::Encode,
|
||||
V: EncodeAppend<Item=I>,
|
||||
{
|
||||
U::append(k1.borrow(), k2.borrow(), items, &RuntimeStorage)
|
||||
}
|
||||
}
|
||||
|
||||
/// child storage NOTE could replace unhashed by having only one kind of storage (root being null storage
|
||||
|
||||
@@ -150,4 +150,24 @@ pub trait StorageDoubleMap<K1: codec::Codec, K2: codec::Codec, V: codec::Codec>
|
||||
|
||||
/// Mutate the value under a key.
|
||||
fn mutate<R, F: FnOnce(&mut Self::Query) -> R, S: UnhashedStorage>(k1: &K1, k2: &K2, f: F, storage: &S) -> R;
|
||||
|
||||
/// Append the given items to the value under the key specified.
|
||||
fn append<I, S: UnhashedStorage>(
|
||||
k1: &K1,
|
||||
k2: &K2,
|
||||
items: &[I],
|
||||
storage: &S,
|
||||
) -> Result<(), &'static str>
|
||||
where
|
||||
I: codec::Encode,
|
||||
V: codec::EncodeAppend<Item=I>,
|
||||
{
|
||||
let key = Self::key_for(k1, k2);
|
||||
let new_val = <V as codec::EncodeAppend>::append(
|
||||
storage.get_raw(&key).unwrap_or_default(),
|
||||
items,
|
||||
).ok_or_else(|| "Could not append given item")?;
|
||||
storage.put_raw(&key, &new_val);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user