pub struct Chain {
pub chain: Vec<Block>,
pub current_transactions: Vec<Transaction>,
pub difficulty: f64,
pub address: String,
pub reward: f64,
pub fee: f64,
pub wallets: HashMap<String, Wallet, RandomState>,
}Expand description
Blockchain.
Fields§
§chain: Vec<Block>Chain of blocks.
current_transactions: Vec<Transaction>List of transactions.
difficulty: f64Current difficulty level of the network.
address: StringBlockchain genesis address.
reward: f64Block reward.
fee: f64Transaction fee.
wallets: HashMap<String, Wallet, RandomState>Map to associate wallets with their corresponding addresses and balances.
Implementations§
Source§impl Chain
impl Chain
Sourcepub fn get_transactions(&self, page: usize, size: usize) -> Vec<Transaction>
pub fn get_transactions(&self, page: usize, size: usize) -> Vec<Transaction>
Sourcepub fn get_transaction(&self, hash: String) -> Option<&Transaction>
pub fn get_transaction(&self, hash: String) -> Option<&Transaction>
Sourcepub fn create_wallet(&mut self, email: String) -> String
pub fn create_wallet(&mut self, email: String) -> String
Sourcepub fn get_wallet_balance(&self, address: String) -> Option<f64>
pub fn get_wallet_balance(&self, address: String) -> Option<f64>
Sourcepub fn get_wallet_transactions(
&self,
address: String,
page: usize,
size: usize,
) -> Option<Vec<Transaction>>
pub fn get_wallet_transactions( &self, address: String, page: usize, size: usize, ) -> Option<Vec<Transaction>>
Sourcepub fn get_last_hash(&self) -> String
pub fn get_last_hash(&self) -> String
Get the hash of the last block in the blockchain.
§Returns
The hash of the last block in the blockchain as a string.
Sourcepub fn update_difficulty(&mut self, difficulty: f64) -> bool
pub fn update_difficulty(&mut self, difficulty: f64) -> bool
Sourcepub fn update_reward(&mut self, reward: f64) -> bool
pub fn update_reward(&mut self, reward: f64) -> bool
Sourcepub fn update_fee(&mut self, fee: f64) -> bool
pub fn update_fee(&mut self, fee: f64) -> bool
Sourcepub fn generate_new_block(&mut self) -> bool
pub fn generate_new_block(&mut self) -> bool
Generate a new block and append it to the blockchain.
§Returns
true if a new block is successfully generated and added to the blockchain.
Sourcepub fn get_merkle(transactions: Vec<Transaction>) -> String
pub fn get_merkle(transactions: Vec<Transaction>) -> String
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Chain
impl<'de> Deserialize<'de> for Chain
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Chain
impl RefUnwindSafe for Chain
impl Send for Chain
impl Sync for Chain
impl Unpin for Chain
impl UnwindSafe for Chain
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