use snarkvm_utilities::bytes::{FromBytes, ToBytes};
use std::io::{Read, Result as IoResult, Write};
pub const COL_META: u32 = 0; pub const COL_BLOCK_HEADER: u32 = 1; pub const COL_BLOCK_TRANSACTIONS: u32 = 2; pub const COL_BLOCK_LOCATOR: u32 = 3; pub const COL_TRANSACTION_LOCATION: u32 = 4; pub const COL_COMMITMENT: u32 = 5; pub const COL_SERIAL_NUMBER: u32 = 6; pub const COL_MEMO: u32 = 7; pub const COL_DIGEST: u32 = 8; pub const COL_RECORDS: u32 = 9; pub const COL_CHILD_HASHES: u32 = 10; pub const NUM_COLS: u32 = 11;
pub const KEY_BEST_BLOCK_NUMBER: &str = "BEST_BLOCK_NUMBER";
pub const KEY_MEMORY_POOL: &str = "MEMORY_POOL";
pub const KEY_PEER_BOOK: &str = "PEER_BOOK";
pub const KEY_CURR_CM_INDEX: &str = "CURRENT_CM_INDEX";
pub const KEY_CURR_SN_INDEX: &str = "CURRENT_SN_INDEX";
pub const KEY_CURR_MEMO_INDEX: &str = "CURRENT_MEMO_INDEX";
pub const KEY_CURR_DIGEST: &str = "CURRENT_DIGEST";
#[derive(Debug, PartialEq, Clone)]
pub struct TransactionLocation {
pub index: u32,
pub block_hash: [u8; 32],
}
impl ToBytes for TransactionLocation {
#[inline]
fn write<W: Write>(&self, mut writer: W) -> IoResult<()> {
self.index.write(&mut writer)?;
self.block_hash.write(&mut writer)
}
}
impl FromBytes for TransactionLocation {
#[inline]
fn read<R: Read>(mut reader: R) -> IoResult<Self> {
let index: u32 = FromBytes::read(&mut reader)?;
let block_hash: [u8; 32] = FromBytes::read(&mut reader)?;
Ok(Self { index, block_hash })
}
}
pub fn bytes_to_u32(bytes: Vec<u8>) -> u32 {
let mut num_bytes = [0u8; 4];
num_bytes.copy_from_slice(&bytes);
u32::from_le_bytes(num_bytes)
}