{"id":21233649,"url":"https://github.com/bdr-pro/blockchain_maker","last_synced_at":"2025-03-15T02:43:50.847Z","repository":{"id":226068091,"uuid":"767627586","full_name":"BDR-Pro/blockchain_maker","owner":"BDR-Pro","description":"this is your ultimate toolkit for building, validating, and managing a blockchain in Rust.","archived":false,"fork":false,"pushed_at":"2024-03-07T10:36:06.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-28T07:04:07.670Z","etag":null,"topics":["blockchain","cryptocurrency","cryptography","rust"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/blockchain_maker","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BDR-Pro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-03-05T16:27:39.000Z","updated_at":"2024-03-05T18:57:00.000Z","dependencies_parsed_at":"2024-03-05T18:44:27.490Z","dependency_job_id":null,"html_url":"https://github.com/BDR-Pro/blockchain_maker","commit_stats":null,"previous_names":["bdr-pro/blockchain_maker"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BDR-Pro%2Fblockchain_maker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BDR-Pro%2Fblockchain_maker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BDR-Pro%2Fblockchain_maker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BDR-Pro%2Fblockchain_maker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BDR-Pro","download_url":"https://codeload.github.com/BDR-Pro/blockchain_maker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243676707,"owners_count":20329432,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blockchain","cryptocurrency","cryptography","rust"],"created_at":"2024-11-20T23:59:49.403Z","updated_at":"2025-03-15T02:43:50.829Z","avatar_url":"https://github.com/BDR-Pro.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rust Blockchain Maker Package 🚀\n\nWelcome to the Rust Blockchain Maker Package! This is your ultimate toolkit for building, validating, and managing a blockchain in Rust. Below, you'll find everything you need to know to integrate and leverage our blockchain functionality in your Rust projects.\n\n## Dependencies 📦\n\nBefore diving into the blockchain wonders, make sure to include the following dependencies in your `Cargo.toml`:\n\n```toml\nchrono = \"0.4\"\nserde = { version = \"1.0\", features = [\"derive\"] }\nsha2 = \"0.10\"\nopenssl = \"0.10\"\nserde_json = \"1.0\"\n```\n\nThese dependencies will ensure proper handling of time, serialization, cryptographic functions, and JSON formatting.\n\n## Getting Started 🌟\n\nImport the necessary modules from our package and standard Rust libraries to start crafting your blockchain:\n\n```rust\nuse blockchain_maker::Blockchain; // Our primary Blockchain structure.\n//instead of all of this\nuse chrono::prelude::*; // For handling timestamps.\nuse serde::{Deserialize, Serialize}; // For data serialization.\nuse sha2::{Sha256, Digest}; // For creating cryptographic hashes.\nuse openssl::ec::{EcGroup, EcKey}; // For elliptic curve cryptography.\n```\n\n## Core Functionalities 🛠\n\nOur package provides a variety of functions to support your blockchain adventures:\n\n### `get_block_hash_from_file(path: P) -\u003e Result\u003cString, Box\u003cdyn std::error::Error\u003e\u003e`\n\nRetrieves the hash of a blockchain block from a specified file.\n\n- **Parameters**: `path: P` - A reference to the file path containing the block.\n- **Returns**: A `Result` containing the block hash as a `String` if successful.\n\n### `count_files_in_folder(path: P) -\u003e std::io::Result\u003cusize\u003e`\n\nCounts the files in a specified directory, aiding in block management.\n\n- **Parameters**: `path: P` - A reference to the directory path.\n- **Returns**: A `Result` with the count of files.\n\n### `sign(message: \u0026str, reward: u64, block_number: u64) -\u003e (Vec\u003cu8\u003e, Vec\u003cu8\u003e)`\n\nGenerates a digital signature for a given message using ECDSA.\n\n- **Parameters**\n\n    1- `message: \u0026str` - The message to sign.\n\n    2- `reward: u64` - The mining reward.\n\n    3- `block_number: u64` - The number of the block.\n- **Returns**: A tuple containing the signature and public key.\n\n## Structures 🏗\n\nOur primary structures include `Block` and `Blockchain`, designed to encapsulate all necessary blockchain data and functionalities:\n\n### `Block`\n\nRepresents a single block in the blockchain, containing attributes like `timestamp, data, previous_hash, etc.`\n\n### `Blockchain`\n\nManages the chain of blocks, providing methods for adding `new blocks, validating the chain, and calculating rewards.`\n\n## Usage Example 📝\n\nHere's how you can utilize our package to create and manage a blockchain:\n\n```rust\nuse blockchain_maker::Blockchain;\nuse blockchain_maker::count_files_in_folder;\n\nfn main() {\n    // Attempt to load the blockchain from disk\n    let mut blockchain: Blockchain = match Blockchain::load_chain_from_disk(\"my_blocks\".to_string()) {\n        Ok(chain) =\u003e chain,\n        Err(e) =\u003e {\n            // Handle the error e.g., by logging or creating a new, empty blockchain\n            println!(\"Failed to load chain from disk, error: {}\", e);\n            // Potentially initialize a new, empty blockchain here if desired\n            Blockchain::new() // This assumes you have a `new` method to create an empty blockchain\n        },\n    };\n\n    // Validate the loaded or new blockchain\n    if blockchain.validate_chain(\"my_blocks\".to_string()) {\n        println!(\"Blockchain validated successfully.\");\n    } else {\n        println!(\"Blockchain validation failed.\");\n    }\n\n    // Add new blocks to the blockchain\n    if let Err(e) = blockchain.add_block(\"Block 1 Transactions Data\".to_string()) {\n        println!(\"Failed to add block: {}\", e);\n    }\n\n    if let Err(e) = blockchain.add_block(\"Block 2 Transactions Data\".to_string()) {\n        println!(\"Failed to add block: {}\", e);\n    }\n\n    // Print out the current state of the blockchain or other relevant information\n    // This might involve iterating over the blocks and printing them out, \n    // or simply printing out the number of blocks in the chain\n    println!(\"Current blockchain size: {}\", count_files_in_folder(\"my_blocks\".to_string()).unwrap());\n}\n\n```\n\nThis example demonstrates loading a blockchain from disk, validating it, adding new blocks, and displaying the blockchain size.\n\n## Update 1.1.0 🚀\n\nNow you can chooes initial reward for the first block in the blockchain.\nplus when the halving will happen.\n\n```rust\n    pub struct Blockchain {\n    chain: Vec\u003cBlock\u003e,\n    get_reward: u64,\n    get_halving_interval: u64,\n}\n```\n\n## Contribution and Support 🤝\n\nContributions are welcome! If you'd like to contribute or have found bugs, please open an issue or pull request on our GitHub repository. For support, feel free to reach out via our support channels.\n\nDive into blockchain development with our Rust Blockchain Maker Package! Happy coding! 🚀\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbdr-pro%2Fblockchain_maker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbdr-pro%2Fblockchain_maker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbdr-pro%2Fblockchain_maker/lists"}