pub struct Stump {
    pub leaves: u64,
    pub roots: Vec<NodeHash>,
}

Fields§

§leaves: u64§roots: Vec<NodeHash>

Implementations§

source§

impl Stump

source

pub fn new() -> Self

Creates an empty Stump

Example
use rustreexo::accumulator::stump::Stump;
let s = Stump::new();
source

pub fn verify( &self, proof: &Proof, del_hashes: &[NodeHash] ) -> Result<bool, String>

source

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);
source

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,
    ]
);
source

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());
source

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 Clone for Stump

source§

fn clone(&self) -> Stump

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Stump

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Stump

source§

fn default() -> Stump

Returns the “default value” for a type. Read more
source§

impl PartialEq<Stump> for Stump

source§

fn eq(&self, other: &Stump) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.