Fill out code for the rest of the Substrate events

This commit is contained in:
Luke Parker
2023-04-16 03:16:53 -04:00
parent 36cdf6d4bf
commit 2604746586
3 changed files with 215 additions and 42 deletions

View File

@@ -11,6 +11,20 @@ impl<D: Db> MainDb<D> {
D::key(b"MAIN", dst, key)
}
fn substrate_block_key() -> Vec<u8> {
Self::main_key(b"substrate_block", [])
}
pub fn set_last_substrate_block(&mut self, block: u64) {
let mut txn = self.0.txn();
txn.put(Self::substrate_block_key(), block.to_le_bytes());
txn.commit();
}
pub fn last_substrate_block(&self) -> u64 {
u64::from_le_bytes(
self.0.get(Self::substrate_block_key()).unwrap_or(vec![0; 8]).try_into().unwrap(),
)
}
fn event_key(id: &[u8], index: u32) -> Vec<u8> {
Self::main_key(b"event", [id, index.to_le_bytes().as_ref()].concat())
}