mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
blockstore: Use sled::Batch for insert().
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user