{"id":28339657,"url":"https://github.com/jitendragangwar123/chainrust","last_synced_at":"2025-10-04T14:11:37.232Z","repository":{"id":293898423,"uuid":"985283913","full_name":"jitendragangwar123/ChainRust","owner":"jitendragangwar123","description":"ChainRust is a high-performance blockchain built in Rust, designed for secure and scalable decentralized applications.","archived":false,"fork":false,"pushed_at":"2025-05-27T06:44:42.000Z","size":54,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-20T09:44:03.010Z","etag":null,"topics":["actix-web","blockchain","cryptography","rust"],"latest_commit_sha":null,"homepage":"","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/jitendragangwar123.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,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-17T12:47:47.000Z","updated_at":"2025-06-06T11:48:22.000Z","dependencies_parsed_at":"2025-05-17T20:38:01.510Z","dependency_job_id":null,"html_url":"https://github.com/jitendragangwar123/ChainRust","commit_stats":null,"previous_names":["jitendragangwar123/chainrust"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jitendragangwar123/ChainRust","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jitendragangwar123%2FChainRust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jitendragangwar123%2FChainRust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jitendragangwar123%2FChainRust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jitendragangwar123%2FChainRust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jitendragangwar123","download_url":"https://codeload.github.com/jitendragangwar123/ChainRust/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jitendragangwar123%2FChainRust/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278322146,"owners_count":25967874,"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","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["actix-web","blockchain","cryptography","rust"],"created_at":"2025-05-27T01:50:23.526Z","updated_at":"2025-10-04T14:11:37.219Z","avatar_url":"https://github.com/jitendragangwar123.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ChainRust\n\nA simple blockchain implementation in Rust using the Actix Web framework. The application supports creating and managing a blockchain with transactions, blocks, and Proof of Work (PoW) mining. It includes a REST API with endpoints to retrieve the blockchain and add new blocks, along with Swagger documentation for easy interaction via a web interface.\n\n## Features\n- **Blockchain Core**:\n  - Transactions with sender, receiver, and amount.\n  - Blocks containing transactions, linked via hashes.\n  - Proof of Work mining with configurable difficulty.\n  - Chain validation to ensure integrity.\n  - Persistence to a JSON file (`blockchain.json`).\n  \n- **REST API**:\n  - `POST /wallet`: Create a new wallet with key pair.\n  - `POST /faucet`: Add funds to an address for testing.\n  - `GET /check_balance`: Retrieve an address’s balance.\n  - `POST /transaction`: Add a transaction to the mempool.\n  - `POST /add_block`: Add a new block with transactions.\n  - `GET /chain`: Retrieve the entire blockchain.\n\n  \n- **Swagger Documentation**:\n  - Interactive Swagger UI at `/swagger-ui/` for API exploration and testing.\n  - OpenAPI specification available at `/api-docs/openapi.json`.\n\n- **Modular Design**:\n  - Code organized into modules for transactions, blocks, blockchain, API, and models.\n- **Logging**:\n  - Detailed logging using the `log` crate for debugging and monitoring.\n\n## Prerequisites\n- **Rust**: Install Rust and Cargo (recommended version: 1.81 or later) via [rustup](https://rustup.rs/).\n- **Git**: For cloning the repository.\n- **curl** or a similar tool (optional): For testing API endpoints.\n\n## Setup\n**Clone the Repository**:\n   ```bash\n   git clone https://github.com/jitendragangwar123/ChainRust.git\n   cd ChainRust\n   ```\n**Install Dependencies**:\n  - ***Ensure the following are in your Cargo.toml***:\n  \n    ```bash\n    [dependencies]\n    actix-web=\"4.9.0\"\n    chrono=\"0.4.38\" #handling dates and times\n    serde={version = \"1.0.210\",features = [\"derive\"]}\n    serde_json=\"1.0.128\"\n    sha2=\"0.10.8\"\n    tokio={version = \"1.40.0\",features = [\"full\"]}\n    log = \"0.4.22\"\n    env_logger = \"0.11.5\"\n    utoipa = { version = \"4.2\", features = [\"actix_extras\"] }\n    utoipa-swagger-ui = { version = \"4.0\", features = [\"actix-web\"] }\n    secp256k1 = { version = \"0.29\", features = [\"rand-std\"] }\n    rand = \"0.8\"\n    hex = \"0.4\"\n\n    ```\n**Running the Blockahin Server**:\n```bash\ncargo build\nRUST_LOG=info cargo run\n```\n**Access the Swagger UI**:\n- Open http://127.0.0.1:8080/swagger-ui/ in a browser.\n- Use the UI to explore and test the API endpoints interactively.\n\n\n## API Endpoints\n\n### POST /wallet\n**Description**: Create a new wallet with key pair.\n```bash\ncurl -X POST http://127.0.0.1:8080/wallet -H \"Content-Type: application/json\"\n```\n\n**Response**:\n- `200 OK`: Returns the wallet as JSON.\n- `500 Internal Server Error`: If the server encounters an issue (e.g., key generation failure).\n\n### POST /faucet\n**Description**: Add funds to an address for testing.\n\n```bash\ncurl -X POST http://127.0.0.1:8080/faucet -H \"Content-Type: application/json\" -d '{\"address\": \"\u003cpublic_key\u003e\"}'\n```\n\n\n**Response**:\n- `200 OK`: Returns a JSON string confirming funds added.\n- `400 Bad Request`: If the request body is invalid (e.g., missing address).\n- `500 Internal Server Error`: If the server encounters an issue (e.g., mutex poisoning).\n\n\n### GET /check_balance\n**Description**: Retrieve an address’s balance.\n```bash\ncurl -X GET \"http://127.0.0.1:8080/check_balance?address=\u003cpublic_key\u003e\"\n```\n\n**Response**:\n- `200 OK`: Returns the balance as a JSON integer.\n- `400 Bad Request`: If the request body is invalid (e.g., missing address).\n- `500 Internal Server Error`: If the server encounters an issue (e.g., mutex poisoning).\n\n### POST /transaction\n**Description**: Add a transaction to the mempool.\n\n```bash\ncurl -X POST http://127.0.0.1:8080/transaction -H \"Content-Type: application/json\" -d '{\"sender\": \"\u003cpublic_key\u003e\", \"receiver\": \"\u003cpublic_key\u003e\", \"amount\": 50, \"private_key\": \"\u003csender_private_key\u003e\"}'\n```\n\n**Response**:\n- `200 OK`: Returns a JSON string confirming transaction addition.\n- `400 Bad Request`: If the signature is invalid or funds are insufficient.\n- `500 Internal Server Error`: If the server encounters an issue (e.g., mutex poisoning).\n\n### POST /add_block\n**Description**: Add a new block with mempool transactions.\n```bash\ncurl -X POST http://127.0.0.1:8080/add_block\n```\n\n**Response**:\n- `200 OK`: Returns a JSON string confirming block addition.\n- `400 Bad Request`: If the signature is invalid or funds are insufficient.\n- `500 Internal Server Error`: If the server encounters an issue (e.g., mutex poisoning).\n\n\n### GET /chain\n**Description**: Retrieve the entire blockchain.\n\n```bash\ncurl http://127.0.0.1:8080/chain\n```\n\n**Response**:\n- `200 OK`: Returns the blockchain as JSON.\n- `400 Bad Request`: If the signature is invalid or funds are insufficient.\n- `500 Internal Server Error`: If the server encounters an issue (e.g., mutex poisoning).\n\n\n## Testing\n### Running Tests\n**Run all tests**:\n  ```bash\n  cargo test\n  ```\n**Run specific tests (e.g., block-related tests)**:\n  ```bash\n  cargo test --test block_tests\n  ```\n**Enable detailed logging for debugging**:\n  ```bash\n  RUST_LOG=trace cargo test --test block_tests -- --nocapture\n  ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjitendragangwar123%2Fchainrust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjitendragangwar123%2Fchainrust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjitendragangwar123%2Fchainrust/lists"}