feat(db): move reth-storage-api::ClientVersion and StoredBlockWithdrawals to reth-db-models (#10763)

This commit is contained in:
nk_ysg
2024-09-09 21:53:45 +08:00
committed by GitHub
parent b78e0f6069
commit c258c1547e
13 changed files with 25 additions and 25 deletions

View File

@ -1,7 +1,7 @@
//! Block related models and types.
use reth_codecs::{add_arbitrary_tests, Compact};
use reth_primitives::{Header, Withdrawals, B256};
use reth_primitives::{Header, B256};
use serde::{Deserialize, Serialize};
/// The storage representation of a block's ommers.
@ -15,15 +15,6 @@ pub struct StoredBlockOmmers {
pub ommers: Vec<Header>,
}
/// The storage representation of block withdrawals.
#[derive(Debug, Default, Eq, PartialEq, Clone, Serialize, Deserialize, Compact)]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(compact)]
pub struct StoredBlockWithdrawals {
/// The block withdrawals.
pub withdrawals: Withdrawals,
}
/// Hash of the block header.
pub type HeaderHash = B256;

View File

@ -1,47 +0,0 @@
//! Client version model.
use reth_codecs::{add_arbitrary_tests, Compact};
use serde::{Deserialize, Serialize};
/// Client version that accessed the database.
#[derive(Clone, Eq, PartialEq, Debug, Default, Serialize, Deserialize)]
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
#[add_arbitrary_tests(compact)]
pub struct ClientVersion {
/// Client version
pub version: String,
/// The git commit sha
pub git_sha: String,
/// Build timestamp
pub build_timestamp: String,
}
impl ClientVersion {
/// Returns `true` if no version fields are set.
pub fn is_empty(&self) -> bool {
self.version.is_empty() && self.git_sha.is_empty() && self.build_timestamp.is_empty()
}
}
impl Compact for ClientVersion {
fn to_compact<B>(&self, buf: &mut B) -> usize
where
B: bytes::BufMut + AsMut<[u8]>,
{
self.version.as_bytes().to_compact(buf);
self.git_sha.as_bytes().to_compact(buf);
self.build_timestamp.as_bytes().to_compact(buf)
}
fn from_compact(buf: &[u8], len: usize) -> (Self, &[u8]) {
let (version, buf) = Vec::<u8>::from_compact(buf, len);
let (git_sha, buf) = Vec::<u8>::from_compact(buf, len);
let (build_timestamp, buf) = Vec::<u8>::from_compact(buf, len);
let client_version = Self {
version: unsafe { String::from_utf8_unchecked(version) },
git_sha: unsafe { String::from_utf8_unchecked(git_sha) },
build_timestamp: unsafe { String::from_utf8_unchecked(build_timestamp) },
};
(client_version, buf)
}
}

View File

@ -13,15 +13,15 @@ use serde::{Deserialize, Serialize};
pub mod accounts;
pub mod blocks;
pub mod client_version;
pub mod integer_list;
pub mod sharded_key;
pub mod storage_sharded_key;
pub use accounts::*;
pub use blocks::*;
pub use client_version::ClientVersion;
pub use reth_db_models::{AccountBeforeTx, StoredBlockBodyIndices};
pub use reth_db_models::{
AccountBeforeTx, ClientVersion, StoredBlockBodyIndices, StoredBlockWithdrawals,
};
pub use sharded_key::ShardedKey;
/// Macro that implements [`Encode`] and [`Decode`] for uint types.