Skip to content
Snippets Groups Projects
Commit df634c6a authored by Shubham Singhal's avatar Shubham Singhal
Browse files

Update files to remove warnings

parent 49f8a16e
No related branches found
No related tags found
No related merge requests found
......@@ -5,8 +5,8 @@ use rand::Rng;
use serde::{Serialize, Deserialize};
use crate::crypto::hash::{H256, Hashable};
use crate::transaction::{self, Transaction};
extern crate chrono;
use std::time::{Duration};
use chrono::prelude::*;
#[derive(Serialize, Deserialize, Debug,Clone)]
......
use crate::block::{self, *};
use crate::crypto::hash::{H256,Hashable};
use crate::crypto::hash;
use log::{debug,info};
use log::info;
use std::collections::HashMap;
use std::collections::VecDeque;
extern crate chrono;
use std::time::{Duration};
use chrono::prelude::*;
pub struct Blockchain {
......@@ -19,17 +18,17 @@ pub struct Blockchain {
impl Blockchain {
/// Create a new blockchain, only containing the genesis block
pub fn new() -> Self {
let mut buffer: [u8; 32] = [0; 32];
let buffer: [u8; 32] = [0; 32];
let b:H256 = buffer.into();
let mut genesis:Block = block::generate_genesis_block(&b);
let mut genhash:H256 = genesis.hash();
let genesis:Block = block::generate_genesis_block(&b);
let genhash:H256 = genesis.hash();
let mut chainmap:HashMap<H256,Block> = HashMap::new();
let mut heightsmap:HashMap<H256,u8> = HashMap::new();
let mut buffermap:HashMap<H256,Block> = HashMap::new();
let buffermap:HashMap<H256,Block> = HashMap::new();
chainmap.insert(genhash,genesis);
heightsmap.insert(genhash,0);
let t:H256 = genhash;
let mut newchain:Blockchain = Blockchain{chain:chainmap,tiphash:t,heights:heightsmap,buffer:buffermap,totaldelay:0};
let newchain:Blockchain = Blockchain{chain:chainmap,tiphash:t,heights:heightsmap,buffer:buffermap,totaldelay:0};
newchain
}
......@@ -38,7 +37,7 @@ impl Blockchain {
let h:H256 = block.hash();
let mut flag:bool = false;
//let mut flag:bool = false;
match self.chain.get(&block.header.parenthash){
......@@ -54,21 +53,21 @@ impl Blockchain {
self.chain.insert(h,block.clone());
let len = self.heights[&block.header.parenthash]+1;
self.heights.insert(h,len);
if(len>self.heights[&self.tiphash]){
if len>self.heights[&self.tiphash] {
self.tiphash = h;
}
let mut bhash_copy:H256 = hash::generate_random_hash();
//let mut bhash_copy:H256 = hash::generate_random_hash();
//if stale blocks parent has arrived, insert it into main chain
let mut bhash_vec = Vec::new();
let mut phash_q: VecDeque<H256>= VecDeque::new();
phash_q.push_back(h);
while(!phash_q.is_empty()){
while !phash_q.is_empty() {
match phash_q.pop_front() {
Some(h) => for (bhash,blck) in self.buffer.iter(){
if blck.header.parenthash == h {
flag = true;
bhash_copy = *bhash;
//flag = true;
let bhash_copy:H256 = *bhash;
bhash_vec.push(bhash_copy);
self.chain.insert(bhash_copy,blck.clone());
let b_delay = Local::now().timestamp_millis() - block.header.timestamp;
......@@ -79,7 +78,7 @@ impl Blockchain {
println!("Total number of blocks in blockchain:{}\n",self.chain.len());
let len = self.heights[&blck.header.parenthash]+1;
self.heights.insert(bhash_copy,len);
if(len>self.heights[&self.tiphash]){
if len>self.heights[&self.tiphash] {
self.tiphash = bhash_copy;
}
}
......@@ -139,6 +138,5 @@ mod tests {
let block = block::generate_random_block(&genesis_hash);
blockchain.insert(&block);
assert_eq!(blockchain.tip(), block.hash());
}
}
......@@ -24,7 +24,7 @@ impl MerkleTree {
let mut count = 0;
let mut levelen = datalen;
while !q.is_empty() {
let mut elem1 = q.pop_front().unwrap();
let elem1 = q.pop_front().unwrap();
tree.push(elem1);
count = count + 1;
let temp2 = q.pop_front();
......@@ -89,21 +89,23 @@ impl MerkleTree {
/// Verify that the datum hash with a vector of proofs will produce the Merkle root. Also need the
/// index of datum and `leaf_size`, the total number of leaves.
pub fn verify(root: &H256, datum: &H256, proof: &[H256], index: usize, leaf_size: usize) -> bool {
pub fn verify(root: &H256, datum: &H256, proof: &[H256], index: usize, _leaf_size: usize) -> bool {
let mut h = *datum;
let mut res = false;
let mut i = index;
let mut iter = 0;
let mut leftchild = <[u8;32]>::from(h);
let mut rightchild = <[u8;32]>::from(proof[0]);
while iter<proof.len() {
let mut leftchild = <[u8;32]>::from(h);
let mut rightchild = <[u8;32]>::from(h);
if i%2 ==0 {
leftchild = <[u8;32]>::from(h);
//leftchild = <[u8;32]>::from(h);
rightchild = <[u8;32]>::from(proof[iter]);
} else {
rightchild = <[u8;32]>::from(h);
//rightchild = <[u8;32]>::from(h);
leftchild = <[u8;32]>::from(proof[iter]);
}
let parentval = [&leftchild[..],&rightchild[..]].concat();
h = ring::digest::digest(&ring::digest::SHA256, &parentval[..]).into();
iter = iter + 1;
......
......@@ -7,11 +7,11 @@ use crate::network::message::Message;
use log::{debug,info};
use rand::Rng;
use crossbeam::channel::{unbounded, Receiver, Sender, TryRecvError};
extern crate chrono;
use std::time::{self,Duration};
use chrono::prelude::*;
//use std::time::{self, SystemTime, UNIX_EPOCH};
use std::time;
use std::thread;
use std::sync::{Arc, Mutex};
......
use serde::{Serialize, Deserialize};
use crate::crypto::hash::{H256, Hashable};
use crate::block::{self, *};
use crate::crypto::hash::H256;
use crate::block::Block;
use crate::transaction::Transaction;
#[derive(Serialize, Deserialize, Debug, Clone)]
......
......@@ -61,16 +61,15 @@ impl Context {
let mut required_blocks:Vec<H256> = vec![];
debug!("Received New Block Hashes");
let mut flag:bool = false;
for recv_hash in vec_hashes {
flag = false;
for (bhash,blck) in locked_blockchain.chain.iter(){
let mut flag: bool = false;
for (bhash,_) in locked_blockchain.chain.iter(){
if *bhash == recv_hash{
debug!("Block that hashes to {} already present", bhash);
flag = true;
}
}
for (bhash,blck) in locked_blockchain.buffer.iter(){
for (bhash,_) in locked_blockchain.buffer.iter(){
if *bhash == recv_hash {
debug!("Block that hashes to {} already present", bhash);
flag = true;
......
remove references to generate_random_block and generate_random_transaction
......@@ -2,7 +2,7 @@ extern crate bincode;
extern crate serde;
use serde::{Serialize,Deserialize};
use ring::signature::{self,Ed25519KeyPair, Signature, KeyPair, VerificationAlgorithm, EdDSAParameters};
use ring::signature::{self,Ed25519KeyPair, Signature, KeyPair};
use rand::Rng;
use crate::crypto::hash::{H256, Hashable};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment