pub struct Blockchain { /* private fields */ }Expand description
The blockchain, handles everything. Core to this crypto coin.
Implementations§
Source§impl Blockchain
impl Blockchain
Sourcepub fn new(blockchain_path: &str) -> Self
pub fn new(blockchain_path: &str) -> Self
Create a new blockchain or load one if exists at blockchain_path
Sourcepub fn add_block(
&self,
new_block: Block,
is_ibd: bool,
) -> Result<(), BlockchainError>
pub fn add_block( &self, new_block: Block, is_ibd: bool, ) -> Result<(), BlockchainError>
Add a block to the blockchain, and then save the state of it Will return a blockchain error if the block or any of its included transactions are invalid WARNING: This can be randomly async unsafe, so if you have problems, wrap it in a spawn_blocking()
Sourcepub fn pop_block(&self) -> Result<(), BlockchainError>
pub fn pop_block(&self) -> Result<(), BlockchainError>
Remove the last block added to the blockchain, and update the states of utxos and difficulty manager to return the blockchain to the state it was before the last block was added
pub fn get_utxos(&self) -> &UTXOs
pub fn get_difficulty_manager(&self) -> &DifficultyState
pub fn get_transaction_difficulty(&self) -> [u8; 32]
pub fn get_block_difficulty(&self) -> [u8; 32]
pub fn block_store(&self) -> &BlockStore
Trait Implementations§
Source§impl BlockchainDataProvider for Blockchain
impl BlockchainDataProvider for Blockchain
Source§fn get_height<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<usize, BlockchainDataProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_height<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<usize, BlockchainDataProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Get current height
Source§fn get_reward<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<u64, BlockchainDataProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_reward<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<u64, BlockchainDataProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Get current block reward
Source§fn get_block_by_height<'life0, 'async_trait>(
&'life0 self,
height: usize,
) -> Pin<Box<dyn Future<Output = Result<Option<Block>, BlockchainDataProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_block_by_height<'life0, 'async_trait>(
&'life0 self,
height: usize,
) -> Pin<Box<dyn Future<Output = Result<Option<Block>, BlockchainDataProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Get block by height
Returns option
Source§fn get_block_by_hash<'life0, 'async_trait>(
&'life0 self,
hash: Hash,
) -> Pin<Box<dyn Future<Output = Result<Option<Block>, BlockchainDataProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_block_by_hash<'life0, 'async_trait>(
&'life0 self,
hash: Hash,
) -> Pin<Box<dyn Future<Output = Result<Option<Block>, BlockchainDataProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Get block by hash
Returns option
Source§fn get_height_by_hash<'life0, 'async_trait>(
&'life0 self,
hash: Hash,
) -> Pin<Box<dyn Future<Output = Result<Option<usize>, BlockchainDataProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_height_by_hash<'life0, 'async_trait>(
&'life0 self,
hash: Hash,
) -> Pin<Box<dyn Future<Output = Result<Option<usize>, BlockchainDataProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Get block height by its hash
Returns option
Source§fn get_block_hash_by_height<'life0, 'async_trait>(
&'life0 self,
height: usize,
) -> Pin<Box<dyn Future<Output = Result<Option<Hash>, BlockchainDataProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_block_hash_by_height<'life0, 'async_trait>(
&'life0 self,
height: usize,
) -> Pin<Box<dyn Future<Output = Result<Option<Hash>, BlockchainDataProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Get blocks hash by its block height at which it was added
Returns option
Source§fn get_transaction_difficulty<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<[u8; 32], BlockchainDataProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_transaction_difficulty<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<[u8; 32], BlockchainDataProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Gets current transaction pow difficulty
Source§fn get_block_difficulty<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<[u8; 32], BlockchainDataProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_block_difficulty<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<[u8; 32], BlockchainDataProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Gets current block pow difficulty
Source§fn get_available_transaction_outputs<'life0, 'async_trait>(
&'life0 self,
address: Public,
) -> Pin<Box<dyn Future<Output = Result<Vec<(TransactionId, TransactionOutput, usize)>, BlockchainDataProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_available_transaction_outputs<'life0, 'async_trait>(
&'life0 self,
address: Public,
) -> Pin<Box<dyn Future<Output = Result<Vec<(TransactionId, TransactionOutput, usize)>, BlockchainDataProviderError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Gets all available unspent transactions for an address
Returns a list of unspent outputs (sometimes referred to as inputs as well) and their associated transaction and index in the transactions outputs
Auto Trait Implementations§
impl !Freeze for Blockchain
impl !RefUnwindSafe for Blockchain
impl Send for Blockchain
impl Sync for Blockchain
impl Unpin for Blockchain
impl !UnwindSafe for Blockchain
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more