pub struct State { /* private fields */ }Expand description
The complete private state of one transaction.
Implementations§
Source§impl State
impl State
Sourcepub fn new(txid: impl Into<TxId>) -> Self
pub fn new(txid: impl Into<TxId>) -> Self
Birth with no chain claim or stored evidence, as in Tracker.State.init.
Sourcepub fn evidence(&self) -> Option<&CheckedProof>
pub fn evidence(&self) -> Option<&CheckedProof>
The retained record, including when the word has become stale.
Sourcepub fn suspect(&self) -> bool
pub fn suspect(&self) -> bool
Whether an unresolved fork requires a header recheck before acting.
Sourcepub fn last_hint_at(&self) -> Option<Timestamp>
pub fn last_hint_at(&self) -> Option<Timestamp>
Time of the most recently received hint, even for out of order clocks.
Sourcepub fn reask(&self) -> Option<&Reask>
pub fn reask(&self) -> Option<&Reask>
The next re-ask, which the host must execute and feed back.
Sourcepub fn to_compact(&self) -> Vec<u8> ⓘ
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.
Sourcepub fn from_compact(bytes: &[u8]) -> Result<Self, CompactError>
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.
Sourcepub fn step<H: Headers + ?Sized>(
&mut self,
params: &Params,
headers: &H,
input: Input,
) -> Result<(), CheckError>
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.