Skip to content

Commit

Permalink
feat: add xxhash
Browse files Browse the repository at this point in the history
  • Loading branch information
slavik-pastushenko committed Dec 21, 2024
1 parent fbe8b07 commit 26a618f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ name = "blockchain"
path = "src/lib.rs"

[dependencies]
chrono = "0.4.38"
chrono = "0.4.39"
rand = "0.8.5"
serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0.132"
serde = { version = "1.0.216", features = ["derive"] }
serde_json = "1.0.133"
sha2 = "0.10.8"
twox-hash = "2.1.0"
3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "1.83.0"
components = ["clippy", "rustfmt"]
15 changes: 8 additions & 7 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{collections::HashMap, fmt::Write, iter};
use rand::Rng;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use twox_hash::xxhash64::RandomState;

use crate::{Block, Transaction, Wallet};

Expand All @@ -27,8 +28,8 @@ pub struct Chain {
/// Transaction fee.
pub fee: f64,

/// A map to associate wallets with their corresponding addresses and balances.
pub wallets: HashMap<String, Wallet>,
/// Map to associate wallets with their corresponding addresses and balances.
pub wallets: HashMap<String, Wallet, RandomState>,
}

impl Chain {
Expand All @@ -46,9 +47,9 @@ impl Chain {
fee,
reward,
difficulty,
chain: Vec::new(),
wallets: HashMap::new(),
current_transactions: Vec::new(),
chain: vec![],
wallets: HashMap::default(),
current_transactions: vec![],
address: Chain::generate_address(42),
};

Expand All @@ -67,7 +68,7 @@ impl Chain {
/// A reference to a vector containing the current transactions for the specified page.
pub fn get_transactions(&self, page: usize, size: usize) -> Vec<Transaction> {
// Calculate the total number of pages
let total_pages = (self.current_transactions.len() + size - 1) / size;
let total_pages = self.current_transactions.len().div_ceil(size);

// Return an empty vector if the page is greater than the total number of pages
if page > total_pages {
Expand Down Expand Up @@ -238,7 +239,7 @@ impl Chain {
let mut result = Vec::new();

// Calculate the total number of pages
let total_pages = (self.current_transactions.len() + size - 1) / size;
let total_pages = self.current_transactions.len().div_ceil(size);

// Return an empty vector if the page is greater than the total number of pages
if page > total_pages {
Expand Down

0 comments on commit 26a618f

Please sign in to comment.