Skip to main content

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( &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()

Source

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

Source

pub fn get_utxos(&self) -> &UTXOs

Source

pub fn get_difficulty_manager(&self) -> &DifficultyState

Source

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

Source

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

Source

pub fn block_store(&self) -> &BlockStore

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, '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,

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§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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