Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1 add blockchain (processing) #4

Closed
wants to merge 1 commit into from
Closed
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
Empty file removed src/block.rs
Empty file.
73 changes: 73 additions & 0 deletions src/chain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
mod block;

use rand::{distributions::Alphanumeric, Rng};
use crate::math::{sha256 as hash};
use std::collections::HashMap;
use std::time::{SystemTime, UNIX_EPOCH};
use block::{BlockData as Data};
use block::{ChainFLD as FLD};
use block::{providerData as Provider};

pub impl FLD {
fn new() -> Self {
Self {
blocks: vec![],
provider: Provider {
name: "Folody Crypto Wallet".to_owned(),
shortName: "FLCWL".to_owned(),
version: "V1.0.2RTM".to_owned(),
author: "Folody Crypto".to_owned(),
provider: "Discord".to_owned(),
}
}
}

fn hash2binary(hash: &[u8]) {

}

pub fn initialization(&mut self, fromAddr: String, toAddr: String) {
let mut block: [Any; 2] = [
hash(
rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(7)
.map(char::from)
.collect()
)
];
let mut blockInside = HashMap::new();
let blockData = Data {
fromAddr: fromAddr,
toAddr: toAddr,
amount: 0.0,
transactionMsg: "".to_owned(),
createdAt: SystemTime::now(),
verifiedBy: [],
providerData: self.provider
};

blockInside.insert(block[0].to_string().to_owned(), hash(
rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(7)
.map(char::from)
.collect()
));
blockInside.insert("blockData".to_owned(), blockData);
block[1] = blockData;
self.blocks.push(block);
}

pub fn isValid(&self, block: &[Any; 2], previous_block: &[Any; 2]) {

}
pub fn tryAdd (&mut self, block: [Any; 2]) {
let latest = self.blocks.last().expect("there is at least one block");
if self.isValid(&block, latest) {
self.blocks.push(block);
} else {
error!("could not add block");
}
}
}
23 changes: 23 additions & 0 deletions src/chain/block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pub struct ChainFLD {
pub blocks: Vec,
pub(crate) provider: providerData,
}

pub struct providerData {
pub name: String,
pub shortName: String,
pub version: String,
pub author: String,
pub provider: String,

}
pub struct BlockData {
pub fromAddr: String,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create new transaction type and save to that

pub toAddr: String,
pub amount: f32,
pub transactionMsg: String,
pub createdAt: i64,
pub verifiedBy: Vec<String>,
pub providerData: providerData

}
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod math;
mod chain;

use math::{sha256 as hash};

Expand Down
Loading