Struct rustreexo::accumulator::stump::Stump
source · pub struct Stump {
pub leaves: u64,
pub roots: Vec<NodeHash>,
}
Fields§
§leaves: u64
§roots: Vec<NodeHash>
Implementations§
source§impl Stump
impl Stump
pub fn verify( &self, proof: &Proof, del_hashes: &[NodeHash] ) -> Result<bool, String>
sourcepub fn modify(
&self,
utxos: &[NodeHash],
del_hashes: &[NodeHash],
proof: &Proof
) -> Result<(Stump, UpdateData), String>
pub fn modify( &self, utxos: &[NodeHash], del_hashes: &[NodeHash], proof: &Proof ) -> Result<(Stump, UpdateData), String>
Modify is the external API to change the accumulator state. Since order matters, you can only modify, providing a list of utxos to be added, and txos to be removed, along with it’s proof. Either may be empty.
Example
use std::str::FromStr;
use rustreexo::accumulator::node_hash::NodeHash;
use rustreexo::accumulator::proof::Proof;
use rustreexo::accumulator::stump::Stump;
let s = Stump::new();
let utxos = vec![NodeHash::from_str(
"b151a956139bb821d4effa34ea95c17560e0135d1e4661fc23cedc3af49dac42",
)
.unwrap()];
let stxos = vec![];
let s = s.modify(&utxos, &stxos, &Proof::default());
assert!(s.is_ok());
assert_eq!(s.unwrap().0.roots, utxos);
sourcepub fn serialize<Dst: Write>(&self, writer: &mut Dst) -> Result<usize>
pub fn serialize<Dst: Write>(&self, writer: &mut Dst) -> Result<usize>
Serialize the Stump into a byte array
Example
use rustreexo::accumulator::node_hash::NodeHash;
use rustreexo::accumulator::proof::Proof;
use rustreexo::accumulator::stump::Stump;
let hashes = [0, 1, 2, 3, 4, 5, 6, 7]
.iter()
.map(|&el| NodeHash::from([el; 32]))
.collect::<Vec<_>>();
let (stump, _) = Stump::new()
.modify(&hashes, &[], &Proof::default())
.unwrap();
let mut writer = Vec::new();
stump.serialize(&mut writer).unwrap();
assert_eq!(
writer,
vec![
8, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 150, 124, 244, 241, 98, 69, 217, 222,
235, 97, 61, 137, 135, 76, 197, 134, 232, 173, 253, 8, 28, 17, 124, 123, 16, 4, 66, 30,
63, 113, 246, 74,
]
);
sourcepub fn deserialize<Source: Read>(data: Source) -> Result<Self, String>
pub fn deserialize<Source: Read>(data: Source) -> Result<Self, String>
Deserialize the Stump from a Reader
Example
use rustreexo::accumulator::node_hash::NodeHash;
use rustreexo::accumulator::proof::Proof;
use rustreexo::accumulator::stump::Stump;
let buffer = vec![
8, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 150, 124, 244, 241, 98, 69, 217, 222, 235,
97, 61, 137, 135, 76, 197, 134, 232, 173, 253, 8, 28, 17, 124, 123, 16, 4, 66, 30, 63, 113,
246, 74,
];
let mut buffer = std::io::Cursor::new(buffer);
let hashes = [0, 1, 2, 3, 4, 5, 6, 7]
.iter()
.map(|&el| NodeHash::from([el; 32]))
.collect::<Vec<_>>();
let (stump, _) = Stump::new()
.modify(&hashes, &[], &Proof::default())
.unwrap();
assert_eq!(stump, Stump::deserialize(buffer).unwrap());
sourcepub fn undo(&mut self, old_state: Stump)
pub fn undo(&mut self, old_state: Stump)
Rewinds old tree state, this should be used in case of reorgs.
Takes the ownership over old_state
.
Example
use rustreexo::accumulator::proof::Proof;
use rustreexo::accumulator::stump::Stump;
let s_old = Stump::new();
let mut s_new = Stump::new();
let s_old = s_old.modify(&vec![], &vec![], &Proof::default()).unwrap().0;
s_new = s_old.clone();
s_new = s_new.modify(&vec![], &vec![], &Proof::default()).unwrap().0;
// A reorg happened
s_new.undo(s_old);
Trait Implementations§
source§impl PartialEq<Stump> for Stump
impl PartialEq<Stump> for Stump
impl StructuralPartialEq for Stump
Auto Trait Implementations§
impl RefUnwindSafe for Stump
impl Send for Stump
impl Sync for Stump
impl Unpin for Stump
impl UnwindSafe for Stump
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more