mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-07 22:04:03 -05:00
blockchain: use sled-overlay record parsing functions
This commit is contained in:
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -6492,9 +6492,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "sled-overlay"
|
||||
version = "0.1.5"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad42f44feda8a0f1697d6608bd34999ec40a3894915ca826bb3df66ac9247e75"
|
||||
checksum = "4c33dea88a6fcef15045db58735976a75488268751fa4574ca6d95a3f612a0da"
|
||||
dependencies = [
|
||||
"darkfi-serial",
|
||||
"sled",
|
||||
|
||||
@@ -122,7 +122,7 @@ wasmer-compiler-singlepass = {version = "4.4.0", optional = true}
|
||||
wasmer-middlewares = {version = "4.4.0", optional = true}
|
||||
|
||||
# Blockchain store
|
||||
sled-overlay = {version = "0.1.5", optional = true}
|
||||
sled-overlay = {version = "0.1.6", optional = true}
|
||||
|
||||
# Miner
|
||||
randomx = {git = "https://github.com/darkrenaissance/RandomX", optional = true}
|
||||
|
||||
@@ -22,7 +22,7 @@ bs58 = "0.5.1"
|
||||
log = "0.4.22"
|
||||
num-bigint = "0.4.6"
|
||||
rand = "0.8.5"
|
||||
sled-overlay = "0.1.5"
|
||||
sled-overlay = "0.1.6"
|
||||
toml = "0.8.19"
|
||||
|
||||
# JSON-RPC
|
||||
|
||||
@@ -24,7 +24,7 @@ darkfi-serial = {version = "0.4.2", features = ["async"]}
|
||||
libc = "0.2.159"
|
||||
|
||||
# Event Graph DB
|
||||
sled-overlay = "0.1.5"
|
||||
sled-overlay = "0.1.6"
|
||||
|
||||
# TLS
|
||||
async-trait = "0.1.83"
|
||||
|
||||
@@ -42,7 +42,7 @@ futures = "0.3.31"
|
||||
async-recursion = "1.1.1"
|
||||
colored = "2.1.0"
|
||||
#rustpython-vm = "0.3.1"
|
||||
sled-overlay = "0.1.5"
|
||||
sled-overlay = "0.1.6"
|
||||
url = "2.5.2"
|
||||
semver = "1.0.23"
|
||||
chrono = "0.4.38"
|
||||
|
||||
@@ -28,7 +28,7 @@ darkfi-serial = "0.4.2"
|
||||
blake3 = "1.5.4"
|
||||
|
||||
# Event Graph DB
|
||||
sled-overlay = "0.1.5"
|
||||
sled-overlay = "0.1.6"
|
||||
|
||||
# Misc
|
||||
async-trait = "0.1.83"
|
||||
|
||||
@@ -27,7 +27,7 @@ darkfi = { path = "../../../", features = [
|
||||
darkfi-serial = "0.4.2"
|
||||
|
||||
# Event Graph DB
|
||||
sled-overlay = "0.1.5"
|
||||
sled-overlay = "0.1.6"
|
||||
|
||||
# Crypto
|
||||
blake3 = "1.5.4"
|
||||
|
||||
@@ -26,7 +26,7 @@ darkfi = {path = "../../", features = ["event-graph"]}
|
||||
darkfi-serial = {version = "0.4.2", features = ["async"]}
|
||||
|
||||
# Event Graph DB
|
||||
sled-overlay = "0.1.5"
|
||||
sled-overlay = "0.1.6"
|
||||
|
||||
# Crypto
|
||||
blake3 = "1.5.4"
|
||||
|
||||
@@ -18,7 +18,7 @@ drk = {path = "../../../bin/drk"}
|
||||
|
||||
# Misc
|
||||
log = "0.4.22"
|
||||
sled-overlay = "0.1.5"
|
||||
sled-overlay = "0.1.6"
|
||||
|
||||
# JSON-RPC
|
||||
async-trait = "0.1.83"
|
||||
|
||||
@@ -18,13 +18,13 @@ darkfi = {path = "../../../", features = ["bs58", "validator"]}
|
||||
darkfi_money_contract = {path = "../../../src/contract/money", features = ["no-entrypoint", "client"]}
|
||||
darkfi-contract-test-harness = {path = "../../../src/contract/test-harness"}
|
||||
darkfi-sdk = {path = "../../../src/sdk"}
|
||||
darkfi-serial = {path = "../../../src/serial"}
|
||||
darkfi-serial = "0.4.2"
|
||||
|
||||
# Misc
|
||||
async-std = {version = "1.13.0", features = ["attributes"]}
|
||||
bs58 = "0.5.1"
|
||||
clap = {version = "4.4.11", features = ["derive"]}
|
||||
sled-overlay = "0.1.5"
|
||||
sled-overlay = "0.1.6"
|
||||
|
||||
[patch.crates-io]
|
||||
halo2_proofs = {git="https://github.com/parazyd/halo2", branch="v4"}
|
||||
|
||||
@@ -28,11 +28,14 @@ use darkfi_sdk::{
|
||||
use darkfi_serial::async_trait;
|
||||
use darkfi_serial::{deserialize, serialize, SerialDecodable, SerialEncodable};
|
||||
use num_bigint::BigUint;
|
||||
use sled_overlay::{sled, SledDbOverlayStateDiff};
|
||||
use sled_overlay::{
|
||||
serial::{parse_record, parse_u32_key_record},
|
||||
sled, SledDbOverlayStateDiff,
|
||||
};
|
||||
|
||||
use crate::{tx::Transaction, util::time::Timestamp, Error, Result};
|
||||
|
||||
use super::{parse_record, parse_u32_key_record, Header, HeaderHash, SledDbOverlayPtr};
|
||||
use super::{Header, HeaderHash, SledDbOverlayPtr};
|
||||
|
||||
/// This struct represents a tuple of the form (`header`, `txs`, `signature`).
|
||||
///
|
||||
|
||||
@@ -21,7 +21,7 @@ use std::io::Cursor;
|
||||
use darkfi_sdk::crypto::ContractId;
|
||||
use darkfi_serial::{deserialize, serialize};
|
||||
use log::{debug, error};
|
||||
use sled_overlay::sled;
|
||||
use sled_overlay::{serial::parse_record, sled};
|
||||
|
||||
use crate::{
|
||||
zk::{empty_witnesses, VerifyingKey, ZkCircuit},
|
||||
@@ -29,7 +29,7 @@ use crate::{
|
||||
Error, Result,
|
||||
};
|
||||
|
||||
use super::{parse_record, SledDbOverlayPtr};
|
||||
use super::SledDbOverlayPtr;
|
||||
|
||||
pub const SLED_CONTRACTS_TREE: &[u8] = b"_contracts";
|
||||
pub const SLED_BINCODE_TREE: &[u8] = b"_wasm_bincode";
|
||||
|
||||
@@ -27,11 +27,14 @@ use darkfi_sdk::{
|
||||
#[cfg(feature = "async-serial")]
|
||||
use darkfi_serial::async_trait;
|
||||
use darkfi_serial::{deserialize, serialize, Encodable, SerialDecodable, SerialEncodable};
|
||||
use sled_overlay::sled;
|
||||
use sled_overlay::{
|
||||
serial::{parse_record, parse_u32_key_record},
|
||||
sled,
|
||||
};
|
||||
|
||||
use crate::{util::time::Timestamp, Error, Result};
|
||||
|
||||
use super::{parse_record, parse_u32_key_record, SledDbOverlayPtr};
|
||||
use super::SledDbOverlayPtr;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, SerialEncodable, SerialDecodable)]
|
||||
// We have to introduce a type rather than using an alias so we can restrict API access
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use darkfi_sdk::tx::TransactionHash;
|
||||
use darkfi_serial::{deserialize, Decodable};
|
||||
use log::debug;
|
||||
use sled_overlay::{sled, sled::Transactional};
|
||||
|
||||
@@ -585,31 +584,3 @@ impl BlockchainOverlay {
|
||||
Ok(Arc::new(Mutex::new(Self { overlay, headers, blocks, transactions, contracts })))
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse a sled record with a u32 key in the form of a tuple (`key`, `value`).
|
||||
pub fn parse_u32_key_record<T: Decodable>(record: (sled::IVec, sled::IVec)) -> Result<(u32, T)> {
|
||||
let key_bytes: [u8; 4] = record.0.as_ref().try_into().unwrap();
|
||||
let key = u32::from_be_bytes(key_bytes);
|
||||
let value = deserialize(&record.1)?;
|
||||
|
||||
Ok((key, value))
|
||||
}
|
||||
|
||||
/// Parse a sled record with a u64 key in the form of a tuple (`key`, `value`).
|
||||
pub fn parse_u64_key_record<T: Decodable>(record: (sled::IVec, sled::IVec)) -> Result<(u64, T)> {
|
||||
let key_bytes: [u8; 8] = record.0.as_ref().try_into().unwrap();
|
||||
let key = u64::from_be_bytes(key_bytes);
|
||||
let value = deserialize(&record.1)?;
|
||||
|
||||
Ok((key, value))
|
||||
}
|
||||
|
||||
/// Parse a sled record in the form of a tuple (`key`, `value`).
|
||||
pub fn parse_record<T1: Decodable, T2: Decodable>(
|
||||
record: (sled::IVec, sled::IVec),
|
||||
) -> Result<(T1, T2)> {
|
||||
let key = deserialize(&record.0)?;
|
||||
let value = deserialize(&record.1)?;
|
||||
|
||||
Ok((key, value))
|
||||
}
|
||||
|
||||
@@ -20,11 +20,14 @@ use std::collections::HashMap;
|
||||
|
||||
use darkfi_sdk::tx::TransactionHash;
|
||||
use darkfi_serial::{deserialize, serialize};
|
||||
use sled_overlay::sled;
|
||||
use sled_overlay::{
|
||||
serial::{parse_record, parse_u64_key_record},
|
||||
sled,
|
||||
};
|
||||
|
||||
use crate::{tx::Transaction, Error, Result};
|
||||
|
||||
use super::{parse_record, parse_u64_key_record, SledDbOverlayPtr};
|
||||
use super::SledDbOverlayPtr;
|
||||
|
||||
pub const SLED_TX_TREE: &[u8] = b"_transactions";
|
||||
pub const SLED_TX_LOCATION_TREE: &[u8] = b"_transaction_location";
|
||||
|
||||
@@ -19,7 +19,7 @@ blake3 = "1.5.4"
|
||||
log = "0.4.22"
|
||||
rand = "0.8.5"
|
||||
simplelog = "0.12.2"
|
||||
sled-overlay = "0.1.5"
|
||||
sled-overlay = "0.1.6"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
Reference in New Issue
Block a user