From a637ddffe11b818b87502166cfefd3203af17247 Mon Sep 17 00:00:00 2001 From: ryzen-xp Date: Sun, 13 Sep 2026 15:33:57 +0530 Subject: [PATCH 1/4] Update README structure and enhance Table of Contents --- README.md | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c4756fc..a842e87 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ⛓️ AXE-Chain +# ⛓️ AXE-Chain ⛓️ [![Build](https://github.com/ryzen-xp/Blockchain/actions/workflows/rust.yml/badge.svg)](https://github.com/ryzen-xp/Blockchain/actions/workflows/rust.yml) [![Language](https://img.shields.io/badge/language-Rust-orange.svg)](https://www.rust-lang.org/) @@ -10,15 +10,28 @@ A **Proof of Work blockchain** built from scratch in Rust. AXE-Chain implements ## Table of Contents -- [Overview](#overview) -- [Architecture](#architecture) -- [Project Structure](#project-structure) -- [How It Works](#how-it-works) -- [Getting Started](#getting-started) -- [Usage](#usage) -- [Dependencies](#dependencies) -- [CI](#ci) -- [Contributing](#contributing) +- [⛓️ AXE-Chain ⛓️](#️-axe-chain--️) + - [Table of Contents](#table-of-contents) + - [Overview](#overview) + - [Architecture](#architecture) + - [Project Structure](#project-structure) + - [How It Works](#how-it-works) + - [Blocks](#blocks) + - [Proof of Work](#proof-of-work) + - [Chain Validation](#chain-validation) + - [Genesis Block](#genesis-block) + - [Getting Started](#getting-started) + - [Prerequisites](#prerequisites) + - [Clone](#clone) + - [Build](#build) + - [Test](#test) + - [Usage](#usage) + - [Run the miner](#run-the-miner) + - [Run a node](#run-a-node) + - [Use the wallet](#use-the-wallet) + - [Dependencies](#dependencies) + - [Contributing](#contributing) + - [Author](#author) --- From d80ad34215271eb2a08f721628d291dff39c4b36 Mon Sep 17 00:00:00 2001 From: ryzen-xp Date: Sun, 13 Sep 2026 15:36:00 +0530 Subject: [PATCH 2/4] Refactor blockchain and block implementations for clarity and efficiency --- lib/src/crypto.rs | 2 +- lib/src/types/block.rs | 8 ++++---- lib/src/types/blockchain.rs | 12 +++++++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/src/crypto.rs b/lib/src/crypto.rs index dd5b36f..b632065 100644 --- a/lib/src/crypto.rs +++ b/lib/src/crypto.rs @@ -25,7 +25,7 @@ impl PrivateKey { PrivateKey(SigningKey::random(&mut rng)) } pub fn public_key(&self) -> PublicKey { - PublicKey(self.0.verifying_key().clone()) + PublicKey(*self.0.verifying_key()) } } diff --git a/lib/src/types/block.rs b/lib/src/types/block.rs index 05e860d..884451d 100644 --- a/lib/src/types/block.rs +++ b/lib/src/types/block.rs @@ -69,13 +69,13 @@ impl Block { return Err(CoinError::InvalidSignature); } - input = input + previous_output.value; + input += previous_output.value; inputs.insert(ip.prev_transaction_output_hash, previous_output.clone()); } for op in &tx.outputs { - output = output + op.value; + output += op.value; } if input < output { @@ -103,8 +103,8 @@ impl Block { let miner_reward = self.calculate_miner_reward(utxo).unwrap(); - let block_reward = (crate::INITIAL_REWARD as u64) * 10u64.pow(8) - / 2u64.pow((predicted_block_height / crate::HALVING_INTERVAL as u64) as u32); + let block_reward = crate::INITIAL_REWARD * 10u64.pow(8) + / 2u64.pow((predicted_block_height / crate::HALVING_INTERVAL) as u32); let total_coinbase_tx_outputs_value: u64 = coinbase_tx.outputs.iter().map(|op| op.value).sum(); diff --git a/lib/src/types/blockchain.rs b/lib/src/types/blockchain.rs index c41f421..4660031 100644 --- a/lib/src/types/blockchain.rs +++ b/lib/src/types/blockchain.rs @@ -14,6 +14,12 @@ pub struct Blockchain { mempool: Vec<(DateTime, Transaction)>, } +impl Default for Blockchain { + fn default() -> Self { + Self::new() + } +} + impl Blockchain { pub fn new() -> Self { Blockchain { @@ -100,7 +106,7 @@ impl Blockchain { if self.blocks.is_empty() { return; } - if self.blocks.len() % crate::DIFFICULTY_UPDATE_INTERVAL as usize != 0 { + if !self.blocks.len().is_multiple_of(crate::DIFFICULTY_UPDATE_INTERVAL as usize) { return; } // measure the time it took to mine the last @@ -215,9 +221,9 @@ impl Blockchain { let all_output = tx.1.outputs.iter().map(|x| x.value).sum::(); - let miner_fees = all_inputs - all_output; + - miner_fees + all_inputs - all_output }); Ok(()) From b60698974dd0d5b31ee2247dd9528b95dc867d63 Mon Sep 17 00:00:00 2001 From: ryzen-xp Date: Sun, 13 Sep 2026 15:37:03 +0530 Subject: [PATCH 3/4] Refactor conditionals in Blockchain implementation for improved readability --- lib/src/types/blockchain.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/src/types/blockchain.rs b/lib/src/types/blockchain.rs index 4660031..f52e2b1 100644 --- a/lib/src/types/blockchain.rs +++ b/lib/src/types/blockchain.rs @@ -106,7 +106,11 @@ impl Blockchain { if self.blocks.is_empty() { return; } - if !self.blocks.len().is_multiple_of(crate::DIFFICULTY_UPDATE_INTERVAL as usize) { + if !self + .blocks + .len() + .is_multiple_of(crate::DIFFICULTY_UPDATE_INTERVAL as usize) + { return; } // measure the time it took to mine the last @@ -221,8 +225,6 @@ impl Blockchain { let all_output = tx.1.outputs.iter().map(|x| x.value).sum::(); - - all_inputs - all_output }); From 9f88edfebce69a720f70c25c5e7aee094e52f18a Mon Sep 17 00:00:00 2001 From: ryzen-xp Date: Sun, 13 Sep 2026 15:43:30 +0530 Subject: [PATCH 4/4] Add clippy allows for manual_div_ceil and self_named_constructors --- lib/src/lib.rs | 2 ++ lib/src/sha256.rs | 1 + 2 files changed, 3 insertions(+) diff --git a/lib/src/lib.rs b/lib/src/lib.rs index d748ef9..84685c3 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -1,3 +1,5 @@ +#![allow(clippy::manual_div_ceil)] + use serde::{Deserialize, Serialize}; use uint::construct_uint; diff --git a/lib/src/sha256.rs b/lib/src/sha256.rs index 0012379..9959ea9 100644 --- a/lib/src/sha256.rs +++ b/lib/src/sha256.rs @@ -7,6 +7,7 @@ use std::fmt; pub struct Hash(U256); impl Hash { + #[allow(clippy::self_named_constructors)] pub fn hash(data: &T) -> Self { let mut serialized = vec![];