91cb14ac41
* Remove redundant method * Pull out a method out of a struct * More precise db access abstractions * Move fake trait method out of it * cargo fmt * Fix compilation error after refactoring * Move another fake method out the Store trait * Get rid of superfluous method * Fix refactoring bug * Rename: SimpleStoreItem -> StoreItem * Get rid of the confusing DiskStore type alias * Get rid of SimpleDiskStore type alias * Correction: A method took both self and a ref to Self
36 lines
1.0 KiB
Rust
36 lines
1.0 KiB
Rust
use crate::*;
|
|
use ssz::{Decode, Encode};
|
|
|
|
pub mod beacon_state;
|
|
pub mod partial_beacon_state;
|
|
|
|
impl<T: EthSpec> StoreItem for SignedBeaconBlock<T> {
|
|
fn db_column() -> DBColumn {
|
|
DBColumn::BeaconBlock
|
|
}
|
|
|
|
fn as_store_bytes(&self) -> Vec<u8> {
|
|
let timer = metrics::start_timer(&metrics::BEACON_BLOCK_WRITE_TIMES);
|
|
let bytes = self.as_ssz_bytes();
|
|
|
|
metrics::stop_timer(timer);
|
|
metrics::inc_counter(&metrics::BEACON_BLOCK_WRITE_COUNT);
|
|
metrics::inc_counter_by(&metrics::BEACON_BLOCK_WRITE_BYTES, bytes.len() as i64);
|
|
|
|
bytes
|
|
}
|
|
|
|
fn from_store_bytes(bytes: &[u8]) -> Result<Self, Error> {
|
|
let timer = metrics::start_timer(&metrics::BEACON_BLOCK_READ_TIMES);
|
|
|
|
let len = bytes.len();
|
|
let result = Self::from_ssz_bytes(bytes).map_err(Into::into);
|
|
|
|
metrics::stop_timer(timer);
|
|
metrics::inc_counter(&metrics::BEACON_BLOCK_READ_COUNT);
|
|
metrics::inc_counter_by(&metrics::BEACON_BLOCK_READ_BYTES, len as i64);
|
|
|
|
result
|
|
}
|
|
}
|