mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-07-30 03:51:22 +00:00
reading for Entry
This commit is contained in:
27
src/entry.rs
27
src/entry.rs
@@ -1,4 +1,4 @@
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt, ByteOrder};
|
||||
use byteorder::{LittleEndian, ReadBytesExt};
|
||||
|
||||
use crate::{EntryKind, NodeData, Error, EntryLink};
|
||||
|
||||
@@ -39,6 +39,31 @@ impl Entry {
|
||||
EntryKind::Node(_, right) => Ok(right)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read<R: std::io::Read>(&self, consensus_branch_id: u32, r: &mut R) -> std::io::Result<Self> {
|
||||
let kind = {
|
||||
match r.read_u8()? {
|
||||
0 => {
|
||||
let left = r.read_u32::<LittleEndian>()?;
|
||||
let right = r.read_u32::<LittleEndian>()?;
|
||||
EntryKind::Node(EntryLink::Stored(left), EntryLink::Stored(right))
|
||||
},
|
||||
1 => {
|
||||
EntryKind::Leaf
|
||||
},
|
||||
_ => {
|
||||
return Err(std::io::Error::from(std::io::ErrorKind::InvalidData))
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
let data = NodeData::read(consensus_branch_id, r)?;
|
||||
|
||||
Ok(Entry {
|
||||
kind,
|
||||
data,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<NodeData> for Entry {
|
||||
|
@@ -121,7 +121,7 @@ impl NodeData {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn read<R: std::io::Read>(&self, consensus_branch_id: u32, r: &mut R) -> std::io::Result<Self> {
|
||||
pub fn read<R: std::io::Read>(consensus_branch_id: u32, r: &mut R) -> std::io::Result<Self> {
|
||||
let mut data = Self::default();
|
||||
data.consensus_branch_id = consensus_branch_id;
|
||||
r.read_exact(&mut data.subtree_commitment)?;
|
||||
|
Reference in New Issue
Block a user