Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/)
Expand All @@ -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)

---

Expand Down
2 changes: 1 addition & 1 deletion lib/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down
2 changes: 2 additions & 0 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::manual_div_ceil)]

use serde::{Deserialize, Serialize};
use uint::construct_uint;

Expand Down
1 change: 1 addition & 0 deletions lib/src/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::fmt;
pub struct Hash(U256);

impl Hash {
#[allow(clippy::self_named_constructors)]
pub fn hash<T: Serialize>(data: &T) -> Self {
let mut serialized = vec![];

Expand Down
8 changes: 4 additions & 4 deletions lib/src/types/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down
16 changes: 12 additions & 4 deletions lib/src/types/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ pub struct Blockchain {
mempool: Vec<(DateTime<Utc>, Transaction)>,
}

impl Default for Blockchain {
fn default() -> Self {
Self::new()
}
}

impl Blockchain {
pub fn new() -> Self {
Blockchain {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -215,9 +225,7 @@ impl Blockchain {

let all_output = tx.1.outputs.iter().map(|x| x.value).sum::<u64>();

let miner_fees = all_inputs - all_output;

miner_fees
all_inputs - all_output
});

Ok(())
Expand Down
Loading