[−][src]Struct snarkos_testing::storage::Ledger
Fields
latest_block_height: RwLock<RawRwLock, u32>
ledger_parameters: P
cm_merkle_tree: RwLock<RawRwLock, MerkleTree<P>>
storage: Arc<Storage>
_transaction: PhantomData<T>
Implementations
impl<T, P> Ledger<T, P> where
P: LoadableMerkleParameters,
T: Transaction,
[src]
P: LoadableMerkleParameters,
T: Transaction,
pub fn open() -> Result<Ledger<T, P>, StorageError>
[src]
Instantiates a new ledger storage.
pub fn open_at_path<PATH>(path: PATH) -> Result<Ledger<T, P>, StorageError> where
PATH: AsRef<Path>,
[src]
PATH: AsRef<Path>,
Open the blockchain storage at a particular path.
pub fn is_empty(&self) -> bool
[src]
Returns true if there are no blocks in the ledger.
pub fn get_latest_block_height(&self) -> u32
[src]
Get the latest block height of the chain.
pub fn get_block_count(&self) -> u32
[src]
Get the latest number of blocks in the chain.
pub fn get_peer_book(&self) -> Result<Vec<u8>, StorageError>
[src]
Get the stored old connected peers.
pub fn store_to_peer_book(
&self,
peers_serialized: Vec<u8>
) -> Result<(), StorageError>
[src]
&self,
peers_serialized: Vec<u8>
) -> Result<(), StorageError>
Store the connected peers.
pub fn destroy_storage(path: PathBuf) -> Result<(), StorageError>
[src]
Destroy the storage given a path.
impl<T, P> Ledger<T, P> where
P: LoadableMerkleParameters,
T: Transaction,
[src]
P: LoadableMerkleParameters,
T: Transaction,
pub fn get_latest_block(&self) -> Result<Block<T>, StorageError>
[src]
Get the latest block in the chain.
pub fn get_block(
&self,
block_hash: &BlockHeaderHash
) -> Result<Block<T>, StorageError>
[src]
&self,
block_hash: &BlockHeaderHash
) -> Result<Block<T>, StorageError>
Get a block given the block hash.
pub fn get_block_from_block_number(
&self,
block_number: u32
) -> Result<Block<T>, StorageError>
[src]
&self,
block_number: u32
) -> Result<Block<T>, StorageError>
Get a block given the block number.
pub fn get_block_hash(
&self,
block_number: u32
) -> Result<BlockHeaderHash, StorageError>
[src]
&self,
block_number: u32
) -> Result<BlockHeaderHash, StorageError>
Get the block hash given a block number.
pub fn get_block_number(
&self,
block_hash: &BlockHeaderHash
) -> Result<u32, StorageError>
[src]
&self,
block_hash: &BlockHeaderHash
) -> Result<u32, StorageError>
Get the block number given a block hash.
pub fn get_block_transactions(
&self,
block_hash: &BlockHeaderHash
) -> Result<DPCTransactions<T>, StorageError>
[src]
&self,
block_hash: &BlockHeaderHash
) -> Result<DPCTransactions<T>, StorageError>
Get the list of transaction ids given a block hash.
pub fn get_child_block_hashes(
&self,
parent_header: &BlockHeaderHash
) -> Result<Vec<BlockHeaderHash>, StorageError>
[src]
&self,
parent_header: &BlockHeaderHash
) -> Result<Vec<BlockHeaderHash>, StorageError>
Find the potential child block hashes given a parent block header.
pub fn already_mined(
&self,
block: &Block<T>
) -> Result<Option<u32>, StorageError>
[src]
&self,
block: &Block<T>
) -> Result<Option<u32>, StorageError>
Returns the block number of a conflicting block that has already been mined.
pub fn remove_block(
&self,
block_hash: BlockHeaderHash
) -> Result<(), StorageError>
[src]
&self,
block_hash: BlockHeaderHash
) -> Result<(), StorageError>
Remove a block and it's related data from the storage.
pub fn decommit_latest_block(&self) -> Result<BlockHeaderHash, StorageError>
[src]
De-commit the latest block and return its header hash.
pub fn remove_latest_block(&self) -> Result<(), StorageError>
[src]
Remove the latest block.
pub fn remove_latest_blocks(&self, num_blocks: u32) -> Result<(), StorageError>
[src]
Remove the latest num_blocks
blocks.
impl<T, P> Ledger<T, P> where
P: LoadableMerkleParameters,
T: Transaction,
[src]
P: LoadableMerkleParameters,
T: Transaction,
pub fn block_hash_exists(&self, block_hash: &BlockHeaderHash) -> bool
[src]
Returns true if the block for the given block header hash exists.
pub fn get_block_header(
&self,
block_hash: &BlockHeaderHash
) -> Result<BlockHeader, StorageError>
[src]
&self,
block_hash: &BlockHeaderHash
) -> Result<BlockHeader, StorageError>
Get a block header given the block hash.
pub fn previous_block_hash_exists(&self, block: &Block<T>) -> bool
[src]
Returns true if the block corresponding to this block's previous_block_hash exists.
pub fn get_latest_shared_hash(
&self,
block_locator_hashes: Vec<BlockHeaderHash>
) -> Result<BlockHeaderHash, StorageError>
[src]
&self,
block_locator_hashes: Vec<BlockHeaderHash>
) -> Result<BlockHeaderHash, StorageError>
Returns the latest shared block header hash. If the block locator hashes are for a side chain, returns the common point of fork. If the block locator hashes are for the canon chain, returns the latest block header hash.
pub fn get_block_locator_hashes(
&self
) -> Result<Vec<BlockHeaderHash>, StorageError>
[src]
&self
) -> Result<Vec<BlockHeaderHash>, StorageError>
Returns a list of block locator hashes. The purpose of this method is to detect wrong branches in the caller's canon chain.
impl<T, P> Ledger<T, P> where
P: LoadableMerkleParameters,
T: Transaction,
[src]
P: LoadableMerkleParameters,
T: Transaction,
pub fn get_block_path(
&self,
block_header: &BlockHeader
) -> Result<BlockPath, StorageError>
[src]
&self,
block_header: &BlockHeader
) -> Result<BlockPath, StorageError>
Get the block's path/origin.
pub fn longest_child_path(
&self,
block_hash: BlockHeaderHash
) -> Result<(usize, Vec<BlockHeaderHash>), StorageError>
[src]
&self,
block_hash: BlockHeaderHash
) -> Result<(usize, Vec<BlockHeaderHash>), StorageError>
Find the longest path of non-canon children from the given block header
impl<T, P> Ledger<T, P> where
P: LoadableMerkleParameters,
T: Transaction,
[src]
P: LoadableMerkleParameters,
T: Transaction,
pub fn current_cm_index(&self) -> Result<usize, StorageError>
[src]
Get the current commitment index
pub fn current_sn_index(&self) -> Result<usize, StorageError>
[src]
Get the current serial number index
pub fn current_memo_index(&self) -> Result<usize, StorageError>
[src]
Get the current memo index
pub fn current_digest(&self) -> Result<Vec<u8>, StorageError>
[src]
Get the current ledger digest
pub fn past_digests(
&self
) -> Result<HashSet<Vec<u8>, RandomState>, StorageError>
[src]
&self
) -> Result<HashSet<Vec<u8>, RandomState>, StorageError>
Get the set of past ledger digests
pub fn get_sn_index(
&self,
sn_bytes: &[u8]
) -> Result<Option<usize>, StorageError>
[src]
&self,
sn_bytes: &[u8]
) -> Result<Option<usize>, StorageError>
Get serial number index.
pub fn get_cm_index(
&self,
cm_bytes: &[u8]
) -> Result<Option<usize>, StorageError>
[src]
&self,
cm_bytes: &[u8]
) -> Result<Option<usize>, StorageError>
Get commitment index
pub fn get_memo_index(
&self,
memo_bytes: &[u8]
) -> Result<Option<usize>, StorageError>
[src]
&self,
memo_bytes: &[u8]
) -> Result<Option<usize>, StorageError>
Get memo index
pub fn build_merkle_tree(
&self,
additional_cms: Vec<(<T as Transaction>::Commitment, usize)>
) -> Result<MerkleTree<P>, StorageError>
[src]
&self,
additional_cms: Vec<(<T as Transaction>::Commitment, usize)>
) -> Result<MerkleTree<P>, StorageError>
Get memo index
pub fn update_merkle_tree(&self) -> Result<(), StorageError>
[src]
Rebuild the stored merkle tree with the current stored commitments
impl<T, P> Ledger<T, P> where
P: LoadableMerkleParameters,
T: Transaction,
[src]
P: LoadableMerkleParameters,
T: Transaction,
pub fn insert_only(&self, block: &Block<T>) -> Result<(), StorageError>
[src]
pub fn commit(
&self,
block_header_hash: &BlockHeaderHash
) -> Result<(), StorageError>
[src]
&self,
block_header_hash: &BlockHeaderHash
) -> Result<(), StorageError>
Commit/canonize a particular block.
pub fn insert_and_commit(&self, block: &Block<T>) -> Result<(), StorageError>
[src]
Insert a block into the storage and commit as part of the longest chain.
pub fn is_canon(&self, block_hash: &BlockHeaderHash) -> bool
[src]
Returns true if the block exists in the canon chain.
pub fn is_previous_block_canon(&self, block_header: &BlockHeader) -> bool
[src]
Returns true if the block corresponding to this block's previous_block_h.is_canon(&block_haash is in the canon chain.
pub fn revert_for_fork(
&self,
side_chain_path: &SideChainPath
) -> Result<(), StorageError>
[src]
&self,
side_chain_path: &SideChainPath
) -> Result<(), StorageError>
Revert the chain to the state before the fork.
impl<T, P> Ledger<T, P> where
P: LoadableMerkleParameters,
T: Transaction,
[src]
P: LoadableMerkleParameters,
T: Transaction,
pub fn get_memory_pool(&self) -> Result<Vec<u8>, StorageError>
[src]
Get the stored memory pool transactions.
pub fn store_to_memory_pool(
&self,
transactions_serialized: Vec<u8>
) -> Result<(), StorageError>
[src]
&self,
transactions_serialized: Vec<u8>
) -> Result<(), StorageError>
Store the memory pool transactions.
impl<T, P> Ledger<T, P> where
P: LoadableMerkleParameters,
T: Transaction,
[src]
P: LoadableMerkleParameters,
T: Transaction,
pub fn get_record_commitments(
&self,
limit: Option<usize>
) -> Result<Vec<Vec<u8>>, StorageError>
[src]
&self,
limit: Option<usize>
) -> Result<Vec<Vec<u8>>, StorageError>
Get all stored record commitments of the node
pub fn get_record<R>(
&self,
record_commitment: &Vec<u8>
) -> Result<Option<R>, StorageError> where
R: Record,
[src]
&self,
record_commitment: &Vec<u8>
) -> Result<Option<R>, StorageError> where
R: Record,
Get a transaction bytes given the transaction id.
pub fn store_record<R>(&self, record: &R) -> Result<(), StorageError> where
R: Record,
[src]
R: Record,
Get a transaction bytes given the transaction id.
pub fn store_records<R>(&self, records: &Vec<R>) -> Result<(), StorageError> where
R: Record,
[src]
R: Record,
Get a transaction bytes given the transaction id.
pub fn delete_record<R>(&self, record: R) -> Result<(), StorageError> where
R: Record,
[src]
R: Record,
Removes a record from storage.
impl<T, P> Ledger<T, P> where
P: LoadableMerkleParameters,
T: Transaction,
[src]
P: LoadableMerkleParameters,
T: Transaction,
pub fn get_transaction_location(
&self,
transaction_id: &Vec<u8>
) -> Result<Option<TransactionLocation>, StorageError>
[src]
&self,
transaction_id: &Vec<u8>
) -> Result<Option<TransactionLocation>, StorageError>
Returns a transaction location given the transaction ID if it exists. Returns None
otherwise.
pub fn get_transaction(
&self,
transaction_id: &Vec<u8>
) -> Result<Option<T>, StorageError>
[src]
&self,
transaction_id: &Vec<u8>
) -> Result<Option<T>, StorageError>
Returns a transaction given the transaction ID if it exists. Returns None
otherwise.
pub fn get_transaction_bytes(
&self,
transaction_id: &Vec<u8>
) -> Result<Vec<u8>, StorageError>
[src]
&self,
transaction_id: &Vec<u8>
) -> Result<Vec<u8>, StorageError>
Returns a transaction in bytes given a transaction ID.
pub fn transcation_conflicts(&self, transaction: &T) -> bool
[src]
Returns true if the transaction has internal parameters that already exist in the ledger.
Trait Implementations
impl<T, P> LedgerScheme for Ledger<T, P> where
P: LoadableMerkleParameters,
T: Transaction,
[src]
P: LoadableMerkleParameters,
T: Transaction,
type Block = Block<<Ledger<T, P> as LedgerScheme>::Transaction>
type Commitment = <T as Transaction>::Commitment
type MerkleParameters = P
type MerklePath = MerklePath<<Ledger<T, P> as LedgerScheme>::MerkleParameters>
type MerkleTreeDigest = <<<Ledger<T, P> as LedgerScheme>::MerkleParameters as MerkleParameters>::H as CRH>::Output
type SerialNumber = <T as Transaction>::SerialNumber
type Transaction = T
fn new(
path: &PathBuf,
parameters: <Ledger<T, P> as LedgerScheme>::MerkleParameters,
genesis_block: <Ledger<T, P> as LedgerScheme>::Block
) -> Result<Ledger<T, P>, LedgerError>
[src]
path: &PathBuf,
parameters: <Ledger<T, P> as LedgerScheme>::MerkleParameters,
genesis_block: <Ledger<T, P> as LedgerScheme>::Block
) -> Result<Ledger<T, P>, LedgerError>
Instantiates a new ledger with a genesis block.
fn len(&self) -> usize
[src]
Returns the number of blocks including the genesis block
fn parameters(&self) -> &<Ledger<T, P> as LedgerScheme>::MerkleParameters
[src]
Return the parameters used to construct the ledger Merkle tree.
fn digest(&self) -> Option<<Ledger<T, P> as LedgerScheme>::MerkleTreeDigest>
[src]
Return a digest of the latest ledger Merkle tree.
fn validate_digest(
&self,
digest: &<Ledger<T, P> as LedgerScheme>::MerkleTreeDigest
) -> bool
[src]
&self,
digest: &<Ledger<T, P> as LedgerScheme>::MerkleTreeDigest
) -> bool
Check that st_{ts} is a valid digest for some (past) ledger state.
fn contains_cm(&self, cm: &<Ledger<T, P> as LedgerScheme>::Commitment) -> bool
[src]
Returns true if the given commitment exists in the ledger.
fn contains_sn(&self, sn: &<Ledger<T, P> as LedgerScheme>::SerialNumber) -> bool
[src]
Returns true if the given serial number exists in the ledger.
fn contains_memo(
&self,
memo: &<<Ledger<T, P> as LedgerScheme>::Transaction as Transaction>::Memorandum
) -> bool
[src]
&self,
memo: &<<Ledger<T, P> as LedgerScheme>::Transaction as Transaction>::Memorandum
) -> bool
Returns true if the given memo exists in the ledger.
fn prove_cm(
&self,
cm: &<Ledger<T, P> as LedgerScheme>::Commitment
) -> Result<<Ledger<T, P> as LedgerScheme>::MerklePath, LedgerError>
[src]
&self,
cm: &<Ledger<T, P> as LedgerScheme>::Commitment
) -> Result<<Ledger<T, P> as LedgerScheme>::MerklePath, LedgerError>
Returns the Merkle path to the latest ledger digest for a given commitment, if it exists in the ledger.
fn verify_cm(
_parameters: &<Ledger<T, P> as LedgerScheme>::MerkleParameters,
digest: &<Ledger<T, P> as LedgerScheme>::MerkleTreeDigest,
cm: &<Ledger<T, P> as LedgerScheme>::Commitment,
witness: &<Ledger<T, P> as LedgerScheme>::MerklePath
) -> bool
[src]
_parameters: &<Ledger<T, P> as LedgerScheme>::MerkleParameters,
digest: &<Ledger<T, P> as LedgerScheme>::MerkleTreeDigest,
cm: &<Ledger<T, P> as LedgerScheme>::Commitment,
witness: &<Ledger<T, P> as LedgerScheme>::MerklePath
) -> bool
Returns true if the given Merkle path is a valid witness for the given ledger digest and commitment.
Auto Trait Implementations
impl<T, P> !RefUnwindSafe for Ledger<T, P>
impl<T, P> Send for Ledger<T, P> where
P: Send,
T: Send,
<P as MerkleParameters>::H: CRH,
<<P as MerkleParameters>::H as CRH>::Output: Send,
P: Send,
T: Send,
<P as MerkleParameters>::H: CRH,
<<P as MerkleParameters>::H as CRH>::Output: Send,
impl<T, P> Sync for Ledger<T, P> where
P: Send + Sync,
T: Sync,
<P as MerkleParameters>::H: CRH,
<<P as MerkleParameters>::H as CRH>::Output: Send + Sync,
P: Send + Sync,
T: Sync,
<P as MerkleParameters>::H: CRH,
<<P as MerkleParameters>::H as CRH>::Output: Send + Sync,
impl<T, P> Unpin for Ledger<T, P> where
P: Unpin,
T: Unpin,
<P as MerkleParameters>::H: CRH,
<<P as MerkleParameters>::H as CRH>::Output: Unpin,
P: Unpin,
T: Unpin,
<P as MerkleParameters>::H: CRH,
<<P as MerkleParameters>::H as CRH>::Output: Unpin,
impl<T, P> UnwindSafe for Ledger<T, P> where
P: UnwindSafe,
T: UnwindSafe,
<P as MerkleParameters>::H: CRH,
<<P as MerkleParameters>::H as CRH>::Output: UnwindSafe,
P: UnwindSafe,
T: UnwindSafe,
<P as MerkleParameters>::H: CRH,
<<P as MerkleParameters>::H as CRH>::Output: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,