mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 17:01:09 +00:00
implement aux-storing in client-db
This commit is contained in:
@@ -43,6 +43,7 @@ pub(crate) mod columns {
|
||||
pub const HEADER: Option<u32> = Some(2);
|
||||
pub const CACHE: Option<u32> = Some(3);
|
||||
pub const CHT: Option<u32> = Some(4);
|
||||
pub const AUX: Option<u32> = Some(5);
|
||||
}
|
||||
|
||||
/// Light blockchain storage. Stores most recent headers + CHTs for older headers.
|
||||
@@ -238,6 +239,7 @@ impl<Block> LightBlockchainStorage<Block> for LightStorage<Block>
|
||||
header: Block::Header,
|
||||
authorities: Option<Vec<AuthorityId>>,
|
||||
leaf_state: NewBlockState,
|
||||
aux_ops: Vec<(Vec<u8>, Option<Vec<u8>>)>,
|
||||
) -> ClientResult<()> {
|
||||
let mut transaction = DBTransaction::new();
|
||||
|
||||
@@ -253,6 +255,13 @@ impl<Block> LightBlockchainStorage<Block> for LightStorage<Block>
|
||||
::utils::number_and_hash_to_lookup_key(number, hash)
|
||||
};
|
||||
|
||||
for (key, maybe_val) in aux_ops {
|
||||
match maybe_val {
|
||||
Some(val) => transaction.put_vec(columns::AUX, &key, val),
|
||||
None => transaction.delete(columns::AUX, &key),
|
||||
}
|
||||
}
|
||||
|
||||
if leaf_state.is_best() {
|
||||
// handle reorg.
|
||||
{
|
||||
@@ -427,7 +436,7 @@ pub(crate) mod tests {
|
||||
) -> Hash {
|
||||
let header = prepare_header(parent, number, extrinsics_root);
|
||||
let hash = header.hash();
|
||||
db.import_header(header, authorities, NewBlockState::Best).unwrap();
|
||||
db.import_header(header, authorities, NewBlockState::Best, Vec::new()).unwrap();
|
||||
hash
|
||||
}
|
||||
|
||||
@@ -439,7 +448,7 @@ pub(crate) mod tests {
|
||||
) -> Hash {
|
||||
let header = prepare_header(parent, number, Default::default());
|
||||
let hash = header.hash();
|
||||
db.import_header(header, authorities, NewBlockState::Best).unwrap();
|
||||
db.import_header(header, authorities, NewBlockState::Best, Vec::new()).unwrap();
|
||||
hash
|
||||
}
|
||||
|
||||
@@ -451,7 +460,7 @@ pub(crate) mod tests {
|
||||
) -> Hash {
|
||||
let header = prepare_header(parent, number, Default::default());
|
||||
let hash = header.hash();
|
||||
db.import_header(header, authorities, NewBlockState::Final).unwrap();
|
||||
db.import_header(header, authorities, NewBlockState::Final, Vec::new()).unwrap();
|
||||
hash
|
||||
}
|
||||
|
||||
@@ -463,7 +472,7 @@ pub(crate) mod tests {
|
||||
) -> Hash {
|
||||
let header = prepare_header(parent, number, Default::default());
|
||||
let hash = header.hash();
|
||||
db.import_header(header, authorities, NewBlockState::Normal).unwrap();
|
||||
db.import_header(header, authorities, NewBlockState::Normal, Vec::new()).unwrap();
|
||||
hash
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user