Blockchain

Struct Blockchain 

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

The blockchain, handles everything. Core to this crypto coin.

Implementations§

Source§

impl Blockchain

Source

pub fn new(blockchain_path: &str) -> Self

Create a new blockchain or load one if exists at blockchain_path

Source

pub fn add_block(&mut self, new_block: Block) -> 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

Source

pub fn pop_block(&mut 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

Source

pub fn get_block_by_height(&self, height: usize) -> Option<Block>

Source

pub fn get_utxo_diffs_by_height(&self, height: usize) -> Option<UTXODiff>

Source

pub fn get_block_by_hash(&self, hash: &Hash) -> Option<Block>

Source

pub fn get_height_by_hash(&self, hash: &Hash) -> Option<usize>

Source

pub fn get_block_hash_by_height(&self, height: usize) -> Option<&Hash>

Source

pub fn get_height(&self) -> usize

Source

pub fn get_utxos(&self) -> &UTXOs

Source

pub fn get_difficulty_manager(&self) -> &DifficultyManager

Source

pub fn get_transaction_difficulty(&self) -> [u8; 32]

Source

pub fn get_block_difficulty(&self) -> [u8; 32]

Source

pub fn get_all_blocks(&self) -> Vec<&Hash>

Trait Implementations§

Source§

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,

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,

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,

Get block by height Returns option
Source§

fn get_block_by_hash<'life0, 'life1, 'async_trait>( &'life0 self, hash: &'life1 Hash, ) -> Pin<Box<dyn Future<Output = Result<Option<Block>, BlockchainDataProviderError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get block by hash Returns option
Source§

fn get_height_by_hash<'life0, 'life1, 'async_trait>( &'life0 self, hash: &'life1 Hash, ) -> Pin<Box<dyn Future<Output = Result<Option<usize>, BlockchainDataProviderError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: '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,

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,

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,

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,

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

impl Debug for Blockchain

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

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> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, U> TryFrom<U> for T
where 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>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where 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>

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V