blockstore: Use sled::Batch for insert().

This commit is contained in:
parazyd
2022-04-03 15:55:06 +02:00
parent 4a4b40d7be
commit 1439d921da

View File

@@ -1,3 +1,5 @@
use sled::Batch;
use crate::{
util::serial::{deserialize, serialize, SerialDecodable, SerialEncodable},
Result,
@@ -32,12 +34,15 @@ impl BlockStore {
/// The blocks are hashed with blake3 and this blockhash is used as
// the key, where value is the serialized block itself.
pub fn insert(&self, blocks: Vec<Block>) -> Result<()> {
let mut batch = Batch::default();
for i in &blocks {
let serialized = serialize(i);
let blockhash = blake3::hash(&serialized);
self.0.insert(blockhash.as_bytes(), serialized)?;
batch.insert(blockhash.as_bytes(), serialized);
}
self.0.apply_batch(batch)?;
Ok(())
}