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) --- 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/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![]; 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..f52e2b1 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,11 @@ 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 +225,7 @@ 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(())