Struct snarkos_storage::LedgerState
source · [−]pub struct LedgerState<N: Network> { /* private fields */ }
Implementations
sourceimpl<N: Network> LedgerState<N>
impl<N: Network> LedgerState<N>
sourcepub fn open_writer<S: Storage, P: AsRef<Path>>(path: P) -> Result<Self>
pub fn open_writer<S: Storage, P: AsRef<Path>>(path: P) -> Result<Self>
Opens a new writable instance of LedgerState
from the given storage path.
For a read-only instance of LedgerState
, use LedgerState::open_reader
.
A writable instance of LedgerState
possesses full functionality, whereas
a read-only instance of LedgerState
may only call immutable methods.
sourcepub fn open_reader<S: Storage, P: AsRef<Path>>(path: P) -> Result<Arc<Self>>
pub fn open_reader<S: Storage, P: AsRef<Path>>(path: P) -> Result<Arc<Self>>
Opens a read-only instance of LedgerState
from the given storage path.
For a writable instance of LedgerState
, use LedgerState::open_writer
.
A writable instance of LedgerState
possesses full functionality, whereas
a read-only instance of LedgerState
may only call immutable methods.
sourcepub fn is_read_only(&self) -> bool
pub fn is_read_only(&self) -> bool
Returns true
if the ledger is in read-only mode.
sourcepub fn latest_block(&self) -> Block<N>
pub fn latest_block(&self) -> Block<N>
Returns the latest block.
sourcepub fn latest_block_height(&self) -> u32
pub fn latest_block_height(&self) -> u32
Returns the latest block height.
sourcepub fn latest_block_hash(&self) -> N::BlockHash
pub fn latest_block_hash(&self) -> N::BlockHash
Returns the latest block hash.
sourcepub fn latest_block_timestamp(&self) -> i64
pub fn latest_block_timestamp(&self) -> i64
Returns the latest block timestamp.
sourcepub fn latest_block_difficulty_target(&self) -> u64
pub fn latest_block_difficulty_target(&self) -> u64
Returns the latest block difficulty target.
sourcepub fn latest_cumulative_weight(&self) -> u128
pub fn latest_cumulative_weight(&self) -> u128
Returns the latest cumulative weight.
sourcepub fn latest_block_header(&self) -> BlockHeader<N>
pub fn latest_block_header(&self) -> BlockHeader<N>
Returns the latest block header.
sourcepub fn latest_block_transactions(&self) -> Transactions<N>
pub fn latest_block_transactions(&self) -> Transactions<N>
Returns the transactions from the latest block.
sourcepub fn latest_block_locators(&self) -> BlockLocators<N>
pub fn latest_block_locators(&self) -> BlockLocators<N>
Returns the latest block locators.
sourcepub fn latest_ledger_root(&self) -> N::LedgerRoot
pub fn latest_ledger_root(&self) -> N::LedgerRoot
Returns the latest ledger root.
sourcepub fn contains_ledger_root(&self, ledger_root: &N::LedgerRoot) -> Result<bool>
pub fn contains_ledger_root(&self, ledger_root: &N::LedgerRoot) -> Result<bool>
Returns true
if the given ledger root exists in storage.
sourcepub fn contains_block_height(&self, block_height: u32) -> Result<bool>
pub fn contains_block_height(&self, block_height: u32) -> Result<bool>
Returns true
if the given block height exists in storage.
sourcepub fn contains_block_hash(&self, block_hash: &N::BlockHash) -> Result<bool>
pub fn contains_block_hash(&self, block_hash: &N::BlockHash) -> Result<bool>
Returns true
if the given block hash exists in storage.
sourcepub fn contains_transaction(
&self,
transaction_id: &N::TransactionID
) -> Result<bool>
pub fn contains_transaction(
&self,
transaction_id: &N::TransactionID
) -> Result<bool>
Returns true
if the given transaction ID exists in storage.
sourcepub fn contains_serial_number(
&self,
serial_number: &N::SerialNumber
) -> Result<bool>
pub fn contains_serial_number(
&self,
serial_number: &N::SerialNumber
) -> Result<bool>
Returns true
if the given serial number exists in storage.
sourcepub fn contains_commitment(&self, commitment: &N::Commitment) -> Result<bool>
pub fn contains_commitment(&self, commitment: &N::Commitment) -> Result<bool>
Returns true
if the given commitment exists in storage.
sourcepub fn get_ciphertext(
&self,
commitment: &N::Commitment
) -> Result<N::RecordCiphertext>
pub fn get_ciphertext(
&self,
commitment: &N::Commitment
) -> Result<N::RecordCiphertext>
Returns the record ciphertext for a given commitment.
sourcepub fn get_transition(
&self,
transition_id: &N::TransitionID
) -> Result<Transition<N>>
pub fn get_transition(
&self,
transition_id: &N::TransitionID
) -> Result<Transition<N>>
Returns the transition for a given transition ID.
sourcepub fn get_transaction(
&self,
transaction_id: &N::TransactionID
) -> Result<Transaction<N>>
pub fn get_transaction(
&self,
transaction_id: &N::TransactionID
) -> Result<Transaction<N>>
Returns the transaction for a given transaction ID.
sourcepub fn get_transaction_metadata(
&self,
transaction_id: &N::TransactionID
) -> Result<Metadata<N>>
pub fn get_transaction_metadata(
&self,
transaction_id: &N::TransactionID
) -> Result<Metadata<N>>
Returns the transaction metadata for a given transaction ID.
sourcepub fn get_cumulative_weight(&self, block_height: u32) -> Result<u128>
pub fn get_cumulative_weight(&self, block_height: u32) -> Result<u128>
Returns the cumulative weight up to a given block height (inclusive) for the canonical chain.
sourcepub fn get_block_height(&self, block_hash: &N::BlockHash) -> Result<u32>
pub fn get_block_height(&self, block_hash: &N::BlockHash) -> Result<u32>
Returns the block height for the given block hash.
sourcepub fn get_block_hash(&self, block_height: u32) -> Result<N::BlockHash>
pub fn get_block_hash(&self, block_height: u32) -> Result<N::BlockHash>
Returns the block hash for the given block height.
sourcepub fn get_block_hashes(
&self,
start_block_height: u32,
end_block_height: u32
) -> Result<Vec<N::BlockHash>>
pub fn get_block_hashes(
&self,
start_block_height: u32,
end_block_height: u32
) -> Result<Vec<N::BlockHash>>
Returns the block hashes from the given start_block_height
to end_block_height
(inclusive).
sourcepub fn get_previous_block_hash(&self, block_height: u32) -> Result<N::BlockHash>
pub fn get_previous_block_hash(&self, block_height: u32) -> Result<N::BlockHash>
Returns the previous block hash for the given block height.
sourcepub fn get_block_header(&self, block_height: u32) -> Result<BlockHeader<N>>
pub fn get_block_header(&self, block_height: u32) -> Result<BlockHeader<N>>
Returns the block header for the given block height.
sourcepub fn get_block_headers(
&self,
start_block_height: u32,
end_block_height: u32
) -> Result<Vec<BlockHeader<N>>>
pub fn get_block_headers(
&self,
start_block_height: u32,
end_block_height: u32
) -> Result<Vec<BlockHeader<N>>>
Returns the block headers from the given start_block_height
to end_block_height
(inclusive).
sourcepub fn get_block_transactions(
&self,
block_height: u32
) -> Result<Transactions<N>>
pub fn get_block_transactions(
&self,
block_height: u32
) -> Result<Transactions<N>>
Returns the transactions from the block of the given block height.
sourcepub fn get_block(&self, block_height: u32) -> Result<Block<N>>
pub fn get_block(&self, block_height: u32) -> Result<Block<N>>
Returns the block for a given block height.
sourcepub fn get_blocks(
&self,
start_block_height: u32,
end_block_height: u32
) -> Result<Vec<Block<N>>>
pub fn get_blocks(
&self,
start_block_height: u32,
end_block_height: u32
) -> Result<Vec<Block<N>>>
Returns the blocks from the given start_block_height
to end_block_height
(inclusive).
sourcepub fn get_previous_ledger_root(
&self,
block_height: u32
) -> Result<N::LedgerRoot>
pub fn get_previous_ledger_root(
&self,
block_height: u32
) -> Result<N::LedgerRoot>
Returns the ledger root in the block header of the given block height.
sourcepub fn get_block_locators(&self, block_height: u32) -> Result<BlockLocators<N>>
pub fn get_block_locators(&self, block_height: u32) -> Result<BlockLocators<N>>
Returns the block locators of the current ledger, from the given block height.
sourcepub fn check_block_locators(
&self,
block_locators: &BlockLocators<N>
) -> Result<bool>
pub fn check_block_locators(
&self,
block_locators: &BlockLocators<N>
) -> Result<bool>
Check that the block locators are well formed.
sourcepub fn get_block_template<R: Rng + CryptoRng>(
&self,
recipient: Address<N>,
is_public: bool,
transactions: &[Transaction<N>],
rng: &mut R
) -> Result<BlockTemplate<N>>
pub fn get_block_template<R: Rng + CryptoRng>(
&self,
recipient: Address<N>,
is_public: bool,
transactions: &[Transaction<N>],
rng: &mut R
) -> Result<BlockTemplate<N>>
Returns a block template based on the latest state of the ledger.
sourcepub fn mine_next_block<R: Rng + CryptoRng>(
&self,
recipient: Address<N>,
is_public: bool,
transactions: &[Transaction<N>],
terminator: &AtomicBool,
rng: &mut R
) -> Result<(Block<N>, Record<N>)>
pub fn mine_next_block<R: Rng + CryptoRng>(
&self,
recipient: Address<N>,
is_public: bool,
transactions: &[Transaction<N>],
terminator: &AtomicBool,
rng: &mut R
) -> Result<(Block<N>, Record<N>)>
Mines a new block using the latest state of the given ledger.
sourcepub fn add_next_block(&self, block: &Block<N>) -> Result<()>
pub fn add_next_block(&self, block: &Block<N>) -> Result<()>
Adds the given block as the next block in the ledger to storage.
sourcepub fn revert_to_block_height(&self, block_height: u32) -> Result<Vec<Block<N>>>
pub fn revert_to_block_height(&self, block_height: u32) -> Result<Vec<Block<N>>>
Reverts the ledger state back to the given block height, returning the removed blocks on success.
sourcepub fn get_ledger_inclusion_proof(
&self,
commitment: N::Commitment
) -> Result<LedgerProof<N>>
pub fn get_ledger_inclusion_proof(
&self,
commitment: N::Commitment
) -> Result<LedgerProof<N>>
Returns a ledger proof for the given commitment.
Trait Implementations
Auto Trait Implementations
impl<N> !RefUnwindSafe for LedgerState<N>
impl<N> Send for LedgerState<N> where
<N as Network>::InnerCurve: PairingEngine<Fq = <N as Network>::OuterScalarField> + PairingEngine<Fr = <N as Network>::InnerScalarField>,
impl<N> Sync for LedgerState<N> where
<N as Network>::InnerCurve: PairingEngine<Fq = <N as Network>::OuterScalarField> + PairingEngine<Fr = <N as Network>::InnerScalarField>,
impl<N> Unpin for LedgerState<N> where
N: Unpin,
<N as Network>::BlockHash: Unpin,
<N as Network>::Commitment: Unpin,
<N as Network>::FunctionID: Unpin,
<<N as Network>::InnerCurve as PairingEngine>::G1Affine: Unpin,
<N as Network>::InnerCircuitID: Unpin,
<N as Network>::InnerCurve: PairingEngine<Fq = <N as Network>::OuterScalarField> + PairingEngine<Fr = <N as Network>::InnerScalarField>,
<N as Network>::InnerScalarField: Unpin,
<N as Network>::LedgerRoot: Unpin,
<N as Network>::OuterProof: Unpin,
<N as Network>::PoSWNonce: Unpin,
<N as Network>::PoSWProof: Unpin,
<N as Network>::ProgramAffineCurve: Unpin,
<N as Network>::RecordCiphertext: Unpin,
<N as Network>::RecordViewKey: Unpin,
<N as Network>::SerialNumber: Unpin,
<N as Network>::TransactionID: Unpin,
<N as Network>::TransactionsRoot: Unpin,
<N as Network>::TransitionID: Unpin,
impl<N> !UnwindSafe for LedgerState<N>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
pub fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more