Blockchain
A Rust crate provides an interface for interacting with a blockchain.
Reference implementation
Features
new(address, difficulty, reward): Initialize a new blockchain with the specified parameters.get_transactions(): Get a list of current transactions in the blockchain.get_transaction(hash): Get a transaction by its hash.add_transaction(from, to, amount): Add a new transaction to the blockchain.validate_transaction(from, amount): Validate a new transaction to the blockchain.get_last_hash(): Get the hash of the last block in the blockchain.update_difficulty(difficulty): Update the mining difficulty of the blockchain.update_reward(reward): Update the block reward.update_fee(fee): Update the transaction fee.generate_new_block(): Generate a new block and append it to the blockchain.get_merkle(transactions): Calculate the Merkle root hash for a list of transactions.proof_of_work(header): Perform the proof-of-work process to mine a block.hash(item): Calculate the SHA-256 hash of a serializable item.
Options
| Option | Data type | Description |
|---|---|---|
address |
String |
The address associated with the blockchain. |
difficulty |
f64 |
The initial mining difficulty level of the network. |
reward |
f64 |
The initial block reward for miners. |
fee |
f64 |
The transaction fee. |
Safety
This crate uses #![forbid(unsafe_code)] to ensure everything is implemented in 100% safe Rust.
Documentation
For more in-depth details, please refer to the full documentation.
If you encounter any issues or have questions that are not addressed in the documentation, feel free to submit an issue.
Usage
Run the following Cargo command in your project directory:
extern crate blockchain;
use Chain;
Examples
Provides a command-line interface (CLI) for interacting with blockchain
Contributing
Build the application:
Test the application:
Run the application:
Run clippy:
Run lint:
Generate documentation in HTML format: