Skip to main content

State

Struct State 

Source
pub struct State { /* private fields */ }
Expand description

The complete private state of one transaction.

Implementations§

Source§

impl State

Source

pub fn new(txid: impl Into<TxId>) -> Self

Birth with no chain claim or stored evidence, as in Tracker.State.init.

Source

pub fn txid(&self) -> &str

The host’s tracked transaction.

Source

pub fn word(&self) -> &Word

The current word. It is immutable outside the transition function.

Source

pub fn evidence(&self) -> Option<&CheckedProof>

The retained record, including when the word has become stale.

Source

pub fn suspect(&self) -> bool

Whether an unresolved fork requires a header recheck before acting.

Source

pub fn hints(&self) -> &[Hint]

Observations in newest received order, matching the Lean list.

Source

pub fn last_hint_at(&self) -> Option<Timestamp>

Time of the most recently received hint, even for out of order clocks.

Source

pub fn reask(&self) -> Option<&Reask>

The next re-ask, which the host must execute and feed back.

Source

pub fn to_compact(&self) -> Vec<u8> ⓘ

The compact byte form (bsv-stack-lean #92): a version byte, the txid, the word, the evidence, the suspect mark, the hints, the last hint time and the re-ask. The layout is in the source of src/compact.rs; the version byte changes when the layout does, so a later release tells an earlier layout from its own rather than misreading it.

Source

pub fn from_compact(bytes: &[u8]) -> Result<Self, CompactError>

Restore a state from State::to_compact’s bytes.

The rule: a restored mined word is still suspect until its proof is re-checked against the host’s headers. CheckedProof has no deserializer, because bytes are not a check: the chain may have moved while the state was stored. So the stored proof comes back as the record (its path reduces for this txid to the stored root, which equals the stored header’s root), the word comes back mined on that record, and the state is marked suspect with Reask::Recheck due when no other re-ask was pending. A Tracker holding it rechecks it on the next tip, as it does any suspect word; a host holding the state alone feeds Evidence::Recheck before it serves the inclusion.

Every other field returns exactly: a state whose word is not mined, or that was already suspect with a re-ask pending, restores equal to the state that wrote the bytes, and a restored state writes bytes that restore equal to it.

§Errors

CompactError::UnknownVersion for a version this crate does not read, CompactError::Truncated, CompactError::TrailingBytes and CompactError::Malformed for bytes the encoder never writes (a mined word with no stored proof among them), and CompactError::Evidence for a stored proof that does not hold together.

Source

pub fn step<H: Headers + ?Sized>( &mut self, params: &Params, headers: &H, input: Input, ) -> Result<(), CheckError>

Execute one Lean transition. Proof and header failures retain the word and record the re-ask before returning an error to the host.

§Errors

The CheckError of a proof, competitor, chain event or recheck whose check fails; the word is kept and the re-ask recorded.

Trait Implementations§

Source§

impl Clone for State

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for State

Source§

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

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

impl Eq for State

Source§

impl PartialEq for State

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for State

Auto Trait Implementations§

§

impl Freeze for State

§

impl RefUnwindSafe for State

§

impl Send for State

§

impl Sync for State

§

impl Unpin for State

§

impl UnsafeUnpin for State

§

impl UnwindSafe for State

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V