mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-08-01 12:51:30 +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};
|
use crate::{EntryKind, NodeData, Error, EntryLink};
|
||||||
|
|
||||||
@@ -39,6 +39,31 @@ impl Entry {
|
|||||||
EntryKind::Node(_, right) => Ok(right)
|
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 {
|
impl From<NodeData> for Entry {
|
||||||
|
@@ -121,7 +121,7 @@ impl NodeData {
|
|||||||
Ok(())
|
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();
|
let mut data = Self::default();
|
||||||
data.consensus_branch_id = consensus_branch_id;
|
data.consensus_branch_id = consensus_branch_id;
|
||||||
r.read_exact(&mut data.subtree_commitment)?;
|
r.read_exact(&mut data.subtree_commitment)?;
|
||||||
|
Reference in New Issue
Block a user